Skip to content

Commit

Permalink
Throw error on None
Browse files Browse the repository at this point in the history
  • Loading branch information
Edenzzzz committed Feb 24, 2025
1 parent 33ca853 commit 4a036ea
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions python/sglang/srt/openai_api/protocol.py
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,10 @@ class MessagewithContent(BaseModel):
# Avoid openai InternalServerError when input is None
@field_validator("content", mode="before")
def handle_none_content(cls, v):
"""Convert None to empty string to avoid validation errors."""
return "" if v is None else v
raise ValueError(
"Message content for Chat Completion and Tool Calling cannot be None. "
+ "Please input a valid string."
)


class ChatCompletionMessageGenericParam(MessagewithContent, BaseModel):
Expand Down

0 comments on commit 4a036ea

Please sign in to comment.