The fastest, litest AI Gateway. Rust core with Python SDK. Call 100+ LLM APIs in OpenAI (or native) format with cost tracking, guardrails, load balancing, and logging [Bedrock, Azure, OpenAI, Anthropic, OpenAI, VertexAI, vLLM, Nvidia NIM]
Python ai-gatewayanthropicazure-openaibedrockgatewaylangchainlitellmllmllm-gatewayllmopsmcp-gatewayopenaiopenai-proxyrustrust-aivertex-ai
fix volcengine thinking parameters missing if set disable
LingXuanYinbf7868bb0e05
diff --git a/litellm/llms/volcengine/chat/transformation.py b/litellm/llms/volcengine/chat/transformation.pyindex 216570a1aba..62073a1a2df 100644--- a/litellm/llms/volcengine/chat/transformation.py+++ b/litellm/llms/volcengine/chat/transformation.py@@ -4,6 +4,9 @@ from litellm.llms.openai_like.chat.transformation import OpenAILikeChatConfigclass VolcEngineChatConfig(OpenAILikeChatConfig):+ """+ Reference: https://www.volcengine.com/docs/82379/1494384+ """frequency_penalty: Optional[int] = Nonefunction_call: Optional[Union[str, dict]] = Nonefunctions: 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 legalif (thinking_value is not Noneand 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+ passreturn optional_paramsdiff --git a/tests/test_litellm/llms/volcengine/test_volcengine.py b/tests/test_litellm/llms/volcengine/test_volcengine.pyindex 59317914192..e02a781789e 100644--- a/tests/test_litellm/llms/volcengine/test_volcengine.py+++ b/tests/test_litellm/llms/volcengine/test_volcengine.py@@ -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_bodymapped_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_bodyresult_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_bodyresult_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 structureresult_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 dictresult_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"}