mirror of
https://github.com/BerriAI/litellm.git
synced 2026-10-08 03:08:45 +00:00
Support Deepseek 3.2 with Reasoning (#17384)
* Add openrouter/deepseek/deepseek-v3.2 * Added deepseek-provided v3.2 * Allow reasoning effort param for openrouter models that support it * Added tests
This commit is contained in:
parent
099ccf56a7
commit
f22bc0aab2
3 changed files with 72 additions and 0 deletions
|
|
@ -10,6 +10,7 @@ from enum import Enum
|
|||
from typing import Any, AsyncIterator, Iterator, List, Optional, Tuple, Union, cast
|
||||
|
||||
import httpx
|
||||
import litellm
|
||||
|
||||
from litellm.llms.base_llm.base_model_iterator import BaseModelResponseIterator
|
||||
from litellm.llms.base_llm.chat.transformation import BaseLLMException
|
||||
|
|
@ -28,6 +29,20 @@ class CacheControlSupportedModels(str, Enum):
|
|||
|
||||
|
||||
class OpenrouterConfig(OpenAIGPTConfig):
|
||||
def get_supported_openai_params(self, model: str) -> list:
|
||||
"""
|
||||
Allow reasoning parameters for models flagged as reasoning-capable.
|
||||
"""
|
||||
supported_params = super().get_supported_openai_params(model=model)
|
||||
try:
|
||||
if litellm.supports_reasoning(
|
||||
model=model, custom_llm_provider="openrouter"
|
||||
) or litellm.supports_reasoning(model=model):
|
||||
supported_params.append("reasoning_effort")
|
||||
except Exception:
|
||||
pass
|
||||
return list(dict.fromkeys(supported_params))
|
||||
|
||||
def map_openai_params(
|
||||
self,
|
||||
non_default_params: dict,
|
||||
|
|
|
|||
|
|
@ -9629,6 +9629,21 @@
|
|||
"supports_prompt_caching": true,
|
||||
"supports_tool_choice": true
|
||||
},
|
||||
"deepseek/deepseek-v3.2": {
|
||||
"input_cost_per_token": 2.8e-07,
|
||||
"input_cost_per_token_cache_hit": 2.8e-08,
|
||||
"litellm_provider": "deepseek",
|
||||
"max_input_tokens": 163840,
|
||||
"max_output_tokens": 163840,
|
||||
"max_tokens": 8192,
|
||||
"mode": "chat",
|
||||
"output_cost_per_token": 4e-07,
|
||||
"supports_assistant_prefill": true,
|
||||
"supports_function_calling": true,
|
||||
"supports_prompt_caching": true,
|
||||
"supports_reasoning": true,
|
||||
"supports_tool_choice": true
|
||||
},
|
||||
"deepseek.v3-v1:0": {
|
||||
"input_cost_per_token": 5.8e-07,
|
||||
"litellm_provider": "bedrock_converse",
|
||||
|
|
@ -20565,6 +20580,21 @@
|
|||
"supports_reasoning": true,
|
||||
"supports_tool_choice": true
|
||||
},
|
||||
"openrouter/deepseek/deepseek-v3.2": {
|
||||
"input_cost_per_token": 2.8e-07,
|
||||
"input_cost_per_token_cache_hit": 2.8e-08,
|
||||
"litellm_provider": "openrouter",
|
||||
"max_input_tokens": 163840,
|
||||
"max_output_tokens": 163840,
|
||||
"max_tokens": 8192,
|
||||
"mode": "chat",
|
||||
"output_cost_per_token": 4e-07,
|
||||
"supports_assistant_prefill": true,
|
||||
"supports_function_calling": true,
|
||||
"supports_prompt_caching": true,
|
||||
"supports_reasoning": true,
|
||||
"supports_tool_choice": true
|
||||
},
|
||||
"openrouter/deepseek/deepseek-v3.2-exp": {
|
||||
"input_cost_per_token": 2e-07,
|
||||
"input_cost_per_token_cache_hit": 2e-08,
|
||||
|
|
|
|||
|
|
@ -489,3 +489,30 @@ def test_openrouter_cost_tracking_streaming():
|
|||
# Verify cost field is preserved in the Usage object - this is the key data for cost tracking
|
||||
# The chunk_parser converts the dict to a Usage Pydantic model which includes the cost field
|
||||
assert result2.usage.cost == 0.0001
|
||||
|
||||
|
||||
def test_openrouter_reasoning_models_allow_reasoning_effort_param():
|
||||
"""
|
||||
OpenRouter reasoning-capable models should accept the reasoning_effort param.
|
||||
"""
|
||||
config = OpenrouterConfig()
|
||||
|
||||
supported_params = config.get_supported_openai_params(
|
||||
model="openrouter/deepseek/deepseek-v3.2"
|
||||
)
|
||||
|
||||
assert "reasoning_effort" in supported_params
|
||||
assert supported_params.count("reasoning_effort") == 1
|
||||
|
||||
|
||||
def test_openrouter_non_reasoning_models_do_not_add_reasoning_effort():
|
||||
"""
|
||||
Models without reasoning support should not gain reasoning-specific params.
|
||||
"""
|
||||
config = OpenrouterConfig()
|
||||
|
||||
supported_params = config.get_supported_openai_params(
|
||||
model="openrouter/anthropic/claude-3-5-haiku"
|
||||
)
|
||||
|
||||
assert "reasoning_effort" not in supported_params
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue