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 e4e6ebd1da9..ff5086c225c 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 @@ -1,15 +1,28 @@ -import React, { useEffect, useState } from "react"; -import { Modal, Form, Button, Select as AntdSelect } from "antd"; -import { Text, TextInput } from "@tremor/react"; +import React, { useEffect, useState, useCallback } from "react"; +import { Button } from "@/components/ui/button"; +import { + Dialog, + DialogContent, + DialogFooter, + DialogHeader, + DialogTitle, +} from "@/components/ui/dialog"; +import { Input } from "@/components/ui/input"; +import { Form, Select as AntdSelect } from "antd"; import { modelAvailableCall, modelPatchUpdateCall } from "../networking"; -import { fetchAvailableModels, ModelGroup } from "../playground/llm_calls/fetch_models"; +import { + fetchAvailableModels, + ModelGroup, +} from "../playground/llm_calls/fetch_models"; import RouterConfigBuilder from "../add_model/RouterConfigBuilder"; import NotificationsManager from "../molecules/notifications_manager"; interface EditAutoRouterModalProps { isVisible: boolean; onCancel: () => void; + // eslint-disable-next-line @typescript-eslint/no-explicit-any onSuccess: (updatedModel: any) => void; + // eslint-disable-next-line @typescript-eslint/no-explicit-any modelData: any; accessToken: string; userRole: string; @@ -27,22 +40,77 @@ const EditAutoRouterModal: React.FC = ({ const [loading, setLoading] = useState(false); const [modelAccessGroups, setModelAccessGroups] = useState([]); const [modelInfo, setModelInfo] = useState([]); - const [showCustomDefaultModel, setShowCustomDefaultModel] = useState(false); - const [showCustomEmbeddingModel, setShowCustomEmbeddingModel] = useState(false); + const [_showCustomDefaultModel, setShowCustomDefaultModel] = + useState(false); + const [_showCustomEmbeddingModel, setShowCustomEmbeddingModel] = + useState(false); + // eslint-disable-next-line @typescript-eslint/no-explicit-any const [routerConfig, setRouterConfig] = useState(null); + const initializeForm = useCallback(() => { + try { + let parsedConfig = null; + if (modelData.litellm_params?.auto_router_config) { + if (typeof modelData.litellm_params.auto_router_config === "string") { + parsedConfig = JSON.parse( + modelData.litellm_params.auto_router_config, + ); + } else { + parsedConfig = modelData.litellm_params.auto_router_config; + } + } + + setRouterConfig(parsedConfig); + + form.setFieldsValue({ + auto_router_name: modelData.model_name, + auto_router_default_model: + modelData.litellm_params?.auto_router_default_model || "", + auto_router_embedding_model: + modelData.litellm_params?.auto_router_embedding_model || "", + model_access_group: modelData.model_info?.access_groups || [], + }); + + const allModelGroups = new Set( + modelInfo.map((model) => model.model_group), + ); + setShowCustomDefaultModel( + !allModelGroups.has(modelData.litellm_params?.auto_router_default_model), + ); + setShowCustomEmbeddingModel( + !allModelGroups.has( + modelData.litellm_params?.auto_router_embedding_model, + ), + ); + } catch (error) { + console.error("Error parsing auto router config:", error); + NotificationsManager.fromBackend("Error loading auto router configuration"); + } + }, [form, modelData, modelInfo]); + useEffect(() => { if (isVisible && modelData) { initializeForm(); } - }, [isVisible, modelData]); + }, [isVisible, modelData, initializeForm]); useEffect(() => { const fetchModelAccessGroups = async () => { if (!accessToken) return; try { - const response = await modelAvailableCall(accessToken, "", "", false, null, true, true); - setModelAccessGroups(response["data"].map((model: any) => model["id"])); + const response = await modelAvailableCall( + accessToken, + "", + "", + false, + null, + true, + true, + ); + setModelAccessGroups( + // eslint-disable-next-line @typescript-eslint/no-explicit-any + response["data"].map((model: any) => model["id"]), + ); } catch (error) { console.error("Error fetching model access groups:", error); } @@ -64,38 +132,6 @@ const EditAutoRouterModal: React.FC = ({ } }, [isVisible, accessToken]); - const initializeForm = () => { - try { - // Parse the auto_router_config if it exists and is a string - let parsedConfig = null; - if (modelData.litellm_params?.auto_router_config) { - if (typeof modelData.litellm_params.auto_router_config === "string") { - parsedConfig = JSON.parse(modelData.litellm_params.auto_router_config); - } else { - parsedConfig = modelData.litellm_params.auto_router_config; - } - } - - setRouterConfig(parsedConfig); - - // Set form values - form.setFieldsValue({ - auto_router_name: modelData.model_name, - auto_router_default_model: modelData.litellm_params?.auto_router_default_model || "", - auto_router_embedding_model: modelData.litellm_params?.auto_router_embedding_model || "", - model_access_group: modelData.model_info?.access_groups || [], - }); - - // Check if using custom models - const allModelGroups = new Set(modelInfo.map((model) => model.model_group)); - setShowCustomDefaultModel(!allModelGroups.has(modelData.litellm_params?.auto_router_default_model)); - setShowCustomEmbeddingModel(!allModelGroups.has(modelData.litellm_params?.auto_router_embedding_model)); - } catch (error) { - console.error("Error parsing auto router config:", error); - NotificationsManager.fromBackend("Error loading auto router configuration"); - } - }; - const handleSubmit = async () => { try { setLoading(true); @@ -147,101 +183,112 @@ const EditAutoRouterModal: React.FC = ({ })); return ( - - Cancel - , - , - ]} - width={1000} - destroyOnHidden + onOpenChange={(o) => (!o ? onCancel() : undefined)} > -
- - Edit the auto router configuration including routing logic, default models, and access settings. - + + + Edit Auto Router Configuration + +
+

+ Edit the auto router configuration including routing logic, default + models, and access settings. +

-
- {/* Auto Router Name */} - - - - - {/* Router Configuration Builder */} -
- { - setRouterConfig(config); - }} - /> -
- - {/* Default Model */} - - { - setShowCustomDefaultModel(value === "custom"); - }} - options={[...modelOptions, { value: "custom", label: "Enter custom model name" }]} - showSearch={true} - /> - - - {/* Embedding Model */} - - { - setShowCustomEmbeddingModel(value === "custom"); - }} - options={[...modelOptions, { value: "custom", label: "Enter custom model name" }]} - showSearch={true} - allowClear - /> - - - {/* Model Access Groups - Admin only */} - {userRole === "Admin" && ( + + + + +
+ { + setRouterConfig(config); + }} + /> +
+ + ({ - value: group, - label: group, - }))} - maxTagCount="responsive" + placeholder="Select a default model" + onChange={(value) => { + setShowCustomDefaultModel(value === "custom"); + }} + options={[ + ...modelOptions, + { value: "custom", label: "Enter custom model name" }, + ]} + showSearch={true} + /> + + + + { + setShowCustomEmbeddingModel(value === "custom"); + }} + options={[ + ...modelOptions, + { value: "custom", label: "Enter custom model name" }, + ]} + showSearch={true} allowClear /> - )} -
-
- + + {userRole === "Admin" && ( + + ({ + value: group, + label: group, + }))} + maxTagCount="responsive" + allowClear + /> + + )} + +
+ + + + + + ); };