import React from "react"; import { Form, Select as AntSelect } from "antd"; import { TextInput, Text } from "@tremor/react"; import { Row, Col } from "antd"; import { Providers } from "../provider_info_helpers"; interface LiteLLMModelNameFieldProps { selectedProvider: Providers; providerModels: string[]; getPlaceholder: (provider: Providers) => string; } const LiteLLMModelNameField: React.FC = ({ selectedProvider, providerModels, getPlaceholder, }) => { const form = Form.useFormInstance(); const handleModelChange = (value: string | string[]) => { // Ensure value is always treated as an array const values = Array.isArray(value) ? value : [value]; // If "all-wildcard" is selected, clear the model_name field if (values.includes("all-wildcard")) { form.setFieldsValue({ model_name: undefined, model_mappings: [] }); } else { // Get current model value to check if we need to update const currentModel = form.getFieldValue('model'); // Only update if the value has actually changed if (JSON.stringify(currentModel) !== JSON.stringify(values)) { // Create mappings first const mappings = values.map(model => ({ public_name: model, litellm_model: model })); // Update both fields in one call to reduce re-renders form.setFieldsValue({ model: values, model_mappings: mappings }); } } }; // Handle custom model name changes const handleCustomModelNameChange = (e: React.ChangeEvent) => { const customName = e.target.value; // Immediately update the model mappings const currentMappings = form.getFieldValue('model_mappings') || []; const updatedMappings = currentMappings.map((mapping: any) => { if (mapping.public_name === 'custom' || mapping.litellm_model === 'custom') { return { public_name: customName, litellm_model: customName }; } return mapping; }); form.setFieldsValue({ model_mappings: updatedMappings }); }; return ( <> {(selectedProvider === Providers.Azure) || (selectedProvider === Providers.OpenAI_Compatible) || (selectedProvider === Providers.Ollama) ? ( <> ) : providerModels.length > 0 ? ( (option?.label ?? '').toLowerCase().includes(input.toLowerCase()) } options={[ { label: 'Custom Model Name (Enter below)', value: 'custom' }, { label: `All ${selectedProvider} Models (Wildcard)`, value: 'all-wildcard' }, ...providerModels.map(model => ({ label: model, value: model })) ]} style={{ width: '100%' }} /> ) : ( )} {/* Custom Model Name field */} prevValues.model !== currentValues.model } > {({ getFieldValue }) => { const selectedModels = getFieldValue('model') || []; const modelArray = Array.isArray(selectedModels) ? selectedModels : [selectedModels]; return modelArray.includes('custom') && ( ); }} Actual model name used for making litellm.completion() call. We loadbalance models with the same public name ); }; export default LiteLLMModelNameField;