mirror of
https://github.com/BerriAI/litellm.git
synced 2025-04-27 11:43:54 +00:00
fix(proxy_server.py): add custom json helper func to work across multiple pydantic versions
This commit is contained in:
parent
0b1da2bd5a
commit
a8f5b4b69c
2 changed files with 5 additions and 4 deletions
|
@ -1,7 +1,7 @@
|
||||||
from pydantic import BaseModel, Extra, Field
|
from pydantic import BaseModel, Extra, Field
|
||||||
from typing import Optional, List, Union, Dict, Literal
|
from typing import Optional, List, Union, Dict, Literal
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import uuid
|
import uuid, json
|
||||||
######### Request Class Definition ######
|
######### Request Class Definition ######
|
||||||
class ProxyChatCompletionRequest(BaseModel):
|
class ProxyChatCompletionRequest(BaseModel):
|
||||||
model: str
|
model: str
|
||||||
|
@ -84,6 +84,9 @@ class GenerateKeyRequest(BaseModel):
|
||||||
user_id: Optional[str] = None
|
user_id: Optional[str] = None
|
||||||
max_parallel_requests: Optional[int] = None
|
max_parallel_requests: Optional[int] = None
|
||||||
|
|
||||||
|
def json(self, **kwargs) -> str:
|
||||||
|
return json.dumps(self.dict(), **kwargs)
|
||||||
|
|
||||||
class GenerateKeyResponse(BaseModel):
|
class GenerateKeyResponse(BaseModel):
|
||||||
key: str
|
key: str
|
||||||
expires: datetime
|
expires: datetime
|
||||||
|
|
|
@ -1128,9 +1128,7 @@ async def generate_key_fn(request: Request, data: GenerateKeyRequest, Authorizat
|
||||||
- user_id: (str) Unique user id - used for tracking spend across multiple keys for same user id.
|
- user_id: (str) Unique user id - used for tracking spend across multiple keys for same user id.
|
||||||
"""
|
"""
|
||||||
# data = await request.json()
|
# data = await request.json()
|
||||||
print(f"type of object: {type(data)}")
|
data_json = json.loads(data.json()) # type: ignore
|
||||||
data_json = json.loads(data.model_dump_json()) # type: ignore
|
|
||||||
print(f"data_json: {data_json}")
|
|
||||||
response = await generate_key_helper_fn(**data_json)
|
response = await generate_key_helper_fn(**data_json)
|
||||||
return GenerateKeyResponse(key=response["token"], expires=response["expires"], user_id=response["user_id"])
|
return GenerateKeyResponse(key=response["token"], expires=response["expires"], user_id=response["user_id"])
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue