Skip to content

Commit c53f3c4

Browse files
authored
Fix API calls on Windows (#225)
* replace os.path.join with urllib.parse.urljoin * bump version * bump versions
1 parent a6edfd8 commit c53f3c4

File tree

4 files changed

+13
-12
lines changed

4 files changed

+13
-12
lines changed

clients/python/llmengine/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
# See the License for the specific language governing permissions and
1313
# limitations under the License.
1414

15-
__version__ = "0.0.0.beta11"
15+
__version__ = "0.0.0.beta12"
1616

1717
from typing import Sequence
1818

clients/python/llmengine/api_engine.py

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
from functools import wraps
66
from io import BufferedReader
77
from typing import Any, AsyncIterable, Dict, Iterator, Optional
8+
from urllib.parse import urljoin
89

910
import requests
1011
from aiohttp import ClientSession, ClientTimeout
1112
from llmengine.errors import parse_error
1213

13-
SPELLBOOK_API_URL = "https://api.spellbook.scale.com/llm-engine"
14+
SPELLBOOK_API_URL = "https://api.spellbook.scale.com/llm-engine/"
1415
LLM_ENGINE_BASE_PATH = os.getenv("LLM_ENGINE_BASE_PATH", SPELLBOOK_API_URL)
1516
DEFAULT_TIMEOUT: int = 10
1617

@@ -51,7 +52,7 @@ def validate_api_key(cls):
5152
def _get(cls, resource_name: str, timeout: int) -> Dict[str, Any]:
5253
api_key = get_api_key()
5354
response = requests.get(
54-
os.path.join(LLM_ENGINE_BASE_PATH, resource_name),
55+
urljoin(LLM_ENGINE_BASE_PATH, resource_name),
5556
timeout=timeout,
5657
headers={"x-api-key": api_key},
5758
auth=(api_key, ""),
@@ -67,7 +68,7 @@ def put(
6768
) -> Dict[str, Any]:
6869
api_key = get_api_key()
6970
response = requests.put(
70-
os.path.join(LLM_ENGINE_BASE_PATH, resource_name),
71+
urljoin(LLM_ENGINE_BASE_PATH, resource_name),
7172
json=data,
7273
timeout=timeout,
7374
headers={"x-api-key": api_key},
@@ -82,7 +83,7 @@ def put(
8283
def _delete(cls, resource_name: str, timeout: int) -> Dict[str, Any]:
8384
api_key = get_api_key()
8485
response = requests.delete(
85-
os.path.join(LLM_ENGINE_BASE_PATH, resource_name),
86+
urljoin(LLM_ENGINE_BASE_PATH, resource_name),
8687
timeout=timeout,
8788
headers={"x-api-key": api_key},
8889
auth=(api_key, ""),
@@ -96,7 +97,7 @@ def _delete(cls, resource_name: str, timeout: int) -> Dict[str, Any]:
9697
def post_sync(cls, resource_name: str, data: Dict[str, Any], timeout: int) -> Dict[str, Any]:
9798
api_key = get_api_key()
9899
response = requests.post(
99-
os.path.join(LLM_ENGINE_BASE_PATH, resource_name),
100+
urljoin(LLM_ENGINE_BASE_PATH, resource_name),
100101
json=data,
101102
timeout=timeout,
102103
headers={"x-api-key": api_key},
@@ -113,7 +114,7 @@ def post_stream(
113114
) -> Iterator[Dict[str, Any]]:
114115
api_key = get_api_key()
115116
response = requests.post(
116-
os.path.join(LLM_ENGINE_BASE_PATH, resource_name),
117+
urljoin(LLM_ENGINE_BASE_PATH, resource_name),
117118
json=data,
118119
timeout=timeout,
119120
headers={"x-api-key": api_key},
@@ -145,7 +146,7 @@ def post_file(
145146
) -> Dict[str, Any]:
146147
api_key = get_api_key()
147148
response = requests.post(
148-
os.path.join(LLM_ENGINE_BASE_PATH, resource_name),
149+
urljoin(LLM_ENGINE_BASE_PATH, resource_name),
149150
files=files,
150151
timeout=timeout,
151152
headers={"x-api-key": api_key},
@@ -164,7 +165,7 @@ async def apost_sync(
164165
timeout=ClientTimeout(timeout), headers={"x-api-key": api_key}
165166
) as session:
166167
async with session.post(
167-
os.path.join(LLM_ENGINE_BASE_PATH, resource_name), json=data
168+
urljoin(LLM_ENGINE_BASE_PATH, resource_name), json=data
168169
) as resp:
169170
if resp.status != 200:
170171
raise parse_error(resp.status, await resp.read())
@@ -180,7 +181,7 @@ async def apost_stream(
180181
timeout=ClientTimeout(timeout), headers={"x-api-key": api_key}
181182
) as session:
182183
async with session.post(
183-
os.path.join(LLM_ENGINE_BASE_PATH, resource_name), json=data
184+
urljoin(LLM_ENGINE_BASE_PATH, resource_name), json=data
184185
) as resp:
185186
if resp.status != 200:
186187
raise parse_error(resp.status, await resp.read())

clients/python/pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "scale-llm-engine"
3-
version = "0.0.0.beta11"
3+
version = "0.0.0.beta12"
44
description = "Scale LLM Engine Python client"
55
license = "Apache-2.0"
66
authors = ["Phil Chen <[email protected]>"]

clients/python/setup.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
setup(
44
name="scale-llm-engine",
55
python_requires=">=3.7",
6-
version="0.0.0.beta11",
6+
version="0.0.0.beta12",
77
packages=find_packages(),
88
)

0 commit comments

Comments
 (0)