mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-09 03:18:44 +00:00
fix(volcengine): handle thinking disabled parameter properly (#13598)
* fix(volcengine): handle thinking disabled parameter properly
When thinking is set to {"type": "disabled"} in volcengine provider config,
skip adding the parameter to extra_body entirely instead of passing it through.
This prevents "thinking: undefined" from appearing in request logs.
Fixes #13039
* test(volcengine): fix and enhance thinking parameter tests
- Fixed existing test that expected broken behavior
- Added comprehensive test coverage for all thinking parameter scenarios:
* thinking disabled → omitted from extra_body
* thinking enabled → included in extra_body
* thinking None → included in extra_body as None
* custom thinking values → included in extra_body
* no thinking parameter → empty result
All tests passing, verifying the fix for issue #13039
This commit is contained in:
parent
b5d0a7eb95
commit
dea98a315b
2 changed files with 73 additions and 11 deletions
|
|
@ -81,8 +81,18 @@ class VolcEngineConfig(OpenAILikeChatConfig):
|
|||
)
|
||||
|
||||
if "thinking" in optional_params:
|
||||
optional_params.setdefault("extra_body", {})["thinking"] = (
|
||||
optional_params.pop("thinking")
|
||||
)
|
||||
thinking_value = optional_params.pop("thinking")
|
||||
|
||||
# Handle disabled thinking case - don't add to extra_body if disabled
|
||||
if (
|
||||
thinking_value is not None
|
||||
and isinstance(thinking_value, dict)
|
||||
and thinking_value.get("type") == "disabled"
|
||||
):
|
||||
# Skip adding thinking parameter when it's disabled
|
||||
pass
|
||||
else:
|
||||
# Add thinking parameter to extra_body for all other cases
|
||||
optional_params.setdefault("extra_body", {})["thinking"] = thinking_value
|
||||
|
||||
return optional_params
|
||||
|
|
|
|||
|
|
@ -14,6 +14,7 @@ class TestVolcEngineConfig:
|
|||
supported_params = config.get_supported_openai_params(model="doubao-seed-1.6")
|
||||
assert "thinking" in supported_params
|
||||
|
||||
# Test thinking disabled - should NOT appear in extra_body
|
||||
mapped_params = config.map_openai_params(
|
||||
non_default_params={
|
||||
"thinking": {"type": "disabled"},
|
||||
|
|
@ -23,11 +24,8 @@ class TestVolcEngineConfig:
|
|||
drop_params=False,
|
||||
)
|
||||
|
||||
assert mapped_params == {
|
||||
"extra_body": {
|
||||
"thinking": {"type": "disabled"},
|
||||
}
|
||||
}
|
||||
# Fixed: thinking disabled should be omitted from extra_body
|
||||
assert mapped_params == {}
|
||||
|
||||
e2e_mapped_params = get_optional_params(
|
||||
model="doubao-seed-1.6",
|
||||
|
|
@ -42,6 +40,61 @@ class TestVolcEngineConfig:
|
|||
"type": "enabled",
|
||||
}
|
||||
|
||||
def test_thinking_parameter_handling(self):
|
||||
"""Test comprehensive thinking parameter handling scenarios"""
|
||||
config = VolcEngineConfig()
|
||||
|
||||
# Test 1: thinking enabled - should appear in extra_body
|
||||
result_enabled = config.map_openai_params(
|
||||
non_default_params={"thinking": {"type": "enabled"}},
|
||||
optional_params={},
|
||||
model="doubao-seed-1.6",
|
||||
drop_params=False,
|
||||
)
|
||||
assert result_enabled == {
|
||||
"extra_body": {"thinking": {"type": "enabled"}}
|
||||
}
|
||||
|
||||
# Test 2: thinking None - should appear in extra_body as None
|
||||
result_none = config.map_openai_params(
|
||||
non_default_params={"thinking": None},
|
||||
optional_params={},
|
||||
model="doubao-seed-1.6",
|
||||
drop_params=False,
|
||||
)
|
||||
assert result_none == {
|
||||
"extra_body": {"thinking": None}
|
||||
}
|
||||
|
||||
# Test 3: thinking with custom value - should appear in extra_body
|
||||
result_custom = config.map_openai_params(
|
||||
non_default_params={"thinking": "custom_mode"},
|
||||
optional_params={},
|
||||
model="doubao-seed-1.6",
|
||||
drop_params=False,
|
||||
)
|
||||
assert result_custom == {
|
||||
"extra_body": {"thinking": "custom_mode"}
|
||||
}
|
||||
|
||||
# Test 4: thinking disabled - should NOT appear in extra_body
|
||||
result_disabled = config.map_openai_params(
|
||||
non_default_params={"thinking": {"type": "disabled"}},
|
||||
optional_params={},
|
||||
model="doubao-seed-1.6",
|
||||
drop_params=False,
|
||||
)
|
||||
assert result_disabled == {}
|
||||
|
||||
# Test 5: No thinking parameter - should return empty dict
|
||||
result_no_thinking = config.map_openai_params(
|
||||
non_default_params={},
|
||||
optional_params={},
|
||||
model="doubao-seed-1.6",
|
||||
drop_params=False,
|
||||
)
|
||||
assert result_no_thinking == {}
|
||||
|
||||
def test_e2e_completion(self):
|
||||
from openai import OpenAI
|
||||
|
||||
|
|
@ -78,6 +131,5 @@ class TestVolcEngineConfig:
|
|||
|
||||
mock_create.assert_called_once()
|
||||
print(mock_create.call_args.kwargs)
|
||||
assert mock_create.call_args.kwargs["extra_body"] == {
|
||||
"thinking": {"type": "disabled"},
|
||||
}
|
||||
# Fixed: thinking disabled should NOT appear in extra_body
|
||||
assert "extra_body" not in mock_create.call_args.kwargs or "thinking" not in mock_create.call_args.kwargs.get("extra_body", {})
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue