diff --git a/lmdeploy/serve/openai/api_server.py b/lmdeploy/serve/openai/api_server.py index 28096af9b..e1af990a5 100644 --- a/lmdeploy/serve/openai/api_server.py +++ b/lmdeploy/serve/openai/api_server.py @@ -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]: @@ -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 @@ -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: diff --git a/lmdeploy/serve/openai/protocol.py b/lmdeploy/serve/openai/protocol.py index 8d5b38757..8f2919a1a 100644 --- a/lmdeploy/serve/openai/protocol.py +++ b/lmdeploy/serve/openai/protocol.py @@ -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): @@ -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): @@ -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):