mirror of
https://github.com/tiennm99/litellm.git
synced 2026-07-11 03:04:02 +00:00
fix volcengine thinking parameters missing if set disable
update test volcengine
This commit is contained in:
@@ -4,6 +4,9 @@ from litellm.llms.openai_like.chat.transformation import OpenAILikeChatConfig
|
||||
|
||||
|
||||
class VolcEngineChatConfig(OpenAILikeChatConfig):
|
||||
"""
|
||||
Reference: https://www.volcengine.com/docs/82379/1494384
|
||||
"""
|
||||
frequency_penalty: Optional[int] = None
|
||||
function_call: Optional[Union[str, dict]] = None
|
||||
functions: Optional[list] = None
|
||||
@@ -81,20 +84,22 @@ class VolcEngineChatConfig(OpenAILikeChatConfig):
|
||||
)
|
||||
|
||||
if "thinking" in optional_params:
|
||||
"""
|
||||
The `thinking` parameters of VolcEngine model has different default values.
|
||||
See the docs for details.
|
||||
Refrence: https://www.volcengine.com/docs/82379/1449737#0002
|
||||
"""
|
||||
thinking_value = optional_params.pop("thinking")
|
||||
|
||||
# Handle disabled thinking case - don't add to extra_body if disabled
|
||||
# Handle using thinking params case - add to extra_body if value is legal
|
||||
if (
|
||||
thinking_value is not None
|
||||
and isinstance(thinking_value, dict)
|
||||
and thinking_value.get("type") == "disabled"
|
||||
and thinking_value.get("type", None) in ["enabled", "disabled", "auto"], # legal values, see docs
|
||||
):
|
||||
# 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
|
||||
|
||||
optional_params.setdefault("extra_body", {})["thinking"] = thinking_value
|
||||
else:
|
||||
# Skip adding thinking parameter when it's not set
|
||||
pass
|
||||
return optional_params
|
||||
|
||||
@@ -14,7 +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
|
||||
# Test thinking disabled - should appear in extra_body
|
||||
mapped_params = config.map_openai_params(
|
||||
non_default_params={
|
||||
"thinking": {"type": "disabled"},
|
||||
@@ -25,7 +25,9 @@ class TestVolcEngineConfig:
|
||||
)
|
||||
|
||||
# Fixed: thinking disabled should be omitted from extra_body
|
||||
assert mapped_params == {}
|
||||
assert mapped_params == {
|
||||
"extra_body": {"thinking": {"type": "disabled"}}
|
||||
}
|
||||
|
||||
e2e_mapped_params = get_optional_params(
|
||||
model="doubao-seed-1.6",
|
||||
@@ -43,7 +45,7 @@ class TestVolcEngineConfig:
|
||||
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"}},
|
||||
@@ -54,38 +56,36 @@ class TestVolcEngineConfig:
|
||||
assert result_enabled == {
|
||||
"extra_body": {"thinking": {"type": "enabled"}}
|
||||
}
|
||||
|
||||
# Test 2: thinking None - should appear in extra_body as None
|
||||
|
||||
# Test 2: thinking None - should NOT appear in extra_body
|
||||
result_none = config.map_openai_params(
|
||||
non_default_params={"thinking": None},
|
||||
optional_params={},
|
||||
model="doubao-seed-1.6",
|
||||
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
|
||||
assert result_none == {}
|
||||
|
||||
# Test 3: thinking with custom value - should NOT appear in extra_body (invalid value)
|
||||
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
|
||||
assert result_custom == {}
|
||||
|
||||
# Test 4: thinking disabled - should appear in extra_body with original structure
|
||||
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 == {}
|
||||
|
||||
assert result_disabled == {
|
||||
"extra_body": {"thinking": {"type": "disabled"}}
|
||||
}
|
||||
|
||||
# Test 5: No thinking parameter - should return empty dict
|
||||
result_no_thinking = config.map_openai_params(
|
||||
non_default_params={},
|
||||
@@ -131,5 +131,5 @@ class TestVolcEngineConfig:
|
||||
|
||||
mock_create.assert_called_once()
|
||||
print(mock_create.call_args.kwargs)
|
||||
# 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", {})
|
||||
# Fixed: thinking disabled should appear in extra_body with original structure
|
||||
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"}
|
||||
|
||||
Reference in New Issue
Block a user