Skip to content

Commit fab225a

Browse files
author
sangchengmeng
committed
fix_openai_chat_bug
1 parent 4847468 commit fab225a

File tree

1 file changed

+10
-2
lines changed

1 file changed

+10
-2
lines changed

lightllm/server/api_models.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import time
22

3-
from pydantic import BaseModel, Field
3+
from pydantic import BaseModel, Field, field_validator
44
from typing import Dict, List, Optional, Union, Literal
55
import uuid
66

@@ -9,7 +9,7 @@ class ChatCompletionRequest(BaseModel):
99
# The openai api native parameters
1010
model: str
1111
messages: List[Dict[str, str]]
12-
function_call: Optional[str] = 'none'
12+
function_call: Optional[str] = "none"
1313
temperature: Optional[float] = 1
1414
top_p: Optional[float] = 1.0
1515
n: Optional[int] = 1
@@ -52,6 +52,10 @@ class ChatCompletionResponse(BaseModel):
5252
choices: List[ChatCompletionResponseChoice]
5353
usage: UsageInfo
5454

55+
@field_validator("id", mode="before")
56+
def ensure_id_is_str(cls, v):
57+
return str(v)
58+
5559

5660
class DeltaMessage(BaseModel):
5761
role: Optional[str] = None
@@ -70,3 +74,7 @@ class ChatCompletionStreamResponse(BaseModel):
7074
created: int = Field(default_factory=lambda: int(time.time()))
7175
model: str
7276
choices: List[ChatCompletionStreamResponseChoice]
77+
78+
@field_validator("id", mode="before")
79+
def ensure_id_is_str(cls, v):
80+
return str(v)

0 commit comments

Comments
 (0)