sentiogate-python 1.3.0__py3-none-any.whl → 1.3.2__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- sentiogate/__init__.py +2 -0
- sentiogate/client.py +37 -2
- {sentiogate_python-1.3.0.dist-info → sentiogate_python-1.3.2.dist-info}/METADATA +1 -1
- sentiogate_python-1.3.2.dist-info/RECORD +8 -0
- sentiogate_python-1.3.0.dist-info/RECORD +0 -8
- {sentiogate_python-1.3.0.dist-info → sentiogate_python-1.3.2.dist-info}/WHEEL +0 -0
- {sentiogate_python-1.3.0.dist-info → sentiogate_python-1.3.2.dist-info}/licenses/LICENSE +0 -0
- {sentiogate_python-1.3.0.dist-info → sentiogate_python-1.3.2.dist-info}/top_level.txt +0 -0
sentiogate/__init__.py
CHANGED
|
@@ -9,6 +9,7 @@ from .client import (
|
|
|
9
9
|
AutoRouterClient,
|
|
10
10
|
RouterClientError,
|
|
11
11
|
parse_retry_after,
|
|
12
|
+
validate_base_url,
|
|
12
13
|
)
|
|
13
14
|
|
|
14
15
|
__version__ = VERSION
|
|
@@ -20,4 +21,5 @@ __all__ = [
|
|
|
20
21
|
"AutoRouterClient",
|
|
21
22
|
"RouterClientError",
|
|
22
23
|
"parse_retry_after",
|
|
24
|
+
"validate_base_url",
|
|
23
25
|
]
|
sentiogate/client.py
CHANGED
|
@@ -18,7 +18,7 @@ import urllib.request
|
|
|
18
18
|
from collections.abc import Callable, Iterator
|
|
19
19
|
from typing import Any
|
|
20
20
|
|
|
21
|
-
VERSION = "1.3.
|
|
21
|
+
VERSION = "1.3.2"
|
|
22
22
|
# Sent on every request: honest, names this SDK, its real version and the OS it runs on (never a browser string,
|
|
23
23
|
# never the default Python-urllib agent, which the gateway's bot check may refuse).
|
|
24
24
|
USER_AGENT = f"sentiogate-python/{VERSION} ({platform.system() or 'unknown'})"
|
|
@@ -105,6 +105,17 @@ DEFAULT_BASE_URL = "https://api.sentiogate.dev"
|
|
|
105
105
|
DEFAULT_TIMEOUT = 130.0
|
|
106
106
|
|
|
107
107
|
|
|
108
|
+
def validate_base_url(url: str | None) -> str:
|
|
109
|
+
"""Validates and normalizes client base_url to ensure safe protocol scheme."""
|
|
110
|
+
target = (url or DEFAULT_BASE_URL).strip()
|
|
111
|
+
parsed = urllib.parse.urlsplit(target)
|
|
112
|
+
if parsed.scheme not in ("http", "https"):
|
|
113
|
+
raise ValueError(f"Invalid base_url scheme '{parsed.scheme}'. Only 'http' and 'https' are allowed.")
|
|
114
|
+
if not parsed.netloc:
|
|
115
|
+
raise ValueError(f"Invalid base_url '{target}': missing host.")
|
|
116
|
+
return target.rstrip("/")
|
|
117
|
+
|
|
118
|
+
|
|
108
119
|
class AutoRouterClient:
|
|
109
120
|
"""Thin, zero-leak client SDK for connecting applications to SentioGate.
|
|
110
121
|
|
|
@@ -131,7 +142,7 @@ class AutoRouterClient:
|
|
|
131
142
|
max_retry_wait: float = 60.0,
|
|
132
143
|
user_agent: str | None = None,
|
|
133
144
|
) -> None:
|
|
134
|
-
self.base_url = base_url
|
|
145
|
+
self.base_url = validate_base_url(base_url)
|
|
135
146
|
self.api_key = api_key
|
|
136
147
|
self.timeout = timeout
|
|
137
148
|
self.max_retries = max(0, int(max_retries))
|
|
@@ -176,6 +187,10 @@ class AutoRouterClient:
|
|
|
176
187
|
hedge_delay_ms: int | None = None, # deprecated no-op: ignored by the gateway
|
|
177
188
|
cache: bool = False,
|
|
178
189
|
cache_bypass: bool = False,
|
|
190
|
+
max_cost_usd: float | None = None,
|
|
191
|
+
max_latency_ms: int | None = None,
|
|
192
|
+
strict_cost: bool = False,
|
|
193
|
+
tool_search: str | bool | None = None,
|
|
179
194
|
extra_body: dict[str, Any] | None = None,
|
|
180
195
|
) -> dict[str, Any]:
|
|
181
196
|
"""Send a chat completion request to the router.
|
|
@@ -206,6 +221,14 @@ class AutoRouterClient:
|
|
|
206
221
|
payload["plugins"] = plugins
|
|
207
222
|
if router_metadata:
|
|
208
223
|
payload["router_metadata"] = True
|
|
224
|
+
if max_cost_usd is not None:
|
|
225
|
+
payload["max_cost_usd"] = max_cost_usd
|
|
226
|
+
if max_latency_ms is not None:
|
|
227
|
+
payload["max_latency_ms"] = max_latency_ms
|
|
228
|
+
if strict_cost:
|
|
229
|
+
payload["strict_cost"] = True
|
|
230
|
+
if tool_search is not None:
|
|
231
|
+
payload["tool_search"] = tool_search
|
|
209
232
|
if extra_body:
|
|
210
233
|
payload.update(extra_body)
|
|
211
234
|
|
|
@@ -291,6 +314,10 @@ class AutoRouterClient:
|
|
|
291
314
|
constraints: dict[str, Any] | None = None,
|
|
292
315
|
plugins: list[dict[str, Any]] | None = None,
|
|
293
316
|
tier: str = "free",
|
|
317
|
+
max_cost_usd: float | None = None,
|
|
318
|
+
max_latency_ms: int | None = None,
|
|
319
|
+
strict_cost: bool = False,
|
|
320
|
+
tool_search: str | bool | None = None,
|
|
294
321
|
extra_body: dict[str, Any] | None = None,
|
|
295
322
|
) -> Iterator[dict[str, Any]]:
|
|
296
323
|
"""Stream chat completion chunks (SSE) from the router.
|
|
@@ -316,6 +343,14 @@ class AutoRouterClient:
|
|
|
316
343
|
payload["constraints"] = constraints
|
|
317
344
|
if plugins is not None:
|
|
318
345
|
payload["plugins"] = plugins
|
|
346
|
+
if max_cost_usd is not None:
|
|
347
|
+
payload["max_cost_usd"] = max_cost_usd
|
|
348
|
+
if max_latency_ms is not None:
|
|
349
|
+
payload["max_latency_ms"] = max_latency_ms
|
|
350
|
+
if strict_cost:
|
|
351
|
+
payload["strict_cost"] = True
|
|
352
|
+
if tool_search is not None:
|
|
353
|
+
payload["tool_search"] = tool_search
|
|
319
354
|
if extra_body:
|
|
320
355
|
payload.update(extra_body)
|
|
321
356
|
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
sentiogate/__init__.py,sha256=29ukbIt-wtLmQrTZqO06A20-fO6RiDzhTO2L_VMA-uQ,494
|
|
2
|
+
sentiogate/client.py,sha256=5ZadLMYjM9bchJ-dYd_gGR-n9wAxmaX62cNve5ReWc8,24904
|
|
3
|
+
sentiogate/py.typed,sha256=-yl3TJziRnBGR4RQVDoLxLVJCMoslIXZL48QaM0ulXI,35
|
|
4
|
+
sentiogate_python-1.3.2.dist-info/licenses/LICENSE,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
|
|
5
|
+
sentiogate_python-1.3.2.dist-info/METADATA,sha256=c8wIoktFw6eUL9yFappVLZ-whZuqW7GM37tLXMhxj2c,4921
|
|
6
|
+
sentiogate_python-1.3.2.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
7
|
+
sentiogate_python-1.3.2.dist-info/top_level.txt,sha256=fxARYgd5oUze_a7WfsncfYRu5Qfu75FhwXhKE97He4c,11
|
|
8
|
+
sentiogate_python-1.3.2.dist-info/RECORD,,
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
sentiogate/__init__.py,sha256=XS9WQtXdB12a4CVopwi4wyFhS3Oy2tsafe2VHA0Glr0,446
|
|
2
|
-
sentiogate/client.py,sha256=14gyNmAVkv4Ck6ATUCExbff6Iu40ITA8S11nTdn4d6c,23389
|
|
3
|
-
sentiogate/py.typed,sha256=-yl3TJziRnBGR4RQVDoLxLVJCMoslIXZL48QaM0ulXI,35
|
|
4
|
-
sentiogate_python-1.3.0.dist-info/licenses/LICENSE,sha256=z8d0m5b2O9McPEK1xHG_dWgUBT6EfBDz6wA0F7xSPTA,11358
|
|
5
|
-
sentiogate_python-1.3.0.dist-info/METADATA,sha256=oI45fZyi94hG-_LttSYmdHEKhS9-7TuVxE07Im3OLfw,4921
|
|
6
|
-
sentiogate_python-1.3.0.dist-info/WHEEL,sha256=mOdXR9C3wMVov7cSY8PY-XCzo3SmmWCHvGQr5csJoao,91
|
|
7
|
-
sentiogate_python-1.3.0.dist-info/top_level.txt,sha256=fxARYgd5oUze_a7WfsncfYRu5Qfu75FhwXhKE97He4c,11
|
|
8
|
-
sentiogate_python-1.3.0.dist-info/RECORD,,
|
|
File without changes
|
|
File without changes
|
|
File without changes
|