Skip to content

Commit f34bbd1

Browse files
Merge pull request #14569 from talesofai/volcengine-fix-thinking-parameters-missing-if-not-set
fix volcengine thinking parameters missing when it set disable
2 parents 3f90fe9 + f8c9009 commit f34bbd1

File tree

2 files changed

+53
-30
lines changed

2 files changed

+53
-30
lines changed

litellm/llms/volcengine/chat/transformation.py

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,9 @@
44

55

66
class VolcEngineChatConfig(OpenAILikeChatConfig):
7+
"""
8+
Reference: https://www.volcengine.com/docs/82379/1494384
9+
"""
710
frequency_penalty: Optional[int] = None
811
function_call: Optional[Union[str, dict]] = None
912
functions: Optional[list] = None
@@ -81,20 +84,22 @@ def map_openai_params(
8184
)
8285

8386
if "thinking" in optional_params:
87+
"""
88+
The `thinking` parameters of VolcEngine model has different default values.
89+
See the docs for details.
90+
Refrence: https://www.volcengine.com/docs/82379/1449737#0002
91+
"""
8492
thinking_value = optional_params.pop("thinking")
8593

86-
# Handle disabled thinking case - don't add to extra_body if disabled
94+
# Handle using thinking params case - add to extra_body if value is legal
8795
if (
8896
thinking_value is not None
8997
and isinstance(thinking_value, dict)
90-
and thinking_value.get("type") == "disabled"
98+
and thinking_value.get("type", None) in ["enabled", "disabled", "auto"] # legal values, see docs
9199
):
92-
# Skip adding thinking parameter when it's disabled
93-
pass
100+
# Add thinking parameter to extra_body for all legal cases
101+
optional_params.setdefault("extra_body", {})["thinking"] = thinking_value
94102
else:
95-
# Add thinking parameter to extra_body for all other cases
96-
optional_params.setdefault("extra_body", {})[
97-
"thinking"
98-
] = thinking_value
99-
103+
# Skip adding thinking parameter when it's not set or has invalid value
104+
pass
100105
return optional_params

tests/test_litellm/llms/volcengine/test_volcengine.py

Lines changed: 39 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ def test_get_optional_params(self):
1414
supported_params = config.get_supported_openai_params(model="doubao-seed-1.6")
1515
assert "thinking" in supported_params
1616

17-
# Test thinking disabled - should NOT appear in extra_body
17+
# Test thinking disabled - should appear in extra_body
1818
mapped_params = config.map_openai_params(
1919
non_default_params={
2020
"thinking": {"type": "disabled"},
@@ -24,8 +24,10 @@ def test_get_optional_params(self):
2424
drop_params=False,
2525
)
2626

27-
# Fixed: thinking disabled should be omitted from extra_body
28-
assert mapped_params == {}
27+
# Fixed: thinking disabled should appear in extra_body
28+
assert mapped_params == {
29+
"extra_body": {"thinking": {"type": "disabled"}}
30+
}
2931

3032
e2e_mapped_params = get_optional_params(
3133
model="doubao-seed-1.6",
@@ -43,7 +45,7 @@ def test_get_optional_params(self):
4345
def test_thinking_parameter_handling(self):
4446
"""Test comprehensive thinking parameter handling scenarios"""
4547
config = VolcEngineConfig()
46-
48+
4749
# Test 1: thinking enabled - should appear in extra_body
4850
result_enabled = config.map_openai_params(
4951
non_default_params={"thinking": {"type": "enabled"}},
@@ -54,38 +56,36 @@ def test_thinking_parameter_handling(self):
5456
assert result_enabled == {
5557
"extra_body": {"thinking": {"type": "enabled"}}
5658
}
57-
58-
# Test 2: thinking None - should appear in extra_body as None
59+
60+
# Test 2: thinking None - should NOT appear in extra_body
5961
result_none = config.map_openai_params(
6062
non_default_params={"thinking": None},
6163
optional_params={},
62-
model="doubao-seed-1.6",
64+
model="doubao-seed-1.6",
6365
drop_params=False,
6466
)
65-
assert result_none == {
66-
"extra_body": {"thinking": None}
67-
}
68-
69-
# Test 3: thinking with custom value - should appear in extra_body
67+
assert result_none == {}
68+
69+
# Test 3: thinking with custom value - should NOT appear in extra_body (invalid value)
7070
result_custom = config.map_openai_params(
7171
non_default_params={"thinking": "custom_mode"},
7272
optional_params={},
7373
model="doubao-seed-1.6",
7474
drop_params=False,
7575
)
76-
assert result_custom == {
77-
"extra_body": {"thinking": "custom_mode"}
78-
}
79-
80-
# Test 4: thinking disabled - should NOT appear in extra_body
76+
assert result_custom == {}
77+
78+
# Test 4: thinking disabled - should appear in extra_body with original structure
8179
result_disabled = config.map_openai_params(
8280
non_default_params={"thinking": {"type": "disabled"}},
8381
optional_params={},
8482
model="doubao-seed-1.6",
8583
drop_params=False,
8684
)
87-
assert result_disabled == {}
88-
85+
assert result_disabled == {
86+
"extra_body": {"thinking": {"type": "disabled"}}
87+
}
88+
8989
# Test 5: No thinking parameter - should return empty dict
9090
result_no_thinking = config.map_openai_params(
9191
non_default_params={},
@@ -95,6 +95,24 @@ def test_thinking_parameter_handling(self):
9595
)
9696
assert result_no_thinking == {}
9797

98+
# Test 6: invalid thinking type - should NOT appear in extra_body (invalid type)
99+
result_no_thinking = config.map_openai_params(
100+
non_default_params={"thinking": {"type": "invalid_type"}},
101+
optional_params={},
102+
model="doubao-seed-1.6",
103+
drop_params=False,
104+
)
105+
assert result_no_thinking == {}
106+
107+
# Test 7: invalid thinking type - should NOT appear in extra_body (value is None)
108+
result_no_thinking = config.map_openai_params(
109+
non_default_params={"thinking": {"type": None}},
110+
optional_params={},
111+
model="doubao-seed-1.6",
112+
drop_params=False,
113+
)
114+
assert result_no_thinking == {}
115+
98116
def test_e2e_completion(self):
99117
from openai import OpenAI
100118

@@ -131,5 +149,5 @@ def test_e2e_completion(self):
131149

132150
mock_create.assert_called_once()
133151
print(mock_create.call_args.kwargs)
134-
# Fixed: thinking disabled should NOT appear in extra_body
135-
assert "extra_body" not in mock_create.call_args.kwargs or "thinking" not in mock_create.call_args.kwargs.get("extra_body", {})
152+
# Fixed: thinking disabled should appear in extra_body with original structure
153+
assert "extra_body" in mock_create.call_args.kwargs and "thinking" in mock_create.call_args.kwargs.get("extra_body", {}) and mock_create.call_args.kwargs.get("extra_body", {})["thinking"] == {"type": "disabled"}

0 commit comments

Comments
 (0)