import { ReactComponent as MoreModelIcon } from '@/assets/svg/more-model.svg';
import { useSetModalState } from '@/hooks/commonHooks';
import {
LlmItem,
useFetchLlmFactoryListOnMount,
useFetchMyLlmListOnMount,
} from '@/hooks/llmHooks';
import { ReactComponent as MoonshotIcon } from '@/icons/moonshot.svg';
import { ReactComponent as OpenAiIcon } from '@/icons/openai.svg';
import { ReactComponent as TongYiIcon } from '@/icons/tongyi.svg';
import { ReactComponent as WenXinIcon } from '@/icons/wenxin.svg';
import { ReactComponent as ZhiPuIcon } from '@/icons/zhipu.svg';
import { SettingOutlined, UserOutlined } from '@ant-design/icons';
import {
Avatar,
Button,
Card,
Col,
Collapse,
CollapseProps,
Divider,
Flex,
List,
Row,
Space,
Spin,
Typography,
} from 'antd';
import { useCallback } from 'react';
import SettingTitle from '../components/setting-title';
import ApiKeyModal from './api-key-modal';
import {
useSelectModelProvidersLoading,
useSubmitApiKey,
useSubmitSystemModelSetting,
} from './hooks';
import SystemModelSettingModal from './system-model-setting-modal';
import styles from './index.less';
const IconMap = {
'Tongyi-Qianwen': TongYiIcon,
Moonshot: MoonshotIcon,
OpenAI: OpenAiIcon,
'ZHIPU-AI': ZhiPuIcon,
文心一言: WenXinIcon,
};
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 handleApiKeyClick = () => {
clickApiKey(item.name);
};
const handleShowMoreClick = () => {
switchVisible();
};
return (
{item.name}
{item.tags}
{visible && (
{item.name}}
/>
)}
);
};
const UserSettingModel = () => {
const factoryList = useFetchLlmFactoryListOnMount();
const llmList = useFetchMyLlmListOnMount();
const loading = useSelectModelProvidersLoading();
const {
saveApiKeyLoading,
initialApiKey,
onApiKeySavingOk,
apiKeyVisible,
hideApiKeyModal,
showApiKeyModal,
} = useSubmitApiKey();
const {
saveSystemModelSettingLoading,
onSystemSettingSavingOk,
systemSettingVisible,
hideSystemSettingModal,
showSystemSettingModal,
} = useSubmitSystemModelSetting();
const handleApiKeyClick = useCallback(
(llmFactory: string) => {
showApiKeyModal({ llm_factory: llmFactory });
},
[showApiKeyModal],
);
const handleAddModel = (llmFactory: string) => () => {
handleApiKeyClick(llmFactory);
};
const items: CollapseProps['items'] = [
{
key: '1',
label: 'Added models',
children: (
(
)}
/>
),
},
{
key: '2',
label: 'Models to be added',
children: (
(
{item.name}
{item.tags}
)}
/>
),
},
];
return (
<>
>
);
};
export default UserSettingModel;