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.
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: GPTRouter
3
- Version: 0.1.3
3
+ Version: 0.2.0
4
4
  Summary: A Python package for working with GPTRouter APIs
5
5
  Author-email: sirjanpreet.ext@writesonic.com
6
6
  Classifier: Development Status :: 3 - Alpha
@@ -0,0 +1,2 @@
1
+ httpx>=0.25.2
2
+ pydantic==1.10.14
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: GPTRouter
3
- Version: 0.1.3
3
+ Version: 0.2.0
4
4
  Summary: A Python package for working with GPTRouter APIs
5
5
  Author-email: sirjanpreet.ext@writesonic.com
6
6
  Classifier: Development Status :: 3 - Alpha
@@ -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.model_validate(data)
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.model_validate(data)
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.model_dump(exclude_none=True, by_alias=True)
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
- return GenerationResponse.model_validate(
196
- self._api_call(
197
- path=api_path,
198
- method=api_method,
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.model_dump(exclude_none=True, by_alias=True)
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
- return GenerationResponse.model_validate(
225
- await self._async_api_call(
226
- path=api_path,
227
- method=api_method,
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 = Field(alias='modelName')
23
- provider_name: str = Field(alias='providerName')
27
+ model_name: str
28
+ provider_name: str
24
29
  order: int = Field(int)
25
- prompt_params: Optional[GenerationParams] = Field(default={}, alias="promptParams")
30
+ prompt_params: Optional[GenerationParams] = Field(default={})
26
31
 
27
32
  class Config:
28
- populate_by_name = True
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='providerId')
49
- model_id: Optional[str] = Field(None, alias='modelId')
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
@@ -8,7 +8,9 @@ readme = "README.md"
8
8
  [tool.poetry.dependencies]
9
9
  python = "^3.10"
10
10
  httpx = "^0.25.2"
11
- pydantic = "^2.5.2"
11
+ pydantic = "^1.10.14"
12
+ pyhumps = "^3.8.0"
13
+ python-dotenv = "^1.0.0"
12
14
 
13
15
 
14
16
  [build-system]
@@ -5,7 +5,7 @@ with open("README.md", "r") as fh:
5
5
 
6
6
  setup(
7
7
  name='GPTRouter',
8
- version='0.1.3',
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==2.5.2"
16
+ "pydantic==1.10.14"
17
17
  ],
18
18
  classifiers=[
19
19
  'Development Status :: 3 - Alpha',
@@ -1,2 +0,0 @@
1
- httpx>=0.25.2
2
- pydantic==2.5.2
File without changes
File without changes
File without changes
File without changes