Align reasoning_effort schema across chat, tokenize, and responses (#31784)
This commit is contained in:
@@ -100,6 +100,7 @@ import { Playground } from "/src/snippets/_playground.jsx";
|
|||||||
</thead>
|
</thead>
|
||||||
<tbody>
|
<tbody>
|
||||||
<tr><td style={{padding: "6px 12px"}}><code>none</code></td><td style={{padding: "6px 12px"}}>0.0</td></tr>
|
<tr><td style={{padding: "6px 12px"}}><code>none</code></td><td style={{padding: "6px 12px"}}>0.0</td></tr>
|
||||||
|
<tr><td style={{padding: "6px 12px"}}><code>minimal</code></td><td style={{padding: "6px 12px"}}>0.1</td></tr>
|
||||||
<tr><td style={{padding: "6px 12px"}}><code>low</code></td><td style={{padding: "6px 12px"}}>0.2</td></tr>
|
<tr><td style={{padding: "6px 12px"}}><code>low</code></td><td style={{padding: "6px 12px"}}>0.2</td></tr>
|
||||||
<tr><td style={{padding: "6px 12px"}}><code>medium</code></td><td style={{padding: "6px 12px"}}>0.7</td></tr>
|
<tr><td style={{padding: "6px 12px"}}><code>medium</code></td><td style={{padding: "6px 12px"}}>0.7</td></tr>
|
||||||
<tr><td style={{padding: "6px 12px"}}><code>high</code></td><td style={{padding: "6px 12px"}}>0.9</td></tr>
|
<tr><td style={{padding: "6px 12px"}}><code>high</code></td><td style={{padding: "6px 12px"}}>0.9</td></tr>
|
||||||
|
|||||||
@@ -687,6 +687,23 @@ class ToolChoice(BaseModel):
|
|||||||
type: Literal["function"] = Field(default="function", examples=["function"])
|
type: Literal["function"] = Field(default="function", examples=["function"])
|
||||||
|
|
||||||
|
|
||||||
|
# OpenAI-spec string tiers for reasoning effort (current Responses/Chat API):
|
||||||
|
# none/minimal/low/medium/high/xhigh/max. Used as-is by /v1/responses.
|
||||||
|
ReasoningEffortTier = Literal[
|
||||||
|
"none", "minimal", "low", "medium", "high", "xhigh", "max"
|
||||||
|
]
|
||||||
|
# Chat Completions and /v1/tokenize additionally accept a fine-grained float in
|
||||||
|
# [0.0, 0.99] as an sglang extension (not part of the OpenAI schema, so the
|
||||||
|
# /v1/responses surface deliberately keeps the string tiers only). Single-sourced
|
||||||
|
# so these surfaces cannot drift apart.
|
||||||
|
ReasoningEffortType = Optional[
|
||||||
|
Union[
|
||||||
|
ReasoningEffortTier,
|
||||||
|
Annotated[float, Field(ge=0.0, le=0.99, allow_inf_nan=False)],
|
||||||
|
]
|
||||||
|
]
|
||||||
|
|
||||||
|
|
||||||
class ChatCompletionRequest(BaseModel):
|
class ChatCompletionRequest(BaseModel):
|
||||||
# Ordered by official OpenAI API documentation
|
# Ordered by official OpenAI API documentation
|
||||||
# https://platform.openai.com/docs/api-reference/chat/create
|
# https://platform.openai.com/docs/api-reference/chat/create
|
||||||
@@ -730,16 +747,11 @@ class ChatCompletionRequest(BaseModel):
|
|||||||
return_cached_tokens_details: bool = False
|
return_cached_tokens_details: bool = False
|
||||||
return_prompt_token_ids: bool = False
|
return_prompt_token_ids: bool = False
|
||||||
return_meta_info: bool = False
|
return_meta_info: bool = False
|
||||||
reasoning_effort: Optional[
|
reasoning_effort: ReasoningEffortType = Field(
|
||||||
Union[
|
|
||||||
Literal["none", "minimal", "low", "medium", "high", "xhigh", "max"],
|
|
||||||
Annotated[float, Field(ge=0.0, le=0.99, allow_inf_nan=False)],
|
|
||||||
]
|
|
||||||
] = Field(
|
|
||||||
default=None,
|
default=None,
|
||||||
description="Constrains effort on reasoning for reasoning models. "
|
description="Constrains effort on reasoning for reasoning models. "
|
||||||
"Accepts string levels ('none', 'minimal', 'low', 'medium', 'high', 'xhigh', 'max') or a "
|
"Accepts string levels ('none', 'minimal', 'low', 'medium', 'high', 'xhigh', 'max') or a "
|
||||||
"float in [0.0, 1.0] for fine-grained control. "
|
"float in [0.0, 0.99] for fine-grained control. "
|
||||||
"'none' disables reasoning entirely, 'low' is the least effort, 'high' is the most effort. "
|
"'none' disables reasoning entirely, 'low' is the least effort, 'high' is the most effort. "
|
||||||
"Reducing reasoning effort can result in faster responses and fewer tokens used on reasoning "
|
"Reducing reasoning effort can result in faster responses and fewer tokens used on reasoning "
|
||||||
"in a response. 'none' defaults thinking and enable_thinking to false in "
|
"in a response. 'none' defaults thinking and enable_thinking to false in "
|
||||||
@@ -858,6 +870,7 @@ class ChatCompletionRequest(BaseModel):
|
|||||||
effort = r.get("reasoning_effort")
|
effort = r.get("reasoning_effort")
|
||||||
if isinstance(effort, str) and effort in {
|
if isinstance(effort, str) and effort in {
|
||||||
"none",
|
"none",
|
||||||
|
"minimal",
|
||||||
"low",
|
"low",
|
||||||
"medium",
|
"medium",
|
||||||
"high",
|
"high",
|
||||||
@@ -1301,9 +1314,7 @@ class TokenizeRequest(BaseModel):
|
|||||||
tool_choice: Optional[Union[ToolChoice, Literal["auto", "required", "none"]]] = (
|
tool_choice: Optional[Union[ToolChoice, Literal["auto", "required", "none"]]] = (
|
||||||
Field(default=None, examples=["auto"])
|
Field(default=None, examples=["auto"])
|
||||||
)
|
)
|
||||||
reasoning_effort: Optional[Literal["none", "minimal", "low", "medium", "high"]] = (
|
reasoning_effort: ReasoningEffortType = None
|
||||||
None
|
|
||||||
)
|
|
||||||
continue_final_message: bool = False
|
continue_final_message: bool = False
|
||||||
chat_template_kwargs: Optional[Dict] = None
|
chat_template_kwargs: Optional[Dict] = None
|
||||||
add_special_tokens: bool = Field(
|
add_special_tokens: bool = Field(
|
||||||
@@ -1369,9 +1380,11 @@ OpenAIServingRequest = Union[
|
|||||||
class ResponseReasoningParam(BaseModel):
|
class ResponseReasoningParam(BaseModel):
|
||||||
"""Reasoning parameters for responses."""
|
"""Reasoning parameters for responses."""
|
||||||
|
|
||||||
effort: Optional[Literal["low", "medium", "high"]] = Field(
|
effort: Optional[ReasoningEffortTier] = Field(
|
||||||
default="medium",
|
default="medium",
|
||||||
description="Constrains effort on reasoning for reasoning models.",
|
description="Constrains effort on reasoning for reasoning models. "
|
||||||
|
"Accepts the OpenAI string tiers "
|
||||||
|
"('none','minimal','low','medium','high','xhigh','max').",
|
||||||
)
|
)
|
||||||
summary: Optional[Literal["auto", "concise", "detailed"]] = Field(
|
summary: Optional[Literal["auto", "concise", "detailed"]] = Field(
|
||||||
default=None,
|
default=None,
|
||||||
|
|||||||
Reference in New Issue
Block a user