GPTRouter 0.1.3__tar.gz → 0.2.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.
- {GPTRouter-0.1.3 → GPTRouter-0.2.0}/GPTRouter.egg-info/PKG-INFO +1 -1
- GPTRouter-0.2.0/GPTRouter.egg-info/requires.txt +2 -0
- {GPTRouter-0.1.3 → GPTRouter-0.2.0}/PKG-INFO +1 -1
- {GPTRouter-0.1.3 → GPTRouter-0.2.0}/gpt_router/client.py +15 -17
- {GPTRouter-0.1.3 → GPTRouter-0.2.0}/gpt_router/models.py +18 -7
- {GPTRouter-0.1.3 → GPTRouter-0.2.0}/pyproject.toml +3 -1
- {GPTRouter-0.1.3 → GPTRouter-0.2.0}/setup.py +2 -2
- GPTRouter-0.1.3/GPTRouter.egg-info/requires.txt +0 -2
- {GPTRouter-0.1.3 → GPTRouter-0.2.0}/GPTRouter.egg-info/SOURCES.txt +0 -0
- {GPTRouter-0.1.3 → GPTRouter-0.2.0}/GPTRouter.egg-info/dependency_links.txt +0 -0
- {GPTRouter-0.1.3 → GPTRouter-0.2.0}/GPTRouter.egg-info/top_level.txt +0 -0
- {GPTRouter-0.1.3 → GPTRouter-0.2.0}/LICENSE +0 -0
- {GPTRouter-0.1.3 → GPTRouter-0.2.0}/README.md +0 -0
- {GPTRouter-0.1.3 → GPTRouter-0.2.0}/gpt_router/__init__.py +0 -0
- {GPTRouter-0.1.3 → GPTRouter-0.2.0}/gpt_router/constants.py +0 -0
- {GPTRouter-0.1.3 → GPTRouter-0.2.0}/gpt_router/enums.py +0 -0
- {GPTRouter-0.1.3 → GPTRouter-0.2.0}/gpt_router/exceptions.py +0 -0
- {GPTRouter-0.1.3 → GPTRouter-0.2.0}/setup.cfg +0 -0
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
|
-
|
|
2
|
+
from pydantic import parse_obj_as
|
|
3
3
|
import logging
|
|
4
4
|
import json
|
|
5
5
|
import httpx
|
|
@@ -124,7 +124,7 @@ class GPTRouterClient:
|
|
|
124
124
|
data: dict = json.loads(line_data.strip())
|
|
125
125
|
if data["event"] == "error":
|
|
126
126
|
raise GPTRouterStreamingError(data)
|
|
127
|
-
yield ChunkedGenerationResponse
|
|
127
|
+
yield parse_obj_as(ChunkedGenerationResponse, data)
|
|
128
128
|
except GPTRouterStreamingError as e:
|
|
129
129
|
raise e
|
|
130
130
|
except Exception:
|
|
@@ -162,7 +162,7 @@ class GPTRouterClient:
|
|
|
162
162
|
data = json.loads(line_data.strip())
|
|
163
163
|
if data["event"].lower() == "error":
|
|
164
164
|
raise GPTRouterStreamingError(data["message"])
|
|
165
|
-
yield ChunkedGenerationResponse
|
|
165
|
+
yield parse_obj_as(ChunkedGenerationResponse, data)
|
|
166
166
|
except GPTRouterStreamingError as e:
|
|
167
167
|
raise e
|
|
168
168
|
except Exception:
|
|
@@ -182,7 +182,7 @@ class GPTRouterClient:
|
|
|
182
182
|
api_payload = {
|
|
183
183
|
"stream": is_stream,
|
|
184
184
|
"data": [
|
|
185
|
-
request.
|
|
185
|
+
request.dict(exclude_none=True, by_alias=True)
|
|
186
186
|
for request in ordered_generation_requests
|
|
187
187
|
],
|
|
188
188
|
}
|
|
@@ -192,13 +192,12 @@ class GPTRouterClient:
|
|
|
192
192
|
method=api_method,
|
|
193
193
|
payload=api_payload,
|
|
194
194
|
)
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
payload=api_payload,
|
|
200
|
-
)
|
|
195
|
+
result = self._api_call(
|
|
196
|
+
path=api_path,
|
|
197
|
+
method=api_method,
|
|
198
|
+
payload=api_payload,
|
|
201
199
|
)
|
|
200
|
+
return parse_obj_as(GenerationResponse, result)
|
|
202
201
|
|
|
203
202
|
async def agenerate(
|
|
204
203
|
self,
|
|
@@ -211,7 +210,7 @@ class GPTRouterClient:
|
|
|
211
210
|
api_payload = {
|
|
212
211
|
"stream": is_stream,
|
|
213
212
|
"data": [
|
|
214
|
-
request.
|
|
213
|
+
request.dict(exclude_none=True, by_alias=True)
|
|
215
214
|
for request in ordered_generation_requests
|
|
216
215
|
],
|
|
217
216
|
}
|
|
@@ -221,10 +220,9 @@ class GPTRouterClient:
|
|
|
221
220
|
method=api_method,
|
|
222
221
|
payload=api_payload,
|
|
223
222
|
)
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
payload=api_payload,
|
|
229
|
-
)
|
|
223
|
+
result = await self._async_api_call(
|
|
224
|
+
path=api_path,
|
|
225
|
+
method=api_method,
|
|
226
|
+
payload=api_payload,
|
|
230
227
|
)
|
|
228
|
+
return parse_obj_as(GenerationResponse, result)
|
|
@@ -1,6 +1,11 @@
|
|
|
1
1
|
from pydantic import BaseModel, Field
|
|
2
2
|
|
|
3
3
|
from typing import List, Optional, Dict, Any
|
|
4
|
+
from humps import camelize
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
def to_camel(string):
|
|
8
|
+
return camelize(string)
|
|
4
9
|
|
|
5
10
|
|
|
6
11
|
class GenerationParams(BaseModel):
|
|
@@ -19,39 +24,45 @@ class GenerationParams(BaseModel):
|
|
|
19
24
|
|
|
20
25
|
|
|
21
26
|
class ModelGenerationRequest(BaseModel):
|
|
22
|
-
model_name: str
|
|
23
|
-
provider_name: str
|
|
27
|
+
model_name: str
|
|
28
|
+
provider_name: str
|
|
24
29
|
order: int = Field(int)
|
|
25
|
-
prompt_params: Optional[GenerationParams] = Field(default={}
|
|
30
|
+
prompt_params: Optional[GenerationParams] = Field(default={})
|
|
26
31
|
|
|
27
32
|
class Config:
|
|
28
|
-
|
|
33
|
+
alias_generator = to_camel
|
|
34
|
+
allow_population_by_field_name = True
|
|
29
35
|
protected_namespaces = ()
|
|
30
36
|
|
|
37
|
+
|
|
31
38
|
class Usage(BaseModel):
|
|
32
39
|
completion_tokens: Optional[int] = None
|
|
33
40
|
prompt_tokens: Optional[int] = None
|
|
34
41
|
total_tokens: Optional[int] = None
|
|
35
42
|
|
|
43
|
+
|
|
36
44
|
class Choice(BaseModel):
|
|
37
45
|
index: int
|
|
38
46
|
text: str
|
|
39
47
|
finish_reason: str
|
|
40
48
|
role: Optional[str] = None
|
|
41
49
|
function_call: Optional[Any] = None
|
|
42
|
-
|
|
50
|
+
|
|
43
51
|
|
|
44
52
|
class GenerationResponse(BaseModel):
|
|
45
53
|
id: str
|
|
46
54
|
choices: List[Choice]
|
|
47
55
|
model: str
|
|
48
|
-
provider_id: Optional[str] = Field(None, alias=
|
|
49
|
-
model_id: Optional[str] = Field(None, alias=
|
|
56
|
+
provider_id: Optional[str] = Field(None, alias="providerId")
|
|
57
|
+
model_id: Optional[str] = Field(None, alias="modelId")
|
|
50
58
|
meta: Optional[Usage]
|
|
51
59
|
|
|
52
60
|
class Config:
|
|
61
|
+
alias_generator = to_camel
|
|
62
|
+
allow_population_by_field_name = True
|
|
53
63
|
protected_namespaces = ()
|
|
54
64
|
|
|
65
|
+
|
|
55
66
|
class ChunkedGenerationResponse(BaseModel):
|
|
56
67
|
event: str
|
|
57
68
|
data: dict
|
|
@@ -5,7 +5,7 @@ with open("README.md", "r") as fh:
|
|
|
5
5
|
|
|
6
6
|
setup(
|
|
7
7
|
name='GPTRouter',
|
|
8
|
-
version='0.
|
|
8
|
+
version='0.2.0',
|
|
9
9
|
description='A Python package for working with GPTRouter APIs',
|
|
10
10
|
long_description=long_description,
|
|
11
11
|
long_description_content_type="text/markdown",
|
|
@@ -13,7 +13,7 @@ setup(
|
|
|
13
13
|
packages=['gpt_router'],
|
|
14
14
|
install_requires=[
|
|
15
15
|
'httpx>=0.25.2',
|
|
16
|
-
"pydantic==
|
|
16
|
+
"pydantic==1.10.14"
|
|
17
17
|
],
|
|
18
18
|
classifiers=[
|
|
19
19
|
'Development Status :: 3 - Alpha',
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|