From 0ef583b7deed49f902a39c24799c7c25b64ced00 Mon Sep 17 00:00:00 2001 From: GavinZhu-GMI Date: Tue, 26 Aug 2025 15:47:20 +0800 Subject: [PATCH] fix: allow user to specify function as role (#9635) --- python/sglang/srt/entrypoints/openai/protocol.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/python/sglang/srt/entrypoints/openai/protocol.py b/python/sglang/srt/entrypoints/openai/protocol.py index d36a7f80c..7c1b07318 100644 --- a/python/sglang/srt/entrypoints/openai/protocol.py +++ b/python/sglang/srt/entrypoints/openai/protocol.py @@ -327,7 +327,7 @@ class ToolCall(BaseModel): class ChatCompletionMessageGenericParam(BaseModel): - role: Literal["system", "assistant", "tool"] + role: Literal["system", "assistant", "tool", "function"] content: Union[str, List[ChatCompletionMessageContentTextPart], None] = Field( default=None ) @@ -341,9 +341,9 @@ class ChatCompletionMessageGenericParam(BaseModel): def _normalize_role(cls, v): if isinstance(v, str): v_lower = v.lower() - if v_lower not in {"system", "assistant", "tool"}: + if v_lower not in {"system", "assistant", "tool", "function"}: raise ValueError( - "'role' must be one of 'system', 'assistant', or 'tool' (case-insensitive)." + "'role' must be one of 'system', 'assistant', 'tool', or 'function' (case-insensitive)." ) return v_lower raise ValueError("'role' must be a string")