class ChatCompletionMessageGenericParam(BaseModel):
role: Literal["system", "assistant", "tool"]
content: Union[str, List[ChatCompletionMessageContentTextPart], None]
tool_call_id: Optional[str] = None
name: Optional[str] = None
reasoning_content: Optional[str] = None
tool_calls: Optional[List[ToolCall]] = Field(default=None, examples=[None])
@field_validator("role", mode="before")
@classmethod
def _normalize_role(cls, v):
if isinstance(v, str):
v_lower = v.lower()
if v_lower not in {"system", "assistant", "tool"}:
raise ValueError(
"'role' must be one of 'system', 'assistant', or 'tool' (case-insensitive)."
)
return v_lower
raise ValueError("'role' must be a string")
Checklist
Motivation
According to the https://platform.openai.com/docs/api-reference/chat/create OpenAI Platform, when there is
tool_calls, thecontentcould be optional. But the current implementation could cause 400 Bad Request whencontentfiled is missed undertool_callssituation.Related resources
No response