fix serving issues when requesting real data
This commit is contained in:
@@ -373,6 +373,31 @@ class ChatCompletionRequest(OpenAIBaseModel):
|
||||
|
||||
return None
|
||||
|
||||
@model_validator(mode="before")
|
||||
@classmethod
|
||||
def normalize_messages(cls, data):
|
||||
"""Normalize incoming messages before pydantic union validation.
|
||||
|
||||
Real-world clients (e.g. from other providers) send assistant tool_call
|
||||
messages with content=null, which fails the strict Union type check.
|
||||
Replace null content with "" so validation passes.
|
||||
reasoning_content is intentionally kept — chat_utils.py wraps it as
|
||||
<think>...</think> for multi-turn reasoning history.
|
||||
"""
|
||||
messages = data.get("messages")
|
||||
if not isinstance(messages, list):
|
||||
return data
|
||||
normalized = []
|
||||
for msg in messages:
|
||||
if not isinstance(msg, dict):
|
||||
normalized.append(msg)
|
||||
continue
|
||||
if msg.get("content") is None:
|
||||
msg = {**msg, "content": ""}
|
||||
normalized.append(msg)
|
||||
data = {**data, "messages": normalized}
|
||||
return data
|
||||
|
||||
@model_validator(mode="before")
|
||||
@classmethod
|
||||
def validate_stream_options(cls, data):
|
||||
|
||||
Reference in New Issue
Block a user