Skip to content

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]

feat(ui): expose classifier context window fields on Auto-Router screens (LIT-5036) (#35315)

tin-berri3c2264cfacc3
diff --git a/ui/litellm-dashboard/src/components/add_model/ClassificationMethodConfig.tsx b/ui/litellm-dashboard/src/components/add_model/ClassificationMethodConfig.tsx
index 92df8029edc..75acf87a7d8 100644
--- a/ui/litellm-dashboard/src/components/add_model/ClassificationMethodConfig.tsx
+++ b/ui/litellm-dashboard/src/components/add_model/ClassificationMethodConfig.tsx
@@ -1,7 +1,13 @@
import { InfoCircleOutlined } from "@ant-design/icons";
import { Select as AntdSelect, Card, InputNumber, Radio, Space, Tooltip, Typography } from "antd";
import React from "react";
-import { ClassifierType, ComplexityRouterConfigValue, DEFAULT_CLASSIFIER_TIMEOUT_MS } from "./ComplexityRouterConfig";
+import {
+ ClassifierType,
+ ComplexityRouterConfigValue,
+ DEFAULT_CLASSIFIER_CONTEXT_PER_TURN_CHARS,
+ DEFAULT_CLASSIFIER_CONTEXT_WINDOW_SIZE,
+ DEFAULT_CLASSIFIER_TIMEOUT_MS,
+} from "./ComplexityRouterConfig";
const { Text } = Typography;
@@ -26,14 +32,23 @@ const ClassificationMethodConfig: React.FC<ClassificationMethodConfigProps> = ({
showValidationErrors && value.classifier_type === "llm" && !value.classifier_llm_config?.model;
const handleClassifierTypeChange = (classifierType: ClassifierType) => {
- onChange({
+ const nextValue: ComplexityRouterConfigValue = {
...value,
classifier_type: classifierType,
classifier_llm_config:
classifierType === "llm"
? value.classifier_llm_config ?? { model: "", timeout_ms: DEFAULT_CLASSIFIER_TIMEOUT_MS }
: undefined,
- });
+ classifier_context_window_size:
+ classifierType === "llm"
+ ? value.classifier_context_window_size ?? DEFAULT_CLASSIFIER_CONTEXT_WINDOW_SIZE
+ : undefined,
+ classifier_context_per_turn_chars:
+ classifierType === "llm"
+ ? value.classifier_context_per_turn_chars ?? DEFAULT_CLASSIFIER_CONTEXT_PER_TURN_CHARS
+ : undefined,
+ };
+ onChange(nextValue);
};
const handleClassifierModelChange = (model: string) => {
@@ -56,6 +71,20 @@ const ClassificationMethodConfig: React.FC<ClassificationMethodConfigProps> = ({
});
};
+ const handleClassifierContextWindowSizeChange = (windowSize: number | null) => {
+ onChange({
+ ...value,
+ classifier_context_window_size: windowSize ?? DEFAULT_CLASSIFIER_CONTEXT_WINDOW_SIZE,
+ });
+ };
+
+ const handleClassifierContextPerTurnCharsChange = (perTurnChars: number | null) => {
+ onChange({
+ ...value,
+ classifier_context_per_turn_chars: perTurnChars ?? DEFAULT_CLASSIFIER_CONTEXT_PER_TURN_CHARS,
+ });
+ };
+
return (
<>
<Radio.Group
@@ -111,6 +140,36 @@ const ClassificationMethodConfig: React.FC<ClassificationMethodConfigProps> = ({
response.
</Text>
</div>
+ <div>
+ <Text strong style={{ display: "block", marginBottom: 4 }}>
+ Context Window Size
+ </Text>
+ <InputNumber
+ value={value.classifier_context_window_size ?? DEFAULT_CLASSIFIER_CONTEXT_WINDOW_SIZE}
+ onChange={handleClassifierContextWindowSizeChange}
+ min={0}
+ style={{ width: "100%" }}
+ />
+ <Text type="secondary" style={{ fontSize: 12 }}>
+ Number of prior user turns (tool output and harness reminders excluded) sent to the classifier as context,
+ so a referring follow-up like &quot;now do the same for the streaming path&quot; is classified against
+ what it refers to. Set to 0 to send only the current message.
+ </Text>
+ </div>
+ <div>
+ <Text strong style={{ display: "block", marginBottom: 4 }}>
+ Context Per-Turn Character Limit
+ </Text>
+ <InputNumber
+ value={value.classifier_context_per_turn_chars ?? DEFAULT_CLASSIFIER_CONTEXT_PER_TURN_CHARS}
+ onChange={handleClassifierContextPerTurnCharsChange}
+ min={1}
+ style={{ width: "100%" }}
+ />
+ <Text type="secondary" style={{ fontSize: 12 }}>
+ Prior turns longer than this are truncated.
+ </Text>
+ </div>
</div>
)}
diff --git a/ui/litellm-dashboard/src/components/add_model/ComplexityRouterConfig.test.tsx b/ui/litellm-dashboard/src/components/add_model/ComplexityRouterConfig.test.tsx
index 6b3c1961468..a1e992bd46b 100644
--- a/ui/litellm-dashboard/src/components/add_model/ComplexityRouterConfig.test.tsx
+++ b/ui/litellm-dashboard/src/components/add_model/ComplexityRouterConfig.test.tsx
@@ -99,11 +99,14 @@ describe("ComplexityRouterConfig", () => {
fireEvent.click(screen.getByText("Advanced: Classification Method"));
fireEvent.click(screen.getByText("LLM Classifier"));
- expect(onChange).toHaveBeenCalledWith({
+ const expectedValue: ComplexityRouterConfigValue = {
...defaultValue,
classifier_type: "llm",
classifier_llm_config: { model: "", timeout_ms: 3000 },
- });
+ classifier_context_window_size: 3,
+ classifier_context_per_turn_chars: 200,
+ };
+ expect(onChange).toHaveBeenCalledWith(expectedValue);
});
it("should show classifier fields and use the configured values when classifier_type is llm", () => {
@@ -111,6 +114,8 @@ describe("ComplexityRouterConfig", () => {
...defaultValue,
classifier_type: "llm",
classifier_llm_config: { model: "gpt-3.5-turbo", timeout_ms: 750 },
+ classifier_context_window_size: 5,
+ classifier_context_per_turn_chars: 400,
};
renderWithProviders(<ComplexityRouterConfig modelInfo={mockModelInfo} value={llmValue} onChange={vi.fn()} />);
@@ -119,6 +124,74 @@ describe("ComplexityRouterConfig", () => {
expect(screen.getByText("Classifier Model")).toBeInTheDocument();
expect(screen.getByText("Timeout (ms)")).toBeInTheDocument();
expect(screen.getByDisplayValue("750")).toBeInTheDocument();
+ expect(screen.getByText("Context Window Size")).toBeInTheDocument();
+ expect(screen.getByDisplayValue("5")).toBeInTheDocument();
+ expect(screen.getByText("Context Per-Turn Character Limit")).toBeInTheDocument();
+ expect(screen.getByDisplayValue("400")).toBeInTheDocument();
+ });
+
+ it("should default classifier context fields to 3 and 200 when llm is selected without explicit values", () => {
+ const llmValue: ComplexityRouterConfigValue = {
+ ...defaultValue,
+ classifier_type: "llm",
+ classifier_llm_config: { model: "gpt-3.5-turbo", timeout_ms: 3000 },
+ };
+ renderWithProviders(<ComplexityRouterConfig modelInfo={mockModelInfo} value={llmValue} onChange={vi.fn()} />);
+
+ fireEvent.click(screen.getByText("Advanced: Classification Method"));
+
+ const windowSizeSection = screen.getByText("Context Window Size").closest("div") as HTMLElement;
+ expect(within(windowSizeSection).getByDisplayValue("3")).toBeInTheDocument();
+
+ const perTurnCharsSection = screen.getByText("Context Per-Turn Character Limit").closest("div") as HTMLElement;
+ expect(within(perTurnCharsSection).getByDisplayValue("200")).toBeInTheDocument();
+ });
+
+ it("should hide classifier context fields when classifier_type is heuristic", () => {
+ renderWithProviders(<ComplexityRouterConfig modelInfo={mockModelInfo} value={defaultValue} onChange={vi.fn()} />);
+ fireEvent.click(screen.getByText("Advanced: Classification Method"));
+ expect(screen.queryByText("Context Window Size")).not.toBeInTheDocument();
+ expect(screen.queryByText("Context Per-Turn Character Limit")).not.toBeInTheDocument();
+ });
+
+ it("should call onChange with the updated classifier_context_window_size when edited", () => {
+ const onChange = vi.fn();
+ const llmValue: ComplexityRouterConfigValue = {
+ ...defaultValue,
+ classifier_type: "llm",
+ classifier_llm_config: { model: "gpt-3.5-turbo", timeout_ms: 3000 },
+ };
+ renderWithProviders(<ComplexityRouterConfig modelInfo={mockModelInfo} value={llmValue} onChange={onChange} />);
+ fireEvent.click(screen.getByText("Advanced: Classification Method"));
+
+ const windowSizeSection = screen.getByText("Context Window Size").closest("div") as HTMLElement;
+ const input = within(windowSizeSection).getByRole("spinbutton");
+ fireEvent.change(input, { target: { value: "7" } });
+
+ expect(onChange).toHaveBeenCalledWith({
+ ...llmValue,
+ classifier_context_window_size: 7,
+ });
+ });
+
+ it("should call onChange with the updated classifier_context_per_turn_chars when edited", () => {
+ const onChange = vi.fn();
+ const llmValue: ComplexityRouterConfigValue = {
+ ...defaultValue,
+ classifier_type: "llm",
+ classifier_llm_config: { model: "gpt-3.5-turbo", timeout_ms: 3000 },
+ };
+ renderWithProviders(<ComplexityRouterConfig modelInfo={mockModelInfo} value={llmValue} onChange={onChange} />);
+ fireEvent.click(screen.getByText("Advanced: Classification Method"));
+
+ const perTurnCharsSection = screen.getByText("Context Per-Turn Character Limit").closest("div") as HTMLElement;
+ const input = within(perTurnCharsSection).getByRole("spinbutton");
+ fireEvent.change(input, { target: { value: "500" } });
+
+ expect(onChange).toHaveBeenCalledWith({
+ ...llmValue,
+ classifier_context_per_turn_chars: 500,
+ });
});
it("should render the custom technical keywords field", () => {
diff --git a/ui/litellm-dashboard/src/components/add_model/ComplexityRouterConfig.tsx b/ui/litellm-dashboard/src/components/add_model/ComplexityRouterConfig.tsx
index 1f2edf697a9..de32d15d5a7 100644
--- a/ui/litellm-dashboard/src/components/add_model/ComplexityRouterConfig.tsx
+++ b/ui/litellm-dashboard/src/components/add_model/ComplexityRouterConfig.tsx
@@ -12,6 +12,8 @@ const { Text } = Typography;
export const DEFAULT_CLASSIFIER_TIMEOUT_MS = 3000;
export const DEFAULT_TIER_DISTANCE_PENALTY = 0.5;
+export const DEFAULT_CLASSIFIER_CONTEXT_WINDOW_SIZE = 3;
+export const DEFAULT_CLASSIFIER_CONTEXT_PER_TURN_CHARS = 200;
export interface ComplexityTiers {
SIMPLE: string[];
@@ -40,6 +42,8 @@ export interface ComplexityRouterConfigValue {
tiers: ComplexityTiers;
classifier_type: ClassifierType;
classifier_llm_config?: ClassifierLLMConfig;
+ classifier_context_window_size?: number;
+ classifier_context_per_turn_chars?: number;
adaptive?: boolean;
adaptive_weights?: AdaptiveRouterWeights;
tier_distance_penalty?: number;
diff --git a/ui/litellm-dashboard/src/components/add_model/add_auto_router_tab.tsx b/ui/litellm-dashboard/src/components/add_model/add_auto_router_tab.tsx
index cd3294b347f..fb7eabd7110 100644
--- a/ui/litellm-dashboard/src/components/add_model/add_auto_router_tab.tsx
+++ b/ui/litellm-dashboard/src/components/add_model/add_auto_router_tab.tsx
@@ -99,6 +99,8 @@ const AddAutoRouterTab: React.FC<AddAutoRouterTabProps> = ({
tiers,
classifier_type: classifierType,
classifier_llm_config: classifierLlmConfig,
+ classifier_context_window_size: classifierContextWindowSize,
+ classifier_context_per_turn_chars: classifierContextPerTurnChars,
adaptive = false,
adaptive_weights: adaptiveWeights = DEFAULT_ADAPTIVE_WEIGHTS,
tier_distance_penalty: tierDistancePenalty = DEFAULT_TIER_DISTANCE_PENALTY,
@@ -142,6 +144,8 @@ const AddAutoRouterTab: React.FC<AddAutoRouterTabProps> = ({
tiers,
classifierType,
classifierLlmConfig,
+ classifierContextWindowSize,
+ classifierContextPerTurnChars,
customTechnicalKeywords,
keywordTierRules,
semanticMatchingEnabled,
diff --git a/ui/litellm-dashboard/src/components/add_model/build_complexity_router_config.test.ts b/ui/litellm-dashboard/src/components/add_model/build_complexity_router_config.test.ts
index b5973bf7101..e269a3c9028 100644
--- a/ui/litellm-dashboard/src/components/add_model/build_complexity_router_config.test.ts
+++ b/ui/litellm-dashboard/src/components/add_model/build_complexity_router_config.test.ts
@@ -16,6 +16,8 @@ const baseParams: BuildComplexityRouterConfigParams = {
tiers,
classifierType: "heuristic",
classifierLlmConfig: undefined,
+ classifierContextWindowSize: undefined,
+ classifierContextPerTurnChars: undefined,
customTechnicalKeywords: [],
keywordTierRules: [],
semanticMatchingEnabled: false,
@@ -75,6 +77,52 @@ describe("buildComplexityRouterConfig", () => {
expect(config.classifier_llm_config).toBeUndefined();
});
+ it("includes classifier_context_window_size and classifier_context_per_turn_chars only when classifier_type is llm", () => {
+ const params: BuildComplexityRouterConfigParams = {
+ ...baseParams,
+ classifierType: "llm",
+ classifierLlmConfig: { model: "gpt-4o-mini", timeout_ms: 3000 },
+ classifierContextWindowSize: 5,
+ classifierContextPerTurnChars: 300,
+ };
+ const config = buildComplexityRouterConfig(params);
+ expect(config.classifier_context_window_size).toBe(5);
+ expect(config.classifier_context_per_turn_chars).toBe(300);
+ });
+
+ it("omits classifier_context_window_size and classifier_context_per_turn_chars when classifier_type is heuristic even if values linger in state", () => {
+ const params: BuildComplexityRouterConfigParams = {
+ ...baseParams,
+ classifierType: "heuristic",
+ classifierContextWindowSize: 5,
+ classifierContextPerTurnChars: 300,
+ };
+ const config = buildComplexityRouterConfig(params);
+ expect(config.classifier_context_window_size).toBeUndefined();
+ expect(config.classifier_context_per_turn_chars).toBeUndefined();
+ });
+
+ it("omits classifier_context_window_size and classifier_context_per_turn_chars when classifier_type is llm but neither was set, leaving the backend default", () => {
+ const config = buildComplexityRouterConfig({
+ ...baseParams,
+ classifierType: "llm",
+ classifierLlmConfig: { model: "gpt-4o-mini", timeout_ms: 3000 },
+ });
+ expect(config.classifier_context_window_size).toBeUndefined();
+ expect(config.classifier_context_per_turn_chars).toBeUndefined();
+ });
+
+ it("allows classifier_context_window_size of 0, distinct from unset, to send no prior-turn context", () => {
+ const params: BuildComplexityRouterConfigParams = {
+ ...baseParams,
+ classifierType: "llm",
+ classifierLlmConfig: { model: "gpt-4o-mini", timeout_ms: 3000 },
+ classifierContextWindowSize: 0,
+ };
+ const config = buildComplexityRouterConfig(params);
+ expect(config.classifier_context_window_size).toBe(0);
+ });
+
it("sends keyword_tier_rules with their per-tier targeting preserved (not flattened)", () => {
const params: BuildComplexityRouterConfigParams = {
...baseParams,
diff --git a/ui/litellm-dashboard/src/components/add_model/build_complexity_router_config.ts b/ui/litellm-dashboard/src/components/add_model/build_complexity_router_config.ts
index 02be9b280aa..04a9b0f9bd4 100644
--- a/ui/litellm-dashboard/src/components/add_model/build_complexity_router_config.ts
+++ b/ui/litellm-dashboard/src/components/add_model/build_complexity_router_config.ts
@@ -12,6 +12,8 @@ export interface BuildComplexityRouterConfigParams {
tiers: ComplexityTiers;
classifierType: ClassifierType;
classifierLlmConfig: ClassifierLLMConfig | undefined;
+ classifierContextWindowSize: number | undefined;
+ classifierContextPerTurnChars: number | undefined;
customTechnicalKeywords: string[];
keywordTierRules: KeywordTierRule[];
semanticMatchingEnabled: boolean;
@@ -29,6 +31,8 @@ export interface ComplexityRouterConfigPayload {
tiers: ComplexityTiers;
classifier_type: ClassifierType;
classifier_llm_config?: ClassifierLLMConfig;
+ classifier_context_window_size?: number;
+ classifier_context_per_turn_chars?: number;
custom_technical_keywords?: string[];
keyword_tier_rules?: { keywords: string[]; tier: KeywordTierRule["tier"] }[];
semantic_keyword_matching?: boolean;
@@ -69,6 +73,8 @@ export const buildComplexityRouterConfig = ({
tiers,
classifierType,
classifierLlmConfig,
+ classifierContextWindowSize,
+ classifierContextPerTurnChars,
customTechnicalKeywords,
keywordTierRules,
semanticMatchingEnabled,
@@ -89,6 +95,14 @@ export const buildComplexityRouterConfig = ({
tiers,
classifier_type: classifierType,
...(classifierType === "llm" && classifierLlmConfig && { classifier_llm_config: classifierLlmConfig }),
+ ...(classifierType === "llm" &&
+ classifierContextWindowSize !== undefined && {
+ classifier_context_window_size: classifierContextWindowSize,
+ }),
+ ...(classifierType === "llm" &&
+ classifierContextPerTurnChars !== undefined && {
+ classifier_context_per_turn_chars: classifierContextPerTurnChars,
+ }),
...(customTechnicalKeywords.length > 0 && { custom_technical_keywords: customTechnicalKeywords }),
...(cleanedKeywordTierRules.length > 0 && { keyword_tier_rules: cleanedKeywordTierRules }),
escalation_keywords: cleanedEscalationKeywords,
diff --git a/ui/litellm-dashboard/src/components/edit_auto_router/build_updated_complexity_router_config.test.ts b/ui/litellm-dashboard/src/components/edit_auto_router/build_updated_complexity_router_config.test.ts
index e39a7b6e444..eef5e1e4d06 100644
--- a/ui/litellm-dashboard/src/components/edit_auto_router/build_updated_complexity_router_config.test.ts
+++ b/ui/litellm-dashboard/src/components/edit_auto_router/build_updated_complexity_router_config.test.ts
@@ -86,3 +86,68 @@ describe("buildUpdatedComplexityRouterConfig keyword matching", () => {
expect(result.match_threshold).toBe(0.72);
});
});
+
+const STORED_LLM = {
+ tiers: { SIMPLE: ["gpt-4o-mini"], MEDIUM: [], COMPLEX: [], REASONING: [] },
+ classifier_type: "llm",
+ classifier_llm_config: { model: "gpt-4o-mini", timeout_ms: 3000 },
+ classifier_context_window_size: 5,
+ classifier_context_per_turn_chars: 300,
+};
+
+describe("buildUpdatedComplexityRouterConfig classifier context window", () => {
+ it("round-trips an untouched edit without changing the classifier context values", () => {
+ const formValue = {
+ tiers: STORED_LLM.tiers,
+ classifier_type: "llm" as const,
+ classifier_llm_config: STORED_LLM.classifier_llm_config,
+ classifier_context_window_size: 5,
+ classifier_context_per_turn_chars: 300,
+ };
+ const result = buildUpdatedComplexityRouterConfig(STORED_LLM, formValue);
+
+ expect(result.classifier_context_window_size).toBe(5);
+ expect(result.classifier_context_per_turn_chars).toBe(300);
+ });
+
+ it("persists an edited classifier context window size and per-turn char limit", () => {
+ const formValue = {
+ tiers: STORED_LLM.tiers,
+ classifier_type: "llm" as const,
+ classifier_llm_config: STORED_LLM.classifier_llm_config,
+ classifier_context_window_size: 10,
+ classifier_context_per_turn_chars: 500,
+ };
+ const result = buildUpdatedComplexityRouterConfig(STORED_LLM, formValue);
+
+ expect(result.classifier_context_window_size).toBe(10);
+ expect(result.classifier_context_per_turn_chars).toBe(500);
+ });
+
+ it("omits classifier context fields when classifier_type is heuristic even if values linger in state", () => {
+ const formValue = {
+ tiers: STORED_LLM.tiers,
+ classifier_type: "heuristic" as const,
+ classifier_context_window_size: 5,
+ classifier_context_per_turn_chars: 300,
+ };
+ const result = buildUpdatedComplexityRouterConfig(STORED_LLM, formValue);
+
+ expect(result.classifier_context_window_size).toBeUndefined();
+ expect(result.classifier_context_per_turn_chars).toBeUndefined();
+ });
+
+ it("does not resurrect a stale stored classifier_context_window_size once the form's own value is unset", () => {
+ // classifier_context_window_size is a MANAGED key: the form's value must win over whatever
+ // is still sitting in the stored config, never fall back to it through preservedConfig.
+ const formValue = {
+ tiers: STORED_LLM.tiers,
+ classifier_type: "llm" as const,
+ classifier_llm_config: STORED_LLM.classifier_llm_config,
+ };
+ const result = buildUpdatedComplexityRouterConfig(STORED_LLM, formValue);
+
+ expect(result.classifier_context_window_size).toBeUndefined();
+ expect(result.classifier_context_per_turn_chars).toBeUndefined();
+ });
+});
diff --git a/ui/litellm-dashboard/src/components/edit_auto_router/edit_auto_router_modal.test.tsx b/ui/litellm-dashboard/src/components/edit_auto_router/edit_auto_router_modal.test.tsx
index e47bbecf8bd..504234e8977 100644
--- a/ui/litellm-dashboard/src/components/edit_auto_router/edit_auto_router_modal.test.tsx
+++ b/ui/litellm-dashboard/src/components/edit_auto_router/edit_auto_router_modal.test.tsx
@@ -1,7 +1,7 @@
import userEvent from "@testing-library/user-event";
import { describe, expect, it, vi } from "vitest";
-import { renderWithProviders, screen, waitFor } from "@/../tests/test-utils";
+import { fireEvent, renderWithProviders, screen, waitFor, within } from "@/../tests/test-utils";
import NotificationsManager from "@/components/molecules/notifications_manager";
import EditAutoRouterModal from "./edit_auto_router_modal";
@@ -119,3 +119,68 @@ describe("EditAutoRouterModal keyword matching", () => {
expect(modelPatchUpdateCall).not.toHaveBeenCalled();
});
});
+
+describe("EditAutoRouterModal classifier context window", () => {
+ beforeEach(() => {
+ modelPatchUpdateCall.mockClear();
+ });
+
+ const STORED_LLM_CONFIG = {
+ tiers: { SIMPLE: ["gpt-4o-mini"], MEDIUM: ["gpt-4o-mini"], COMPLEX: ["gpt-4o-mini"], REASONING: ["gpt-4o-mini"] },
+ classifier_type: "llm",
+ classifier_llm_config: { model: "gpt-4o-mini", timeout_ms: 3000 },
+ classifier_context_window_size: 5,
+ classifier_context_per_turn_chars: 300,
+ };
+
+ const renderLlmModal = () =>
+ renderWithProviders(
+ <EditAutoRouterModal
+ isVisible
+ onCancel={vi.fn()}
+ onSuccess={vi.fn()}
+ modelData={{
+ ...MODEL_DATA,
+ litellm_params: { ...MODEL_DATA.litellm_params, complexity_router_config: STORED_LLM_CONFIG },
+ }}
+ accessToken="token"
+ userRole="Admin"
+ />,
+ );
+
+ // Hydration bugs are invisible to the payload-builder unit tests, which only exercise
+ // buildUpdatedComplexityRouterConfig with a form value the caller already assembled by hand.
+ // Only driving the real component through open, then save with nothing touched, catches a
+ // missing initializeForm hydration line.
+ it("shows the stored classifier context values and preserves them through an untouched open-and-save", async () => {
+ const user = userEvent.setup();
+ renderLlmModal();
+
+ await user.click(await screen.findByText("Advanced: Classification Method"));
+ await screen.findByText("Context Window Size");
+ expect(screen.getByDisplayValue("5")).toBeInTheDocument();
+ expect(screen.getByDisplayValue("300")).toBeInTheDocument();
+
+ await user.click(screen.getByRole("button", { name: /save changes/i }));
+
+ await waitFor(() => expect(modelPatchUpdateCall).toHaveBeenCalled());
+ const config = savedConfig();
+ expect(config.classifier_context_window_size).toBe(5);
+ expect(config.classifier_context_per_turn_chars).toBe(300);
+ });
+
+ it("persists an edited classifier context window size", async () => {
+ const user = userEvent.setup();
+ renderLlmModal();
+
+ await user.click(await screen.findByText("Advanced: Classification Method"));
+ const windowSizeSection = (await screen.findByText("Context Window Size")).closest("div") as HTMLElement;
+ const input = within(windowSizeSection).getByRole("spinbutton");
+ fireEvent.change(input, { target: { value: "8" } });
+
+ await user.click(screen.getByRole("button", { name: /save changes/i }));
+
+ await waitFor(() => expect(modelPatchUpdateCall).toHaveBeenCalled());
+ expect(savedConfig().classifier_context_window_size).toBe(8);
+ });
+});
diff --git a/ui/litellm-dashboard/src/components/edit_auto_router/edit_auto_router_modal.tsx b/ui/litellm-dashboard/src/components/edit_auto_router/edit_auto_router_modal.tsx
index 8fbca822165..2686f99307e 100644
--- a/ui/litellm-dashboard/src/components/edit_auto_router/edit_auto_router_modal.tsx
+++ b/ui/litellm-dashboard/src/components/edit_auto_router/edit_auto_router_modal.tsx
@@ -33,6 +33,8 @@ const MANAGED_COMPLEXITY_ROUTER_KEYS = new Set([
"tiers",
"classifier_type",
"classifier_llm_config",
+ "classifier_context_window_size",
+ "classifier_context_per_turn_chars",
"adaptive",
"adaptive_weights",
"tier_distance_penalty",
@@ -86,6 +88,14 @@ export const buildUpdatedComplexityRouterConfig = (
tiers: value.tiers,
classifier_type: value.classifier_type,
...(value.classifier_type === "llm" ? { classifier_llm_config: value.classifier_llm_config } : {}),
+ ...(value.classifier_type === "llm" &&
+ value.classifier_context_window_size !== undefined && {
+ classifier_context_window_size: value.classifier_context_window_size,
+ }),
+ ...(value.classifier_type === "llm" &&
+ value.classifier_context_per_turn_chars !== undefined && {
+ classifier_context_per_turn_chars: value.classifier_context_per_turn_chars,
+ }),
...(customTechnicalKeywords &&
customTechnicalKeywords.length > 0 && {
custom_technical_keywords: customTechnicalKeywords,
@@ -182,7 +192,7 @@ const EditAutoRouterModal: React.FC<EditAutoRouterModalProps> = ({
parsedConfig = JSON.parse(parsedConfig);
}
- setComplexityRouterConfig({
+ const hydratedComplexityRouterConfig: ComplexityRouterConfigValue = {
tiers: {
SIMPLE: normalizeTierModels(parsedConfig.tiers?.SIMPLE),
MEDIUM: normalizeTierModels(parsedConfig.tiers?.MEDIUM),
@@ -191,12 +201,21 @@ const EditAutoRouterModal: React.FC<EditAutoRouterModalProps> = ({
},
classifier_type: parsedConfig.classifier_type || "heuristic",
classifier_llm_config: parsedConfig.classifier_llm_config,
+ classifier_context_window_size:
+ typeof parsedConfig.classifier_context_window_size === "number"
+ ? parsedConfig.classifier_context_window_size
+ : undefined,
+ classifier_context_per_turn_chars:
+ typeof parsedConfig.classifier_context_per_turn_chars === "number"
+ ? parsedConfig.classifier_context_per_turn_chars
+ : undefined,
adaptive: parsedConfig.adaptive || false,
adaptive_weights: parsedConfig.adaptive_weights,
tier_distance_penalty: parsedConfig.tier_distance_penalty,
adaptive_eligible: parsedConfig.adaptive_eligible || "all",
return_raw_model_name: parsedConfig.return_raw_model_name || false,
- });
+ };
+ setComplexityRouterConfig(hydratedComplexityRouterConfig);
setCustomTechnicalKeywords(
Array.isArray(parsedConfig.custom_technical_keywords) ? parsedConfig.custom_technical_keywords : [],
);