import { IconSettings } from '@tabler/icons-react' import debounce from 'lodash.debounce' import { Sheet, SheetContent, SheetDescription, SheetHeader, SheetTitle, SheetTrigger, } from '@/components/ui/sheet' import { DynamicControllerSetting } from '@/containers/dynamicControllerSetting' import { useModelProvider } from '@/hooks/useModelProvider' import { stopModel } from '@/services/models' import { cn } from '@/lib/utils' import { useTranslation } from '@/i18n/react-i18next-compat' type ModelSettingProps = { provider: ProviderObject model: Model smallIcon?: boolean } export function ModelSetting({ model, provider, smallIcon, }: ModelSettingProps) { const { updateProvider } = useModelProvider() const { t } = useTranslation() // Create a debounced version of stopModel that waits 500ms after the last call const debouncedStopModel = debounce((modelId: string) => { stopModel(modelId) }, 500) const handleSettingChange = ( key: string, value: string | boolean | number ) => { if (!provider) return // Create a copy of the model with updated settings const updatedModel = { ...model, settings: { ...model.settings, [key]: { ...(model.settings?.[key] != null ? model.settings?.[key] : {}), controller_props: { ...(model.settings?.[key]?.controller_props ?? {}), value: value, }, }, }, } // Find the model index in the provider's models array const modelIndex = provider.models.findIndex((m) => m.id === model.id) if (modelIndex !== -1) { // Create a copy of the provider's models array const updatedModels = [...provider.models] // Update the specific model in the array updatedModels[modelIndex] = updatedModel as Model // Update the provider with the new models array updateProvider(provider.provider, { models: updatedModels, }) // Call debounced stopModel only when updating ctx_len, ngl, chat_template, or offload_mmproj if (key === 'ctx_len' || key === 'ngl' || key === 'chat_template' || key === 'offload_mmproj') { debouncedStopModel(model.id) } } } return (
{t('common:modelSettings.title', { modelId: model.id })} {t('common:modelSettings.description')}
{Object.entries(model.settings || {}).map(([key, value]) => { const config = value as ProviderSetting return (

{config.title}

{config.description}

handleSettingChange(key, newValue)} />
) })}
) }