Unverified Commit 3fd1431d authored by gongwei-130's avatar gongwei-130 Committed by GitHub
Browse files

support enable in the reasoning field to enable thingking for thinkin… (#9715)

parent 161e9dc5
...@@ -460,6 +460,34 @@ class ChatCompletionRequest(BaseModel): ...@@ -460,6 +460,34 @@ class ChatCompletionRequest(BaseModel):
values["tool_choice"] = "auto" values["tool_choice"] = "auto"
return values return values
@model_validator(mode="before")
@classmethod
def normalize_reasoning_inputs(cls, values: Dict):
r = values.get("reasoning")
if r is None:
return values
if isinstance(r, dict):
effort = r.get("effort") or r.get("reasoning_effort")
if effort in {"low", "medium", "high"}:
values["reasoning_effort"] = effort
enabled = (
r.get("enabled")
if r.get("enabled") is not None
else r.get("enable", False)
)
if isinstance(enabled, str):
enabled = enabled.strip().lower() in {"1", "true", "yes", "y", "on"}
if enabled:
ctk = values.get("chat_template_kwargs")
if not isinstance(ctk, dict):
ctk = {}
ctk.setdefault("thinking", True)
values["chat_template_kwargs"] = ctk
return values
@model_validator(mode="before") @model_validator(mode="before")
@classmethod @classmethod
def set_json_schema(cls, values): def set_json_schema(cls, values):
......
...@@ -192,6 +192,20 @@ class TestChatCompletionRequest(unittest.TestCase): ...@@ -192,6 +192,20 @@ class TestChatCompletionRequest(unittest.TestCase):
self.assertFalse(request.stream_reasoning) self.assertFalse(request.stream_reasoning)
self.assertEqual(request.chat_template_kwargs, {"custom_param": "value"}) self.assertEqual(request.chat_template_kwargs, {"custom_param": "value"})
def test_chat_completion_reasoning_effort(self):
"""Test chat completion with reasoning effort"""
messages = [{"role": "user", "content": "Hello"}]
request = ChatCompletionRequest(
model="test-model",
messages=messages,
reasoning={
"enabled": True,
"reasoning_effort": "high",
},
)
self.assertEqual(request.reasoning_effort, "high")
self.assertEqual(request.chat_template_kwargs, {"thinking": True})
def test_chat_completion_json_format(self): def test_chat_completion_json_format(self):
"""Test chat completion json format""" """Test chat completion json format"""
transcript = "Good morning! It's 7:00 AM, and I'm just waking up. Today is going to be a busy day, " transcript = "Good morning! It's 7:00 AM, and I'm just waking up. Today is going to be a busy day, "
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment