routewise 0.1.0__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.
- routewise-0.1.0/PKG-INFO +9 -0
- routewise-0.1.0/README.md +40 -0
- routewise-0.1.0/routewise/__init__.py +57 -0
- routewise-0.1.0/routewise.egg-info/PKG-INFO +9 -0
- routewise-0.1.0/routewise.egg-info/SOURCES.txt +8 -0
- routewise-0.1.0/routewise.egg-info/dependency_links.txt +1 -0
- routewise-0.1.0/routewise.egg-info/requires.txt +1 -0
- routewise-0.1.0/routewise.egg-info/top_level.txt +1 -0
- routewise-0.1.0/setup.cfg +4 -0
- routewise-0.1.0/setup.py +10 -0
routewise-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
# routewise (Python SDK)
|
|
2
|
+
|
|
3
|
+
Thin client for the routewise cost-aware LLM router. No routing logic lives
|
|
4
|
+
here -- it's a convenience wrapper around HTTP calls to the real API.
|
|
5
|
+
|
|
6
|
+
## Install
|
|
7
|
+
|
|
8
|
+
Locally, for development:
|
|
9
|
+
```bash
|
|
10
|
+
pip install -e ./sdk
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
Or directly from GitHub (once pushed):
|
|
14
|
+
```bash
|
|
15
|
+
pip install git+https://github.com/Ishan-5/llm-router.git#subdirectory=sdk
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
## Usage
|
|
19
|
+
|
|
20
|
+
```python
|
|
21
|
+
from routewise import RouteWiseClient
|
|
22
|
+
|
|
23
|
+
client = RouteWiseClient(api_key="rw_your_key_here")
|
|
24
|
+
|
|
25
|
+
result = client.ask("What is the capital of France?")
|
|
26
|
+
print(result["response"])
|
|
27
|
+
print(result["routed_to"], result["cost_usd"])
|
|
28
|
+
|
|
29
|
+
# Force a specific tier instead of letting the difficulty model decide
|
|
30
|
+
result = client.ask("Explain quantum computing", override_tier="frontier")
|
|
31
|
+
|
|
32
|
+
# Get aggregate usage stats
|
|
33
|
+
stats = client.stats()
|
|
34
|
+
print(stats["total_requests"], stats["cache_hit_rate"])
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
## Errors
|
|
38
|
+
|
|
39
|
+
All non-2xx responses raise `RouteWiseError` with the API's error detail
|
|
40
|
+
message, e.g. invalid key, rate limit exceeded, empty query.
|
|
@@ -0,0 +1,57 @@
|
|
|
1
|
+
"""
|
|
2
|
+
routewise -- a thin Python client for the routewise cost-aware LLM router.
|
|
3
|
+
|
|
4
|
+
This does NOT contain any routing logic. It just wraps HTTP calls to the
|
|
5
|
+
real API so callers don't have to write requests.post()/headers/error
|
|
6
|
+
handling by hand every time.
|
|
7
|
+
"""
|
|
8
|
+
import requests
|
|
9
|
+
|
|
10
|
+
DEFAULT_BASE_URL = "https://llm-router-d2b2.onrender.com"
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class RouteWiseError(Exception):
|
|
14
|
+
"""Raised when the API returns an error response."""
|
|
15
|
+
pass
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
class RouteWiseClient:
|
|
19
|
+
def __init__(self, api_key: str, base_url: str = DEFAULT_BASE_URL, timeout: int = 30):
|
|
20
|
+
self.api_key = api_key
|
|
21
|
+
self.base_url = base_url.rstrip("/")
|
|
22
|
+
self.timeout = timeout
|
|
23
|
+
|
|
24
|
+
def _headers(self) -> dict:
|
|
25
|
+
return {"Authorization": f"Bearer {self.api_key}"}
|
|
26
|
+
|
|
27
|
+
def ask(self, query: str, override_tier: str | None = None) -> dict:
|
|
28
|
+
"""
|
|
29
|
+
Send a query through the router. Returns the full response dict
|
|
30
|
+
(response text, tier used, cost, latency, cache_hit, etc.)
|
|
31
|
+
|
|
32
|
+
override_tier: optionally force "cheap", "mid", or "frontier"
|
|
33
|
+
instead of letting the difficulty model decide.
|
|
34
|
+
"""
|
|
35
|
+
payload = {"query": query}
|
|
36
|
+
if override_tier:
|
|
37
|
+
payload["override_tier"] = override_tier
|
|
38
|
+
|
|
39
|
+
response = requests.post(
|
|
40
|
+
f"{self.base_url}/route",
|
|
41
|
+
headers=self._headers(),
|
|
42
|
+
json=payload,
|
|
43
|
+
timeout=self.timeout,
|
|
44
|
+
)
|
|
45
|
+
|
|
46
|
+
if not response.ok:
|
|
47
|
+
detail = response.json().get("detail", response.text) if response.content else response.text
|
|
48
|
+
raise RouteWiseError(f"[{response.status_code}] {detail}")
|
|
49
|
+
|
|
50
|
+
return response.json()
|
|
51
|
+
|
|
52
|
+
def stats(self) -> dict:
|
|
53
|
+
"""Fetch aggregate usage stats (total requests, cost saved, tier distribution, etc.)"""
|
|
54
|
+
response = requests.get(f"{self.base_url}/stats", timeout=self.timeout)
|
|
55
|
+
if not response.ok:
|
|
56
|
+
raise RouteWiseError(f"[{response.status_code}] {response.text}")
|
|
57
|
+
return response.json()
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
requests
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
routewise
|
routewise-0.1.0/setup.py
ADDED