mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-07 08:26:10 +00:00
fix(proxy): expose configured model mode
This commit is contained in:
parent
92122086ec
commit
425e3069b9
4 changed files with 57 additions and 2 deletions
|
|
@ -7531,6 +7531,9 @@ def create_model_info_response(
|
||||||
max_input_tokens = configured_input
|
max_input_tokens = configured_input
|
||||||
if configured_output is not None:
|
if configured_output is not None:
|
||||||
max_output_tokens = configured_output
|
max_output_tokens = configured_output
|
||||||
|
configured_mode: Final = llm_router.get_configured_mode(model_id)
|
||||||
|
if isinstance(configured_mode, str):
|
||||||
|
base["mode"] = configured_mode
|
||||||
|
|
||||||
if max_input_tokens is not None:
|
if max_input_tokens is not None:
|
||||||
base["max_input_tokens"] = max_input_tokens
|
base["max_input_tokens"] = max_input_tokens
|
||||||
|
|
|
||||||
|
|
@ -9981,6 +9981,17 @@ class Router:
|
||||||
coerce_token_limit(model_info.get("max_output_tokens")),
|
coerce_token_limit(model_info.get("max_output_tokens")),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
def get_configured_mode(self, model_name: str) -> "str | None":
|
||||||
|
"""Return the mode explicitly configured for a concrete deployment."""
|
||||||
|
deployment: Final = self.get_deployment_by_model_group_name(model_group_name=model_name)
|
||||||
|
if deployment is None:
|
||||||
|
return None
|
||||||
|
|
||||||
|
mode: Final = deployment.model_info.get("mode")
|
||||||
|
if isinstance(mode, str) and mode.strip():
|
||||||
|
return mode
|
||||||
|
return None
|
||||||
|
|
||||||
def get_configured_display_name(self, model_name: str) -> "str | None":
|
def get_configured_display_name(self, model_name: str) -> "str | None":
|
||||||
"""
|
"""
|
||||||
Return the display_name explicitly configured in a concrete deployment's
|
Return the display_name explicitly configured in a concrete deployment's
|
||||||
|
|
|
||||||
|
|
@ -11,8 +11,8 @@ class ModelInfoMetadata(TypedDict):
|
||||||
|
|
||||||
class ModelInfoResponse(TypedDict):
|
class ModelInfoResponse(TypedDict):
|
||||||
"""OpenAI-compatible model object. `mode`, `max_input_tokens`, and
|
"""OpenAI-compatible model object. `mode`, `max_input_tokens`, and
|
||||||
`max_output_tokens` are attached when the cost map knows them; `metadata`
|
`max_output_tokens` are attached when the cost map or deployment config
|
||||||
is present only when the endpoint is called with include_metadata=true.
|
knows them; `metadata` is present only with include_metadata=true.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
id: str
|
id: str
|
||||||
|
|
|
||||||
|
|
@ -942,6 +942,47 @@ def test_create_model_info_response_uses_deployment_limits_when_not_in_cost_map(
|
||||||
assert response["max_output_tokens"] == 8000
|
assert response["max_output_tokens"] == 8000
|
||||||
|
|
||||||
|
|
||||||
|
def test_create_model_info_response_uses_deployment_mode_for_auto_router():
|
||||||
|
router = litellm.Router(
|
||||||
|
model_list=[
|
||||||
|
{
|
||||||
|
"model_name": "claude-sonnet",
|
||||||
|
"litellm_params": {"model": "openai/gpt-4o-mini", "api_key": "test-key"},
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"model_name": "claude-auto",
|
||||||
|
"litellm_params": {
|
||||||
|
"model": "auto_router/complexity_router",
|
||||||
|
"complexity_router_config": {
|
||||||
|
"tiers": {
|
||||||
|
"SIMPLE": "claude-sonnet",
|
||||||
|
"MEDIUM": "claude-sonnet",
|
||||||
|
"COMPLEX": "claude-sonnet",
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"complexity_router_default_model": "claude-sonnet",
|
||||||
|
},
|
||||||
|
"model_info": {
|
||||||
|
"mode": "chat",
|
||||||
|
"max_input_tokens": 1_000_000,
|
||||||
|
"max_output_tokens": 128_000,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
]
|
||||||
|
)
|
||||||
|
|
||||||
|
response = create_model_info_response(
|
||||||
|
model_id="claude-auto",
|
||||||
|
provider="openai",
|
||||||
|
llm_router=router,
|
||||||
|
get_model_info=_raise_unmapped,
|
||||||
|
)
|
||||||
|
|
||||||
|
assert response["mode"] == "chat"
|
||||||
|
assert response["max_input_tokens"] == 1_000_000
|
||||||
|
assert response["max_output_tokens"] == 128_000
|
||||||
|
|
||||||
|
|
||||||
def test_create_model_info_response_deployment_limits_override_cost_map():
|
def test_create_model_info_response_deployment_limits_override_cost_map():
|
||||||
router = MagicMock()
|
router = MagicMock()
|
||||||
router.get_configured_token_limits.return_value = (200000, None)
|
router.get_configured_token_limits.return_value = (200000, None)
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue