Skip to content

Commit

Permalink
Fix compatibility issues with Pydantic 2 (#465)
Browse files Browse the repository at this point in the history
  • Loading branch information
aisensiy authored Sep 26, 2023
1 parent a54e3e0 commit 22cd7d1
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 6 deletions.
6 changes: 3 additions & 3 deletions lmdeploy/serve/openai/api_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ def create_error_response(status: HTTPStatus, message: str):
return JSONResponse(
ErrorResponse(message=message,
type='invalid_request_error',
code=status.value).dict())
code=status.value).model_dump())


async def check_request(request) -> Optional[JSONResponse]:
Expand Down Expand Up @@ -152,7 +152,7 @@ def create_stream_response_json(
model=model_name,
choices=[choice_data],
)
response_json = response.json(ensure_ascii=False)
response_json = response.model_dump_json()

return response_json

Expand All @@ -167,7 +167,7 @@ async def completion_stream_generator() -> AsyncGenerator[str, None]:
chunk = ChatCompletionStreamResponse(id=request_id,
choices=[choice_data],
model=model_name)
data = chunk.json(exclude_unset=True, ensure_ascii=False)
data = chunk.model_dump_json(exclude_unset=True)
yield f'data: {data}\n\n'

async for res in result_generator:
Expand Down
6 changes: 3 additions & 3 deletions lmdeploy/serve/openai/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class ChatCompletionResponseChoice(BaseModel):
"""Chat completion response choices."""
index: int
message: ChatMessage
finish_reason: Optional[Literal['stop', 'length']]
finish_reason: Optional[Literal['stop', 'length']] = None


class ChatCompletionResponse(BaseModel):
Expand All @@ -107,7 +107,7 @@ class ChatCompletionResponseStreamChoice(BaseModel):
"""Chat completion response stream choice."""
index: int
delta: DeltaMessage
finish_reason: Optional[Literal['stop', 'length']]
finish_reason: Optional[Literal['stop', 'length']] = None


class ChatCompletionStreamResponse(BaseModel):
Expand Down Expand Up @@ -142,7 +142,7 @@ class CompletionResponseChoice(BaseModel):
index: int
text: str
logprobs: Optional[int] = None
finish_reason: Optional[Literal['stop', 'length']]
finish_reason: Optional[Literal['stop', 'length']] = None


class CompletionResponse(BaseModel):
Expand Down

0 comments on commit 22cd7d1

Please sign in to comment.