diff --git a/litellm/router.py b/litellm/router.py index 303b22c9484..2b8b342d253 100644 --- a/litellm/router.py +++ b/litellm/router.py @@ -50,6 +50,7 @@ from litellm.constants import ( DEFAULT_HEALTH_CHECK_INTERVAL, DEFAULT_HEALTH_CHECK_STALENESS_MULTIPLIER, DEFAULT_MAX_LRU_CACHE_SIZE, + INTERNAL_CALL_ORIGIN_METADATA_KEY, RUNTIME_UPDATABLE_ROUTER_SETTINGS, SESSION_DEPLOYMENT_AFFINITY_TTL_METADATA_KEY, ) @@ -231,6 +232,7 @@ from litellm.types.router import ( ) from litellm.types.services import ServiceTypes from litellm.types.utils import ( + AUTOROUTER_CLASSIFIER_CALL_ORIGIN, PROMPT_QUOTING_ROUTING_DECISION_FIELDS, CustomPricingLiteLLMParams, GenericBudgetConfigType, @@ -2168,6 +2170,76 @@ class Router: verbose_router_logger.debug("Error occurred while printing deployment - %s", e) raise e + @staticmethod + def _deployment_params_with_request_reasoning_override( + deployment_params: Mapping[str, object], request_kwargs: Mapping[str, object] + ) -> dict[str, object]: # mutable-ok: litellm's request pipeline consumes a mutable kwargs mapping + """Return deployment params whose equivalent effort controls cannot outrank a request override. + + Providers expose the same setting through several native carriers. A request-level + ``reasoning_effort`` is the portable override, so a deployment's ``thinking`` or nested + ``*.effort`` must not remain beside it and either win or trigger a conflicting-params 400. + Every changed mapping is copied so the Router's shared deployment config stays immutable. + """ + sanitized: Final = dict(deployment_params) # mutable-ok: request-local copy protects shared Router state + if request_kwargs.get("reasoning_effort") is None: + return sanitized + + sanitized.pop("thinking", None) + Router._pop_effort_from_nested_carrier(sanitized, "output_config") + Router._pop_effort_from_nested_carrier(sanitized, "reasoning") + + extra_body: Final = sanitized.get("extra_body") + if isinstance(extra_body, Mapping): + sanitized_extra_body: Final = dict(extra_body) # mutable-ok: request-local nested copy + sanitized_extra_body.pop("reasoning_effort", None) + sanitized_extra_body.pop("thinking", None) + Router._pop_effort_from_nested_carrier(sanitized_extra_body, "output_config") + Router._pop_effort_from_nested_carrier(sanitized_extra_body, "reasoning") + if sanitized_extra_body: + sanitized["extra_body"] = sanitized_extra_body + else: + sanitized.pop("extra_body", None) + return sanitized + + @staticmethod + def _is_classifier_internal_call(kwargs: Mapping[str, object]) -> bool: + metadata: Final = kwargs.get("metadata") + litellm_metadata: Final = kwargs.get("litellm_metadata") + return any( + isinstance(candidate, Mapping) + and candidate.get(INTERNAL_CALL_ORIGIN_METADATA_KEY) == AUTOROUTER_CLASSIFIER_CALL_ORIGIN + for candidate in (metadata, litellm_metadata) + ) + + def _drop_unsupported_classifier_reasoning_effort( + self, + deployment: DeploymentTypedDict, + model: str, + kwargs: dict[str, object], # mutable-ok: fallback must update the active request and its log body together + ) -> None: + """Let a classifier fallback without reasoning support remain a usable fallback. + + The dashboard only offers explicitly advertised levels, but an existing config can outlive + a model change and fallbacks can target a different group. Unknown capability fails open; + only a provider that explicitly rejects the parameter has it removed. + """ + if kwargs.get("reasoning_effort") is None or not self._is_classifier_internal_call(kwargs): + return + if self._deployment_accepts_param(deployment, model, "reasoning_effort"): + return + verbose_router_logger.warning( + "litellm.router.py: dropping classifier reasoning_effort for model=%s because the selected deployment does not support it", + model, + ) + kwargs.pop("reasoning_effort", None) + proxy_server_request: Final = kwargs.get("proxy_server_request") + if not isinstance(proxy_server_request, dict): + return + body: Final = proxy_server_request.get("body") + if isinstance(body, dict): + body.pop("reasoning_effort", None) + ### COMPLETION, EMBEDDING, IMG GENERATION FUNCTIONS def completion(self, model: str, messages: list[dict[str, str]], **kwargs) -> ModelResponse | CustomStreamWrapper: @@ -2203,9 +2275,16 @@ class Router: specific_deployment=kwargs.pop("specific_deployment", None), request_kwargs=kwargs, ) + self._drop_unsupported_classifier_reasoning_effort( + deployment=cast(DeploymentTypedDict, deployment), # cast-ok: selection returns a router deployment + model=model, + kwargs=kwargs, + ) # Check for silent model experiment # Make a local copy of litellm_params to avoid mutating the Router's state - litellm_params: Final = deployment["litellm_params"].copy() + litellm_params: Final = self._deployment_params_with_request_reasoning_override( + deployment["litellm_params"], kwargs + ) silent_model: Final = litellm_params.pop("silent_model", None) if silent_model is not None: @@ -3216,6 +3295,11 @@ class Router: specific_deployment=kwargs.pop("specific_deployment", None), request_kwargs=kwargs, ) + self._drop_unsupported_classifier_reasoning_effort( + deployment=cast(DeploymentTypedDict, deployment), # cast-ok: selection returns a router deployment + model=model, + kwargs=kwargs, + ) _timeout_debug_deployment_dict = deployment end_time: Final = time.time() @@ -3237,7 +3321,9 @@ class Router: # Check for silent model experiment # Make a local copy of litellm_params to avoid mutating the Router's state - litellm_params: Final = deployment["litellm_params"].copy() + litellm_params: Final = self._deployment_params_with_request_reasoning_override( + deployment["litellm_params"], kwargs + ) silent_model: Final = litellm_params.pop("silent_model", None) if silent_model is not None: @@ -10255,6 +10341,8 @@ class Router: total_itpm: int | None = None total_otpm: int | None = None configurable_clientside_auth_params: CONFIGURABLE_CLIENTSIDE_AUTH_PARAMS = None + reasoning_efforts_initialized = False + reasoning_efforts_unknown = False model_list: Final = self.get_model_list(model_name=model_group) if model_list is None: return None @@ -10441,10 +10529,23 @@ class Router: if model_info.get("rpm", None) is not None and _deployment_rpm is None: _deployment_rpm = model_info.get("rpm") - model_group_info.supported_reasoning_efforts = intersect_supported_reasoning_efforts( - model_group_info.supported_reasoning_efforts, - resolve_supported_reasoning_efforts(model_info, deployment_is_mapped=deployment_is_mapped), + deployment_reasoning_efforts = ( + resolve_supported_reasoning_efforts( # rebind-ok: recalculated per deployment + model_info, deployment_is_mapped=deployment_is_mapped + ) ) + if deployment_reasoning_efforts is None: + reasoning_efforts_unknown = True + model_group_info.supported_reasoning_efforts = None + elif not reasoning_efforts_initialized: + reasoning_efforts_initialized = True + if not reasoning_efforts_unknown: + model_group_info.supported_reasoning_efforts = deployment_reasoning_efforts + elif not reasoning_efforts_unknown: + model_group_info.supported_reasoning_efforts = intersect_supported_reasoning_efforts( + model_group_info.supported_reasoning_efforts, + deployment_reasoning_efforts, + ) if _deployment_tpm is not None: if total_tpm is None: @@ -12308,10 +12409,12 @@ class Router: @staticmethod def _pop_effort_from_nested_carrier(request_kwargs: dict[str, object], carrier: str) -> None: nested: Final = request_kwargs.get(carrier) - if not isinstance(nested, dict): + if not isinstance(nested, Mapping): return - nested.pop("effort", None) - if not nested: + sanitized: Final = {key: value for key, value in nested.items() if key != "effort"} + if sanitized: + request_kwargs[carrier] = sanitized # rebind-ok: copy-on-write, so a shared nested carrier is never edited + else: request_kwargs.pop(carrier, None) @staticmethod diff --git a/litellm/router_strategy/complexity_router/README.md b/litellm/router_strategy/complexity_router/README.md index ee51add1ca1..e3da70f50fe 100644 --- a/litellm/router_strategy/complexity_router/README.md +++ b/litellm/router_strategy/complexity_router/README.md @@ -255,7 +255,8 @@ model_list: classifier_type: heuristic_first heuristic_first_max_tier: SIMPLE classifier_llm_config: - model: gpt-4o-mini + model: gpt-5-mini + reasoning_effort: low tiers: SIMPLE: gpt-4o-mini MEDIUM: gpt-4o @@ -263,6 +264,10 @@ model_list: REASONING: o1-preview ``` +`classifier_llm_config.reasoning_effort` applies only to the internal classifier call. Omit it to +keep the classifier deployment or provider default, or set a supported value such as `none` or +`low` to override that call. + A request short-circuits, meaning it routes on the scorer's own tier with no classifier call, when two things hold: the scorer landed at or below `heuristic_first_max_tier`, and it produced at least one signal. Everything else goes to the classifier, which then decides as it normally would. diff --git a/litellm/router_strategy/complexity_router/complexity_router.py b/litellm/router_strategy/complexity_router/complexity_router.py index a00ae6bee80..17e3d1256d0 100644 --- a/litellm/router_strategy/complexity_router/complexity_router.py +++ b/litellm/router_strategy/complexity_router/complexity_router.py @@ -28,6 +28,7 @@ from pydantic import BaseModel, create_model from litellm._logging import verbose_router_logger from litellm.constants import ( EMPTY_MAPPING, + INTERNAL_CALL_ORIGIN_METADATA_KEY, RETURN_RAW_MODEL_NAME_METADATA_KEY, SESSION_ID_GENERATED_METADATA_KEY, ) @@ -42,6 +43,7 @@ from litellm.router_strategy.complexity_router.tier_predictor import ( TierSuccessPredictor, resolve_tier_artifact, ) +from litellm.types.llms.openai import AllMessageValues from litellm.types.utils import ( AUTOROUTER_CLASSIFIER_CALL_ORIGIN, ModelResponse, @@ -1668,20 +1670,27 @@ class ComplexityRouter(CustomLogger): ) request_metadata = (request_kwargs or {}).get("litellm_metadata") or (request_kwargs or {}).get("metadata") - metadata: Final = forwarded_internal_call_metadata(request_metadata, AUTOROUTER_CLASSIFIER_CALL_ORIGIN) + metadata: Final = { # mutable-ok: SDK metadata kwarg is enriched by the request pipeline + **forwarded_internal_call_metadata(request_metadata, AUTOROUTER_CLASSIFIER_CALL_ORIGIN), + INTERNAL_CALL_ORIGIN_METADATA_KEY: AUTOROUTER_CLASSIFIER_CALL_ORIGIN, + } turn_off_message_logging: Final = _effective_turn_off_message_logging(request_kwargs) - messages_for_call: Final = [ + messages_for_call: Final[list[AllMessageValues]] = [ # mutable-ok: SDK request payload list is built once {"role": "system", "content": classifier_system_prompt}, {"role": "user", "content": user_payload}, ] response_format: Final = classifier_response_format + classifier_call_params: Mapping[str, str] = EMPTY_MAPPING + if llm_config.reasoning_effort is not None: + classifier_call_params = MappingProxyType({"reasoning_effort": llm_config.reasoning_effort}) proxy_server_request: Final = { "body": { "model": llm_config.model, "messages": messages_for_call, "response_format": response_format, + **classifier_call_params, } } @@ -1693,6 +1702,7 @@ class ComplexityRouter(CustomLogger): metadata=metadata, proxy_server_request=proxy_server_request, turn_off_message_logging=turn_off_message_logging, + **classifier_call_params, **_parent_session_kwargs(request_kwargs), ) content: Final = response.choices[0].message.content diff --git a/litellm/router_strategy/complexity_router/config.py b/litellm/router_strategy/complexity_router/config.py index 9f2054dda01..70c1b281e31 100644 --- a/litellm/router_strategy/complexity_router/config.py +++ b/litellm/router_strategy/complexity_router/config.py @@ -12,6 +12,7 @@ from typing import Annotated, Final, Literal from pydantic import BaseModel, ConfigDict, Field, SkipValidation, field_serializer, field_validator, model_validator +from litellm.types.llms.openai import REASONING_EFFORT from litellm.types.router import AdaptiveRouterWeights, ClassifierPlugin, RoutingPlugin from .tier_predictor import TrainedTierArtifact @@ -432,6 +433,13 @@ class ClassifierLLMConfig(BaseModel): model: str = Field( description="Model name (from the router's model_list) to call for classification", ) + reasoning_effort: REASONING_EFFORT | None = Field( + default=None, + description=( + "Reasoning effort override for classifier calls. Leave unset to use " + "the classifier deployment or provider default." + ), + ) timeout_ms: int = Field( default=3000, description="Timeout budget for the classification call, in milliseconds", diff --git a/tests/test_litellm/router_strategy/test_complexity_router.py b/tests/test_litellm/router_strategy/test_complexity_router.py index 3ecccb673f3..aa1b51afe10 100644 --- a/tests/test_litellm/router_strategy/test_complexity_router.py +++ b/tests/test_litellm/router_strategy/test_complexity_router.py @@ -1558,6 +1558,14 @@ class TestLLMClassifierConfig: assert config.classifier_type == "heuristic" assert config.classifier_llm_config is None + @pytest.mark.parametrize("reasoning_effort", ["", "ultra"]) + def test_classifier_reasoning_effort_rejects_unsupported_values(self, reasoning_effort): + with pytest.raises(ValidationError): + ComplexityRouterConfig( + classifier_type="llm", + classifier_llm_config={"model": "haiku-classifier", "reasoning_effort": reasoning_effort}, + ) + CUSTOM_TIER_LABELS: Dict[str, str] = { "SIMPLE": "Cheap", @@ -1871,6 +1879,19 @@ class TestLLMClassifier: call_kwargs = mock_router_instance.acompletion.call_args.kwargs assert call_kwargs["metadata"] == {**request_metadata, "internal_call_origin": "autorouter_classifier"} + @pytest.mark.asyncio + async def test_aclassify_stamps_internal_origin_without_caller_metadata( + self, llm_complexity_router, mock_router_instance + ): + """Fallback handling must still recognize the classifier when an SDK caller supplied no metadata.""" + mock_router_instance.acompletion = AsyncMock(return_value=_llm_response('{"tier": "SIMPLE"}')) + + await llm_complexity_router.aclassify("hi") + + assert mock_router_instance.acompletion.call_args.kwargs["metadata"] == { + "internal_call_origin": "autorouter_classifier" + } + @pytest.mark.asyncio @pytest.mark.parametrize( "request_kwargs", @@ -1948,6 +1969,33 @@ class TestLLMClassifier: "REASONING", ] + @pytest.mark.asyncio + @pytest.mark.parametrize("reasoning_effort", [None, "none", "low"], ids=["omitted", "none", "low"]) + async def test_classifier_reasoning_effort_reaches_only_classifier_call( + self, mock_router_instance, llm_classifier_config, reasoning_effort + ): + classifier_llm_config = { + **llm_classifier_config["classifier_llm_config"], + **({"reasoning_effort": reasoning_effort} if reasoning_effort is not None else {}), + } + router = ComplexityRouter( + model_name="test-complexity-router", + litellm_router_instance=mock_router_instance, + complexity_router_config={**llm_classifier_config, "classifier_llm_config": classifier_llm_config}, + ) + mock_router_instance.acompletion = AsyncMock(return_value=_llm_response('{"tier": "COMPLEX"}')) + + await router.aclassify("explain quantum tunneling in depth") + + call_kwargs = mock_router_instance.acompletion.call_args.kwargs + body = call_kwargs["proxy_server_request"]["body"] + if reasoning_effort is None: + assert "reasoning_effort" not in call_kwargs + assert "reasoning_effort" not in body + else: + assert call_kwargs["reasoning_effort"] == reasoning_effort + assert body["reasoning_effort"] == reasoning_effort + @pytest.mark.asyncio async def test_aclassify_propagates_top_level_turn_off_message_logging( self, llm_complexity_router, mock_router_instance @@ -8735,9 +8783,10 @@ class TestClassificationRubrics: [ {"model": "haiku-classifier", "system_prompt": "Grade the data sensitivity of the request."}, {"model": "haiku-classifier", "classification_rubric": "chat"}, + {"model": "haiku-classifier", "reasoning_effort": "low"}, {"model": "haiku-classifier"}, ], - ids=["custom-prompt", "chat-preset", "neither"], + ids=["custom-prompt", "chat-preset", "reasoning-effort", "neither"], ) def test_config_survives_a_dump_and_rebuild(self, classifier_llm_config): """/auto_router/test_routing dumps this config and hands the dict straight back to diff --git a/tests/test_litellm/test_router.py b/tests/test_litellm/test_router.py index c843a66a1c1..3b4c80b6b4f 100644 --- a/tests/test_litellm/test_router.py +++ b/tests/test_litellm/test_router.py @@ -35,6 +35,7 @@ from litellm.router import ( _anthropic_stream_should_drop_pre_content_ping, _is_retriable_anthropic_status, ) +from litellm.types.router import DeploymentTypedDict def test_update_kwargs_does_not_mutate_defaults_and_merges_metadata(): @@ -9783,11 +9784,12 @@ def test_model_group_info_intersects_supported_reasoning_efforts(): assert result.supported_reasoning_efforts == ("minimal", "low", "medium", "high") -def test_model_group_info_reasoning_efforts_ignore_a_deployment_off_the_map(): +def test_model_group_info_reasoning_efforts_are_unknown_when_any_deployment_is_off_the_map(): """The router fills every ModelInfo key, so a deployment absent from the model map arrives with supports_reasoning None rather than with the key missing. Its synthesized entry carries no mode, which is what separates it from a mapped non-reasoning model, and nothing being known about it is - no reason to drop the levels the rest of the group agrees on.""" + no evidence that the unknown deployment accepts levels its mapped sibling supports. The group + therefore reports unknown instead of advertising a value routing might send to either one.""" router = litellm.Router( model_list=[ { @@ -9821,7 +9823,7 @@ def test_model_group_info_reasoning_efforts_ignore_a_deployment_off_the_map(): ) assert result is not None - assert result.supported_reasoning_efforts == ("none", "minimal", "low", "medium", "high", "max") + assert result.supported_reasoning_efforts is None @@ -9958,11 +9960,11 @@ def test_model_group_info_survives_a_junk_typed_operator_effort_value(): assert result.supported_reasoning_efforts == ("none", "minimal", "low", "medium", "high") -def test_model_group_info_reasoning_efforts_ignore_a_mode_the_operator_declared(): +def test_model_group_info_reasoning_efforts_are_unknown_for_an_operator_declared_mode(): """A deployment is registered in the cost map under its own id with whatever model_info the operator wrote, so a mode they set themselves reads back exactly like one the map supplied. Only - a mode the map supplied marks the deployment as known, or an off-map deployment carrying any - mode empties the group it sits in.""" + a mode the map supplied marks the deployment as known. An off-map deployment carrying an + operator mode remains unknown and must keep the whole group's level support unknown.""" from litellm.router_utils.reasoning_effort_capability import resolve_supported_reasoning_efforts mapped_model = "openai/gpt-5.6-sol" @@ -9993,7 +9995,7 @@ def test_model_group_info_reasoning_efforts_ignore_a_mode_the_operator_declared( ) assert result is not None - assert result.supported_reasoning_efforts == expected + assert result.supported_reasoning_efforts is None class TestAddDeploymentApiBaseProviderResolution: @@ -12252,6 +12254,120 @@ class TestTierParamsTheTargetAccepts: assert accepted == {"reasoning_effort": "max"} +class TestRequestReasoningEffortOverride: + def test_drop_effort_from_nested_carrier_preserves_other_nested_values(self): + params: dict[str, object] = {"output_config": {"effort": "high", "format": "json"}} + + litellm.Router._pop_effort_from_nested_carrier(params, "output_config") + + assert params == {"output_config": {"format": "json"}} + + @pytest.mark.parametrize("metadata_key", ["metadata", "litellm_metadata"]) + def test_is_classifier_internal_call_recognizes_both_metadata_carriers(self, metadata_key): + kwargs = {metadata_key: {"internal_call_origin": "autorouter_classifier"}} + + assert litellm.Router._is_classifier_internal_call(kwargs) is True + assert litellm.Router._is_classifier_internal_call({metadata_key: {}}) is False + + def test_removes_every_deployment_native_effort_carrier_without_mutating_shared_config(self): + extra_body: dict[str, object] = { + "reasoning_effort": "high", + "thinking": {"type": "enabled"}, + "output_config": {"effort": "high", "format": "json"}, + "reasoning": {"effort": "high", "summary": "detailed"}, + "provider_option": True, + } + deployment_params: dict[str, object] = { + "model": "bedrock/converse/anthropic.claude-3-7-sonnet", + "thinking": {"type": "enabled", "budget_tokens": 2048}, + "output_config": {"effort": "high", "format": {"type": "json_schema"}}, + "reasoning": {"effort": "high", "summary": "auto"}, + "extra_body": extra_body, + } + + sanitized = litellm.Router._deployment_params_with_request_reasoning_override( + deployment_params, {"reasoning_effort": "low"} + ) + + assert sanitized == { + "model": "bedrock/converse/anthropic.claude-3-7-sonnet", + "output_config": {"format": {"type": "json_schema"}}, + "reasoning": {"summary": "auto"}, + "extra_body": { + "output_config": {"format": "json"}, + "reasoning": {"summary": "detailed"}, + "provider_option": True, + }, + } + assert deployment_params["thinking"] == {"type": "enabled", "budget_tokens": 2048} + assert deployment_params["output_config"] == {"effort": "high", "format": {"type": "json_schema"}} + assert extra_body["reasoning_effort"] == "high" + + @pytest.mark.parametrize("request_kwargs", [{}, {"reasoning_effort": None}]) + def test_omitted_override_preserves_deployment_defaults(self, request_kwargs): + deployment_params = { + "model": "deepseek/deepseek-reasoner", + "thinking": {"type": "enabled"}, + "output_config": {"effort": "high"}, + } + + assert ( + litellm.Router._deployment_params_with_request_reasoning_override(deployment_params, request_kwargs) + == deployment_params + ) + + @pytest.mark.asyncio + async def test_280_concurrent_overrides_never_mutate_or_leak_through_shared_deployment_params(self): + deployment_params = { + "model": "fireworks_ai/accounts/fireworks/models/kimi-k2-thinking", + "thinking": {"type": "enabled"}, + "output_config": {"effort": "high", "format": "json"}, + "extra_body": {"reasoning_effort": "high", "tenant": "shared"}, + } + efforts = ("none", "minimal", "low", "medium", "high", "xhigh", "max") + + results = await asyncio.gather( + *( + asyncio.to_thread( + litellm.Router._deployment_params_with_request_reasoning_override, + deployment_params, + {"reasoning_effort": efforts[index % len(efforts)]}, + ) + for index in range(280) + ) + ) + + assert all("thinking" not in result for result in results) + assert all(result["output_config"] == {"format": "json"} for result in results) + assert all(result["extra_body"] == {"tenant": "shared"} for result in results) + assert deployment_params["thinking"] == {"type": "enabled"} + assert deployment_params["output_config"] == {"effort": "high", "format": "json"} + assert deployment_params["extra_body"] == {"reasoning_effort": "high", "tenant": "shared"} + + @pytest.mark.parametrize( + ("metadata", "should_drop"), + [({"internal_call_origin": "autorouter_classifier"}, True), ({}, False)], + ids=["classifier", "ordinary-request"], + ) + def test_only_classifier_calls_drop_effort_for_an_unsupported_fallback(self, metadata, should_drop): + router = litellm.Router(model_list=[]) + body: dict[str, object] = {"model": "classifier", "reasoning_effort": "low"} + kwargs: dict[str, object] = { + "reasoning_effort": "low", + "metadata": metadata, + "proxy_server_request": {"body": body}, + } + deployment: DeploymentTypedDict = { + "model_name": "fallback", + "litellm_params": {"model": "openai/gpt-4o-mini"}, + } + + router._drop_unsupported_classifier_reasoning_effort(deployment, "fallback", kwargs) + + assert ("reasoning_effort" not in kwargs) is should_drop + assert ("reasoning_effort" not in body) is should_drop + + class TestPreRoutingTierDrivesFallbacks: """#38832: a complexity/auto router picks a tier behind the router name, but fallback lookup stayed on the router name, so the tier's configured chain never ran and a diff --git a/ui/litellm-dashboard/src/components/add_model/ClassificationMethodConfig.tsx b/ui/litellm-dashboard/src/components/add_model/ClassificationMethodConfig.tsx index a29527a20fa..00ee7bd7d6e 100644 --- a/ui/litellm-dashboard/src/components/add_model/ClassificationMethodConfig.tsx +++ b/ui/litellm-dashboard/src/components/add_model/ClassificationMethodConfig.tsx @@ -13,6 +13,8 @@ import ClassifierPromptEditor from "./ClassifierPromptEditor"; import CustomTierPromptEditor from "./CustomTierPromptEditor"; import { RestrictedSection, restrictedBy } from "./TierRestrictions"; import HeuristicScoringConfig from "./HeuristicScoringConfig"; +import ClassifierReasoningEffortSelect from "./ClassifierReasoningEffortSelect"; +import type { ReasoningEffort } from "./complexity_router_tiers"; import { useComplexityScorerDefaults } from "@/app/(dashboard)/hooks/autoRouter/useComplexityScorerDefaults"; import { ClassificationFrequency, @@ -154,6 +156,7 @@ interface ClassificationMethodConfigProps { value: ComplexityRouterConfigValue; onChange: (value: ComplexityRouterConfigValue) => void; modelOptions: { value: string; label: string }[]; + effortOptionsByModel: Record; customTechnicalKeywords?: string[]; onCustomTechnicalKeywordsChange?: (keywords: string[]) => void; showValidationErrors?: boolean; @@ -236,6 +239,7 @@ const ClassificationMethodConfig: React.FC = ({ value, onChange, modelOptions, + effortOptionsByModel, customTechnicalKeywords, onCustomTechnicalKeywordsChange, showValidationErrors = false, @@ -251,6 +255,9 @@ const ClassificationMethodConfig: React.FC = ({ const contextBudget = value.classifier_context_budget_chars ?? DEFAULT_CLASSIFIER_CONTEXT_BUDGET_CHARS; const contextBudgetQuotesNothing = contextBudget > 0 && contextBudget < MIN_QUOTED_CONTEXT_TURN_CHARS; const classificationRubric = value.classifier_llm_config?.classification_rubric ?? DEFAULT_CLASSIFICATION_RUBRIC; + const classifierModel = value.classifier_llm_config?.model ?? ""; + const classifierReasoningEffort = value.classifier_llm_config?.reasoning_effort; + const explicitlySupportedClassifierEfforts = effortOptionsByModel[classifierModel]; const handleClassifierTypeChange = (classifierType: ClassifierType) => { const nextValue: ComplexityRouterConfigValue = { @@ -299,16 +306,33 @@ const ClassificationMethodConfig: React.FC = ({ }; const handleClassifierModelChange = (model: string) => { + if (model === value.classifier_llm_config?.model) return; + const { reasoning_effort: _reasoningEffort, ...classifierLlmConfig } = value.classifier_llm_config ?? { + model: "", + timeout_ms: DEFAULT_CLASSIFIER_TIMEOUT_MS, + }; onChange({ ...value, classifier_llm_config: { - ...value.classifier_llm_config, + ...classifierLlmConfig, model, - timeout_ms: value.classifier_llm_config?.timeout_ms ?? DEFAULT_CLASSIFIER_TIMEOUT_MS, + timeout_ms: classifierLlmConfig.timeout_ms, }, }); }; + const handleClassifierReasoningEffortChange = (reasoningEffort: ReasoningEffort | undefined) => { + if (!value.classifier_llm_config) return; + const { reasoning_effort: _reasoningEffort, ...classifierLlmConfig } = value.classifier_llm_config; + onChange({ + ...value, + classifier_llm_config: + reasoningEffort === undefined + ? classifierLlmConfig + : { ...classifierLlmConfig, reasoning_effort: reasoningEffort }, + }); + }; + const handleClassifierTimeoutChange = (timeoutMs: number) => { onChange({ ...value, @@ -493,9 +517,16 @@ const ClassificationMethodConfig: React.FC = ({ emptyText="No models found" allowClear={false} className={classifierModelMissing ? "border-destructive" : undefined} + aria-label="Classifier Model" /> {classifierModelMissing && A classifier model is required} +