import React, { useEffect, useState } from 'react'; import { ExternalLink, Plus } from 'lucide-react'; import Modal from '../../Modal'; import { Button } from '../../ui/button'; import { QUICKSTART_GUIDE_URL } from '../providers/modal/constants'; import { Input } from '../../ui/input'; import { Select } from '../../ui/Select'; import { useConfig } from '../../ConfigContext'; import { ToastError, ToastSuccess } from '../../settings/models/toasts'; import { initializeSystem } from '../../../../src/utils/providerUtils'; const ModalButtons = ({ onSubmit, onCancel }) => (
); type AddModelModalProps = { onClose: () => void }; export const AddModelModal = ({ onClose }: AddModelModalProps) => { const { getProviders, upsert } = useConfig(); const [providerOptions, setProviderOptions] = useState([]); const [provider, setProvider] = useState(null); const [modelName, setModelName] = useState(''); const changeModel = async () => { try { await upsert('GOOSE_PROVIDER', provider, false); await upsert('GOOSE_MODEL', modelName, false); await initializeSystem(provider, modelName); ToastSuccess({ title: 'Model changed', msg: `Switched to ${modelName}.`, }); onClose(); } catch (e) { ToastError({ title: 'Failed to add model', traceback: e.message, }); } }; useEffect(() => { (async () => { try { const providersResponse = await getProviders(false); const activeProviders = providersResponse.filter((provider) => provider.is_configured); setProviderOptions( activeProviders.map(({ metadata, name }) => ({ value: name, label: metadata.display_name, })) ); } catch (error) { console.error('Failed to load providers:', error); } })(); }, [getProviders]); return (
}>
Add model
Configure your AI model providers by adding their API keys. your Keys are stored securely and encrypted locally.
setModelName(event.target.value)} value={modelName} />
); };