sentiogate-python 1.3.2__tar.gz → 1.3.3__tar.gz
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_python-1.3.2/sentiogate_python.egg-info → sentiogate_python-1.3.3}/PKG-INFO +1 -1
- {sentiogate_python-1.3.2 → sentiogate_python-1.3.3}/pyproject.toml +1 -1
- {sentiogate_python-1.3.2 → sentiogate_python-1.3.3}/sentiogate/client.py +75 -18
- {sentiogate_python-1.3.2 → sentiogate_python-1.3.3/sentiogate_python.egg-info}/PKG-INFO +1 -1
- {sentiogate_python-1.3.2 → sentiogate_python-1.3.3}/LICENSE +0 -0
- {sentiogate_python-1.3.2 → sentiogate_python-1.3.3}/MANIFEST.in +0 -0
- {sentiogate_python-1.3.2 → sentiogate_python-1.3.3}/README.md +0 -0
- {sentiogate_python-1.3.2 → sentiogate_python-1.3.3}/sentiogate/__init__.py +0 -0
- {sentiogate_python-1.3.2 → sentiogate_python-1.3.3}/sentiogate/py.typed +0 -0
- {sentiogate_python-1.3.2 → sentiogate_python-1.3.3}/sentiogate_python.egg-info/SOURCES.txt +0 -0
- {sentiogate_python-1.3.2 → sentiogate_python-1.3.3}/sentiogate_python.egg-info/dependency_links.txt +0 -0
- {sentiogate_python-1.3.2 → sentiogate_python-1.3.3}/sentiogate_python.egg-info/top_level.txt +0 -0
- {sentiogate_python-1.3.2 → sentiogate_python-1.3.3}/setup.cfg +0 -0
- {sentiogate_python-1.3.2 → sentiogate_python-1.3.3}/tests/test_client.py +0 -0
|
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
|
|
|
4
4
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "sentiogate-python"
|
|
7
|
-
version = "1.3.
|
|
7
|
+
version = "1.3.3"
|
|
8
8
|
description = "Thin, zero-dependency Python client for SentioGate intelligent LLM router"
|
|
9
9
|
authors = [{name = "SentioGate Team", email = "dev@sentiogate.app"}]
|
|
10
10
|
readme = "README.md"
|
|
@@ -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.3"
|
|
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'})"
|
|
@@ -214,7 +214,8 @@ class AutoRouterClient:
|
|
|
214
214
|
if difficulty is not None:
|
|
215
215
|
payload["difficulty"] = difficulty
|
|
216
216
|
if mode is not None:
|
|
217
|
-
payload["mode"] = mode
|
|
217
|
+
payload["mode"] = mode # legacy field, ignored by current gateway
|
|
218
|
+
payload.setdefault("route_preference", mode)
|
|
218
219
|
if constraints is not None:
|
|
219
220
|
payload["constraints"] = constraints
|
|
220
221
|
if plugins is not None:
|
|
@@ -234,9 +235,9 @@ class AutoRouterClient:
|
|
|
234
235
|
|
|
235
236
|
extra_headers: dict[str, str] = {}
|
|
236
237
|
if router_metadata:
|
|
237
|
-
extra_headers["X-
|
|
238
|
+
extra_headers["X-SentioGate-Metadata"] = "enabled"
|
|
238
239
|
if cache_bypass:
|
|
239
|
-
extra_headers["X-Cache
|
|
240
|
+
extra_headers["X-SentioGate-Cache"] = "bypass"
|
|
240
241
|
if extra_body and (extra_body.get("allow_queue") or extra_body.get("allowQueue")):
|
|
241
242
|
extra_headers["X-SentioGate-Allow-Queue"] = "true"
|
|
242
243
|
|
|
@@ -289,6 +290,10 @@ class AutoRouterClient:
|
|
|
289
290
|
return err.response_body
|
|
290
291
|
err.args = (f"Enqueue batch failed ({exc.code}): {err.response_body}",)
|
|
291
292
|
raise err from None
|
|
293
|
+
except RouterClientError:
|
|
294
|
+
raise
|
|
295
|
+
except Exception as exc:
|
|
296
|
+
raise RouterClientError(f"Enqueue batch failed: {exc}") from exc
|
|
292
297
|
|
|
293
298
|
def poll_batch(self, job_id: str) -> dict[str, Any]:
|
|
294
299
|
"""Poll status and output of an enqueued batch job."""
|
|
@@ -302,6 +307,10 @@ class AutoRouterClient:
|
|
|
302
307
|
err = _http_error(exc, "Poll batch HTTP")
|
|
303
308
|
err.args = (f"Poll batch failed ({exc.code}): {err.response_body}",)
|
|
304
309
|
raise err from None
|
|
310
|
+
except RouterClientError:
|
|
311
|
+
raise
|
|
312
|
+
except Exception as exc:
|
|
313
|
+
raise RouterClientError(f"Poll batch failed: {exc}") from exc
|
|
305
314
|
|
|
306
315
|
def stream_chat(
|
|
307
316
|
self,
|
|
@@ -338,7 +347,8 @@ class AutoRouterClient:
|
|
|
338
347
|
if difficulty is not None:
|
|
339
348
|
payload["difficulty"] = difficulty
|
|
340
349
|
if mode is not None:
|
|
341
|
-
payload["mode"] = mode
|
|
350
|
+
payload["mode"] = mode # legacy field, ignored by current gateway
|
|
351
|
+
payload.setdefault("route_preference", mode)
|
|
342
352
|
if constraints is not None:
|
|
343
353
|
payload["constraints"] = constraints
|
|
344
354
|
if plugins is not None:
|
|
@@ -355,7 +365,10 @@ class AutoRouterClient:
|
|
|
355
365
|
payload.update(extra_body)
|
|
356
366
|
|
|
357
367
|
data = json.dumps(payload).encode("utf-8")
|
|
358
|
-
|
|
368
|
+
extra_headers: dict[str, str] = {"Accept": "text/event-stream"}
|
|
369
|
+
if extra_body and (extra_body.get("allow_queue") or extra_body.get("allowQueue")):
|
|
370
|
+
extra_headers["X-SentioGate-Allow-Queue"] = "true"
|
|
371
|
+
req_headers = self._headers(extra_headers)
|
|
359
372
|
req = urllib.request.Request(url, data=data, headers=req_headers, method="POST")
|
|
360
373
|
|
|
361
374
|
attempt = 0
|
|
@@ -373,10 +386,29 @@ class AutoRouterClient:
|
|
|
373
386
|
break
|
|
374
387
|
try:
|
|
375
388
|
with resp_cm as resp:
|
|
389
|
+
ctype = ""
|
|
390
|
+
try:
|
|
391
|
+
ctype = resp.headers.get("Content-Type", "") or ""
|
|
392
|
+
except Exception:
|
|
393
|
+
pass
|
|
394
|
+
if getattr(resp, "status", 200) == 202 or (ctype and "text/event-stream" not in ctype.lower()):
|
|
395
|
+
raw = resp.read().decode("utf-8")
|
|
396
|
+
try:
|
|
397
|
+
yield json.loads(raw)
|
|
398
|
+
except json.JSONDecodeError:
|
|
399
|
+
if raw.lstrip().startswith("data:"):
|
|
400
|
+
for ln in raw.splitlines():
|
|
401
|
+
ln = ln.strip()
|
|
402
|
+
if ln.startswith("data:") and ln[5:].strip() not in ("", "[DONE]"):
|
|
403
|
+
try:
|
|
404
|
+
yield json.loads(ln[5:].strip())
|
|
405
|
+
except json.JSONDecodeError:
|
|
406
|
+
continue
|
|
407
|
+
return
|
|
376
408
|
for line in resp:
|
|
377
409
|
decoded = line.decode("utf-8").strip()
|
|
378
|
-
if decoded.startswith("data:
|
|
379
|
-
raw_data = decoded[
|
|
410
|
+
if decoded.startswith("data:"):
|
|
411
|
+
raw_data = decoded[5:].strip()
|
|
380
412
|
if raw_data == "[DONE]":
|
|
381
413
|
break
|
|
382
414
|
try:
|
|
@@ -391,24 +423,40 @@ class AutoRouterClient:
|
|
|
391
423
|
def report_outcome(
|
|
392
424
|
self,
|
|
393
425
|
request_id: str,
|
|
394
|
-
signals: dict[str, bool],
|
|
426
|
+
signals: dict[str, bool] | None = None,
|
|
395
427
|
provider: str | None = None,
|
|
396
428
|
task_class: str | None = None,
|
|
429
|
+
model: str | None = None,
|
|
430
|
+
success: bool | None = None,
|
|
431
|
+
score: float | None = None,
|
|
432
|
+
latency_ms: int | None = None,
|
|
397
433
|
) -> dict[str, Any]:
|
|
398
|
-
"""
|
|
434
|
+
"""Report an outcome. The gateway requires ``model`` (legacy ``provider`` accepted) and a boolean
|
|
435
|
+
``success`` (or numeric ``score``; legacy ``signals`` are folded into ``success``)."""
|
|
399
436
|
url = f"{self.base_url}/v1/outcomes"
|
|
400
|
-
|
|
401
|
-
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
"task_class"
|
|
405
|
-
|
|
437
|
+
if success is None and signals:
|
|
438
|
+
success = all(bool(v) for v in signals.values())
|
|
439
|
+
payload: dict[str, Any] = {"request_id": request_id, "model": model or provider}
|
|
440
|
+
if task_class is not None:
|
|
441
|
+
payload["task_class"] = task_class
|
|
442
|
+
if success is not None:
|
|
443
|
+
payload["success"] = bool(success)
|
|
444
|
+
if score is not None:
|
|
445
|
+
payload["score"] = score
|
|
446
|
+
if latency_ms is not None:
|
|
447
|
+
payload["latency_ms"] = latency_ms
|
|
448
|
+
if signals:
|
|
449
|
+
payload["signals"] = signals
|
|
450
|
+
if provider:
|
|
451
|
+
payload["provider"] = provider
|
|
406
452
|
data = json.dumps(payload).encode("utf-8")
|
|
407
453
|
req = urllib.request.Request(url, data=data, headers=self._headers(), method="POST")
|
|
408
454
|
|
|
409
455
|
try:
|
|
410
456
|
with urllib.request.urlopen(req, timeout=self.timeout) as resp:
|
|
411
457
|
return json.loads(resp.read().decode("utf-8"))
|
|
458
|
+
except urllib.error.HTTPError as exc:
|
|
459
|
+
raise _http_error(exc, "Outcome report HTTP") from None
|
|
412
460
|
except Exception as exc:
|
|
413
461
|
raise RouterClientError(f"Failed to report outcome: {exc}") from exc
|
|
414
462
|
|
|
@@ -556,8 +604,17 @@ class AutoRouterClient:
|
|
|
556
604
|
except Exception as exc:
|
|
557
605
|
raise RouterClientError(f"Failed to redeem license: {exc}") from exc
|
|
558
606
|
|
|
559
|
-
def get_user_license(self, user_id: str =
|
|
560
|
-
"""Fetch active license voucher details
|
|
607
|
+
def get_user_license(self, user_id: str | None = None) -> dict[str, Any]:
|
|
608
|
+
"""Fetch active license voucher details (defaults to the signed-in user, resolved via /v1/auth/me)."""
|
|
609
|
+
if not user_id:
|
|
610
|
+
me_req = urllib.request.Request(f"{self.base_url}/v1/auth/me", headers=self._headers(), method="GET")
|
|
611
|
+
try:
|
|
612
|
+
with urllib.request.urlopen(me_req, timeout=self.timeout) as resp:
|
|
613
|
+
user_id = (json.loads(resp.read().decode("utf-8")).get("user") or {}).get("id")
|
|
614
|
+
except Exception as exc:
|
|
615
|
+
raise RouterClientError(f"Failed to fetch user license: {exc}") from exc
|
|
616
|
+
if not user_id:
|
|
617
|
+
raise RouterClientError("Failed to fetch user license: could not resolve current user id")
|
|
561
618
|
url = f"{self.base_url}/v1/licenses/user/{urllib.parse.quote(user_id, safe='')}"
|
|
562
619
|
req = urllib.request.Request(url, headers=self._headers(), method="GET")
|
|
563
620
|
try:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{sentiogate_python-1.3.2 → sentiogate_python-1.3.3}/sentiogate_python.egg-info/dependency_links.txt
RENAMED
|
File without changes
|
{sentiogate_python-1.3.2 → sentiogate_python-1.3.3}/sentiogate_python.egg-info/top_level.txt
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|