File size: 8,234 Bytes
7ccbbf8 21cf732 88e5a61 7e26e0d 7ccbbf8 7e26e0d ebf2bde 7e26e0d d80b399 7e26e0d e55650e 3313a7c ebf2bde 7ccbbf8 7e26e0d 7ccbbf8 7e26e0d e693841 7e26e0d e55650e ebf2bde e55650e 21cf732 dea956e e55650e 7e26e0d 21cf732 dea956e 21cf732 7e26e0d d80b399 21cf732 e693841 dd4cbfc dea956e d80b399 21cf732 d80b399 7ccbbf8 88e5a61 ebf2bde 7ccbbf8 d80b399 7ccbbf8 6db9c7b 7ccbbf8 88e5a61 7ccbbf8 3313a7c ebf2bde 3313a7c 7ccbbf8 657bc8a 7e26e0d e55650e 7e26e0d 3fb07ee 7e26e0d 7ccbbf8 88e5a61 21cf732 e693841 21cf732 7ccbbf8 dea956e 7ccbbf8 e693841 6db9c7b 21cf732 7ccbbf8 6db9c7b 7ccbbf8 7e26e0d 7ccbbf8 e693841 dea956e 21cf732 7e26e0d d80b399 88e5a61 d80b399 7e26e0d 7ccbbf8 7e26e0d d80b399 88e5a61 d80b399 7e26e0d d80b399 7e26e0d 7ccbbf8 7e26e0d d80b399 7e26e0d 7ccbbf8 7e26e0d 7ccbbf8 88e5a61 7ccbbf8 7e26e0d d80b399 4c6dadf e55650e 4c6dadf e55650e 88e5a61 40a88fa e55650e 21cf732 e55650e 7e26e0d 3fb07ee 7e26e0d 7ccbbf8 21cf732 e693841 21cf732 dea956e 4c6dadf 7e26e0d 657bc8a |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 |
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,
useSubmitVolcEngine,
useSubmitSystemModelSetting,
} from './hooks';
import styles from './index.less';
import OllamaModal from './ollama-modal';
import VolcEngineModal from "./volcengine-model";
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',
VolcEngine: 'volc_engine',
};
const LlmIcon = ({ name }: { name: string }) => {
const icon = IconMap[name as keyof typeof IconMap];
return icon ? (
<SvgIcon name={`llm/${icon}`} width={48} height={48}></SvgIcon>
) : (
<Avatar shape="square" size="large" icon={<UserOutlined />} />
);
};
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 (
<List.Item>
<Card className={styles.addedCard}>
<Row align={'middle'}>
<Col span={12}>
<Flex gap={'middle'} align="center">
<LlmIcon name={item.name} />
<Flex vertical gap={'small'}>
<b>{item.name}</b>
<Text>{item.tags}</Text>
</Flex>
</Flex>
</Col>
<Col span={12} className={styles.factoryOperationWrapper}>
<Space size={'middle'}>
<Button onClick={handleApiKeyClick}>
{isLocalLlmFactory(item.name) || item.name === 'VolcEngine' ? t('addTheModel') : 'API-Key'}
<SettingOutlined />
</Button>
<Button onClick={handleShowMoreClick}>
<Flex gap={'small'}>
{t('showMoreModels')}
<MoreModelIcon />
</Flex>
</Button>
</Space>
</Col>
</Row>
{visible && (
<List
size="small"
dataSource={item.llm}
className={styles.llmList}
renderItem={(item) => (
<List.Item>
<Space>
{item.name} <Tag color="#b8b8b8">{item.type}</Tag>
<Tooltip title={t('delete', { keyPrefix: 'common' })}>
<Button type={'text'} onClick={handleDeleteLlm(item.name)}>
<CloseCircleOutlined style={{ color: '#D92D20' }} />
</Button>
</Tooltip>
</Space>
</List.Item>
)}
/>
)}
</Card>
</List.Item>
);
};
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 {
volcAddingVisible,
hideVolcAddingModal,
showVolcAddingModal,
onVolcAddingOk,
volcAddingLoading,
selectedVolcFactory,
} = useSubmitVolcEngine();
const handleApiKeyClick = useCallback(
(llmFactory: string) => {
if (isLocalLlmFactory(llmFactory)) {
showLlmAddingModal(llmFactory);
} else if (llmFactory === 'VolcEngine') {
showVolcAddingModal('VolcEngine');
} else {
showApiKeyModal({ llm_factory: llmFactory });
}
},
[showApiKeyModal, showLlmAddingModal, showVolcAddingModal],
);
const handleAddModel = (llmFactory: string) => () => {
if (isLocalLlmFactory(llmFactory)) {
showLlmAddingModal(llmFactory);
} else if (llmFactory === 'VolcEngine') {
showVolcAddingModal('VolcEngine');
} else {
handleApiKeyClick(llmFactory);
}
};
const items: CollapseProps['items'] = [
{
key: '1',
label: t('addedModels'),
children: (
<List
grid={{ gutter: 16, column: 1 }}
dataSource={llmList}
renderItem={(item) => (
<ModelCard item={item} clickApiKey={handleApiKeyClick}></ModelCard>
)}
/>
),
},
{
key: '2',
label: t('modelsToBeAdded'),
children: (
<List
grid={{
gutter: 24,
xs: 1,
sm: 2,
md: 3,
lg: 4,
xl: 4,
xxl: 8,
}}
dataSource={factoryList}
renderItem={(item) => (
<List.Item>
<Card className={styles.toBeAddedCard}>
<Flex vertical gap={'large'}>
<LlmIcon name={item.name} />
<Flex vertical gap={'middle'}>
<b>{item.name}</b>
<Text>{item.tags}</Text>
</Flex>
</Flex>
<Divider></Divider>
<Button type="link" onClick={handleAddModel(item.name)}>
{t('addTheModel')}
</Button>
</Card>
</List.Item>
)}
/>
),
},
];
return (
<section id="xx" className={styles.modelWrapper}>
<Spin spinning={loading}>
<section className={styles.modelContainer}>
<SettingTitle
title={t('model')}
description={t('modelDescription')}
showRightButton
clickButton={showSystemSettingModal}
></SettingTitle>
<Divider></Divider>
<Collapse defaultActiveKey={['1', '2']} ghost items={items} />
</section>
</Spin>
<ApiKeyModal
visible={apiKeyVisible}
hideModal={hideApiKeyModal}
loading={saveApiKeyLoading}
initialValue={initialApiKey}
onOk={onApiKeySavingOk}
llmFactory={llmFactory}
></ApiKeyModal>
<SystemModelSettingModal
visible={systemSettingVisible}
onOk={onSystemSettingSavingOk}
hideModal={hideSystemSettingModal}
loading={saveSystemModelSettingLoading}
></SystemModelSettingModal>
<OllamaModal
visible={llmAddingVisible}
hideModal={hideLlmAddingModal}
onOk={onLlmAddingOk}
loading={llmAddingLoading}
llmFactory={selectedLlmFactory}
></OllamaModal>
<VolcEngineModal
visible={volcAddingVisible}
hideModal={hideVolcAddingModal}
onOk={onVolcAddingOk}
loading={volcAddingLoading}
llmFactory={selectedVolcFactory}
></VolcEngineModal>
</section>
);
};
export default UserSettingModel;
|