mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-09 22:31:41 +00:00
refactor(ui): extract hydrateBuiltInTiers so the edit modal stays under max-lines
Upstream's edit_auto_router_modal.tsx sits at 799 countable lines, one under the 800 cap, so this PR's 11 added lines put the merge result over. The built-in tier hydration moves next to its sibling hydrators in build_complexity_router_config, which is where hydrateCustomTierSet and hydrateTierLabels already live.
This commit is contained in:
parent
17e3dc1c79
commit
a4f865b1be
2 changed files with 25 additions and 15 deletions
|
|
@ -385,6 +385,26 @@ export const customTierWireFields = (
|
|||
};
|
||||
};
|
||||
|
||||
/** The built-in tier pools and the opt-in flag, read back from a stored config. `tiers` is
|
||||
* rewritten wholesale on save, so a stored tier this misses is deleted by any unrelated edit. */
|
||||
export const hydrateBuiltInTiers = (
|
||||
storedTiers: Partial<Record<keyof ComplexityTiers, unknown>> | undefined,
|
||||
storedFlag: boolean | undefined,
|
||||
): { tiers: ComplexityTiers; enable_non_reasoning_tier: boolean } => {
|
||||
const nonReasoning: string[] = normalizeTierModels(storedTiers?.NON_REASONING);
|
||||
const enable_non_reasoning_tier: boolean = storedFlag === true || nonReasoning.length > 0;
|
||||
return {
|
||||
enable_non_reasoning_tier,
|
||||
tiers: {
|
||||
SIMPLE: normalizeTierModels(storedTiers?.SIMPLE),
|
||||
MEDIUM: normalizeTierModels(storedTiers?.MEDIUM),
|
||||
COMPLEX: normalizeTierModels(storedTiers?.COMPLEX),
|
||||
REASONING: normalizeTierModels(storedTiers?.REASONING),
|
||||
...(enable_non_reasoning_tier && { NON_REASONING: nonReasoning }),
|
||||
},
|
||||
};
|
||||
};
|
||||
|
||||
// plan_mode_min_tier rides the strip list because the base payload carries it as a row id;
|
||||
// customTierWireFields re-emits it as the row's name, and an unresolvable floor stays off.
|
||||
const CUSTOM_TIER_STRIPPED_KEYS: readonly string[] = [...CUSTOM_TIER_OMITTED_KEYS, "plan_mode_min_tier"];
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ import ModelChoiceCombobox, { type ModelChoice } from "../add_model/ModelChoiceC
|
|||
import { modelAvailableCall, modelPatchUpdateCall, validateAutoRouterConfig } from "../networking";
|
||||
import { fetchAvailableModels, ModelGroup } from "@/components/llm_calls/fetch_models";
|
||||
import RouterConfigBuilder from "../add_model/RouterConfigBuilder";
|
||||
import { hydrateTierModelParams, normalizeTierModels } from "../add_model/complexity_router_tiers";
|
||||
import { hydrateTierModelParams } from "../add_model/complexity_router_tiers";
|
||||
import {
|
||||
type ActiveTierSet,
|
||||
CUSTOM_TIER_OMITTED_KEYS,
|
||||
|
|
@ -34,6 +34,7 @@ import {
|
|||
getSemanticConfigError,
|
||||
getPlanModeTierError,
|
||||
getTierLabelsError,
|
||||
hydrateBuiltInTiers,
|
||||
hydrateCustomTierSet,
|
||||
hydratePlanModeMinTier,
|
||||
hydrateTierLabels,
|
||||
|
|
@ -139,21 +140,10 @@ export const hydrateComplexityRouterConfig = (
|
|||
parsedConfig: StoredComplexityRouterConfig,
|
||||
complexityRouterDefaultModel: string | null | undefined,
|
||||
): ComplexityRouterConfigValue => {
|
||||
// `tiers` is rewritten wholesale on save, so a stored tier this misses is deleted by any edit,
|
||||
// including one made for an unrelated reason. Hence reading both back rather than assuming four.
|
||||
const storedNonReasoning: string[] = normalizeTierModels(parsedConfig.tiers?.NON_REASONING);
|
||||
const enable_non_reasoning_tier: boolean =
|
||||
parsedConfig.enable_non_reasoning_tier === true || storedNonReasoning.length > 0;
|
||||
const hydratedTiers: ComplexityTiers = {
|
||||
SIMPLE: normalizeTierModels(parsedConfig.tiers?.SIMPLE),
|
||||
MEDIUM: normalizeTierModels(parsedConfig.tiers?.MEDIUM),
|
||||
COMPLEX: normalizeTierModels(parsedConfig.tiers?.COMPLEX),
|
||||
REASONING: normalizeTierModels(parsedConfig.tiers?.REASONING),
|
||||
...(enable_non_reasoning_tier && { NON_REASONING: storedNonReasoning }),
|
||||
};
|
||||
|
||||
const builtIn = hydrateBuiltInTiers(parsedConfig.tiers, parsedConfig.enable_non_reasoning_tier);
|
||||
const { tiers: hydratedTiers, enable_non_reasoning_tier } = builtIn;
|
||||
const custom_tier_set = hydrateCustomTierSet(parsedConfig);
|
||||
const activeTiers = { tiers: hydratedTiers, enable_non_reasoning_tier, custom_tier_set };
|
||||
const activeTiers = { ...builtIn, custom_tier_set };
|
||||
|
||||
return {
|
||||
tiers: hydratedTiers,
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue