import { ReactComponent as MoreModelIcon } from '@/assets/svg/more-model.svg'; import SvgIcon from '@/components/svg-icon'; import { useSetModalState, useTranslate } from '@/hooks/commonHooks'; import { LlmItem, useFetchLlmFactoryListOnMount, useFetchMyLlmListOnMount, } from '@/hooks/llmHooks'; import { CloseCircleOutlined, SettingOutlined, UserOutlined, } from '@ant-design/icons'; import { Avatar, Button, Card, Col, Collapse, CollapseProps, Divider, Flex, List, Row, Space, Spin, Tag, Tooltip, Typography, } from 'antd'; import { useCallback } from 'react'; import SettingTitle from '../components/setting-title'; import { isLocalLlmFactory } from '../utils'; import ApiKeyModal from './api-key-modal'; import { useHandleDeleteLlm, useSelectModelProvidersLoading, useSubmitApiKey, useSubmitOllama, useSubmitSystemModelSetting, } from './hooks'; import styles from './index.less'; import OllamaModal from './ollama-modal'; import SystemModelSettingModal from './system-model-setting-modal'; const IconMap = { 'Tongyi-Qianwen': 'tongyi', Moonshot: 'moonshot', OpenAI: 'openai', 'ZHIPU-AI': 'zhipu', 文心一言: 'wenxin', Ollama: 'ollama', Xinference: 'xinference', DeepSeek: 'deepseek', }; const LlmIcon = ({ name }: { name: string }) => { const icon = IconMap[name as keyof typeof IconMap]; return icon ? ( ) : ( } /> ); }; const { Text } = Typography; interface IModelCardProps { item: LlmItem; clickApiKey: (llmFactory: string) => void; } const ModelCard = ({ item, clickApiKey }: IModelCardProps) => { const { visible, switchVisible } = useSetModalState(); const { t } = useTranslate('setting'); const { handleDeleteLlm } = useHandleDeleteLlm(item.name); const handleApiKeyClick = () => { clickApiKey(item.name); }; const handleShowMoreClick = () => { switchVisible(); }; return ( {item.name} {item.tags} {visible && ( ( {item.name} {item.type} )} /> )} ); }; const UserSettingModel = () => { const factoryList = useFetchLlmFactoryListOnMount(); const llmList = useFetchMyLlmListOnMount(); const loading = useSelectModelProvidersLoading(); const { saveApiKeyLoading, initialApiKey, llmFactory, onApiKeySavingOk, apiKeyVisible, hideApiKeyModal, showApiKeyModal, } = useSubmitApiKey(); const { saveSystemModelSettingLoading, onSystemSettingSavingOk, systemSettingVisible, hideSystemSettingModal, showSystemSettingModal, } = useSubmitSystemModelSetting(); const { t } = useTranslate('setting'); const { llmAddingVisible, hideLlmAddingModal, showLlmAddingModal, onLlmAddingOk, llmAddingLoading, selectedLlmFactory, } = useSubmitOllama(); const handleApiKeyClick = useCallback( (llmFactory: string) => { if (isLocalLlmFactory(llmFactory)) { showLlmAddingModal(llmFactory); } else { showApiKeyModal({ llm_factory: llmFactory }); } }, [showApiKeyModal, showLlmAddingModal], ); const handleAddModel = (llmFactory: string) => () => { if (isLocalLlmFactory(llmFactory)) { showLlmAddingModal(llmFactory); } else { handleApiKeyClick(llmFactory); } }; const items: CollapseProps['items'] = [ { key: '1', label: t('addedModels'), children: ( ( )} /> ), }, { key: '2', label: t('modelsToBeAdded'), children: ( ( {item.name} {item.tags} )} /> ), }, ]; return (
); }; export default UserSettingModel;