|
1 |
| -import { Modal, SliderWithInput } from '@lobehub/ui'; |
| 1 | +import { Modal } from '@lobehub/ui'; |
2 | 2 | import { Checkbox, Form, Input } from 'antd';
|
| 3 | +import isEqual from 'fast-deep-equal'; |
3 | 4 | import { memo } from 'react';
|
4 | 5 | import { useTranslation } from 'react-i18next';
|
5 | 6 |
|
6 |
| -import { GlobalLLMProviderKey } from '@/types/settings'; |
| 7 | +import { useGlobalStore } from '@/store/global'; |
| 8 | +import { modelConfigSelectors } from '@/store/global/slices/settings/selectors'; |
7 | 9 |
|
8 |
| -interface ModelConfigModalProps { |
9 |
| - id: string; |
10 |
| - onOpenChange: (open: boolean) => void; |
11 |
| - open?: boolean; |
12 |
| - provider: GlobalLLMProviderKey; |
13 |
| -} |
14 |
| -const ModelConfigModal = memo<ModelConfigModalProps>(({ open, id, onOpenChange }) => { |
| 10 | +import MaxTokenSlider from './MaxTokenSlider'; |
| 11 | + |
| 12 | +const ModelConfigModal = memo(() => { |
15 | 13 | const [formInstance] = Form.useForm();
|
16 | 14 | const { t } = useTranslation('setting');
|
17 | 15 |
|
| 16 | + const [open, id, provider, dispatchCustomModelCards, toggleEditingCustomModelCard] = |
| 17 | + useGlobalStore((s) => [ |
| 18 | + !!s.editingCustomCardModel, |
| 19 | + s.editingCustomCardModel?.id, |
| 20 | + s.editingCustomCardModel?.provider, |
| 21 | + s.dispatchCustomModelCards, |
| 22 | + s.toggleEditingCustomModelCard, |
| 23 | + ]); |
| 24 | + |
| 25 | + const modelCard = useGlobalStore( |
| 26 | + modelConfigSelectors.getCustomModelCardById({ id, provider }), |
| 27 | + isEqual, |
| 28 | + ); |
| 29 | + |
| 30 | + const closeModal = () => { |
| 31 | + toggleEditingCustomModelCard(undefined); |
| 32 | + }; |
| 33 | + |
18 | 34 | return (
|
19 | 35 | <Modal
|
| 36 | + destroyOnClose |
20 | 37 | maskClosable
|
21 | 38 | onCancel={() => {
|
22 |
| - onOpenChange(false); |
| 39 | + closeModal(); |
| 40 | + }} |
| 41 | + onOk={() => { |
| 42 | + if (!provider || !id) return; |
| 43 | + const data = formInstance.getFieldsValue(); |
| 44 | + |
| 45 | + dispatchCustomModelCards(provider as any, { id, type: 'update', value: data }); |
| 46 | + |
| 47 | + closeModal(); |
23 | 48 | }}
|
24 | 49 | open={open}
|
25 | 50 | title={t('llm.customModelCards.modelConfig.modalTitle')}
|
26 | 51 | >
|
27 |
| - <Form |
28 |
| - colon={false} |
29 |
| - form={formInstance} |
30 |
| - labelCol={{ offset: 0, span: 4 }} |
31 |
| - style={{ marginTop: 16 }} |
32 |
| - wrapperCol={{ offset: 1, span: 19 }} |
| 52 | + <div |
| 53 | + onClick={(e) => { |
| 54 | + e.stopPropagation(); |
| 55 | + }} |
| 56 | + onKeyDown={(e) => { |
| 57 | + e.stopPropagation(); |
| 58 | + }} |
33 | 59 | >
|
34 |
| - <Form.Item label={t('llm.customModelCards.modelConfig.id.title')} name={'id'}> |
35 |
| - <Input placeholder={t('llm.customModelCards.modelConfig.id.placeholder')} /> |
36 |
| - </Form.Item> |
37 |
| - <Form.Item |
38 |
| - label={t('llm.customModelCards.modelConfig.displayName.title')} |
39 |
| - name={'displayName'} |
40 |
| - > |
41 |
| - <Input placeholder={t('llm.customModelCards.modelConfig.displayName.placeholder')} /> |
42 |
| - </Form.Item> |
43 |
| - <Form.Item label={t('llm.customModelCards.modelConfig.tokens.title')} name={'tokens'}> |
44 |
| - <SliderWithInput |
45 |
| - marks={{ |
46 |
| - 100_000: '100k', |
47 |
| - 128_000: '128k', |
48 |
| - 16_385: '16k', |
49 |
| - 200_000: '200k', |
50 |
| - 32_768: '32k', |
51 |
| - 4096: '4k', |
52 |
| - }} |
53 |
| - max={200_000} |
54 |
| - min={0} |
55 |
| - /> |
56 |
| - </Form.Item> |
57 |
| - <Form.Item |
58 |
| - extra={t('llm.customModelCards.modelConfig.functionCall.extra')} |
59 |
| - label={t('llm.customModelCards.modelConfig.functionCall.title')} |
60 |
| - name={'functionCall'} |
61 |
| - > |
62 |
| - <Checkbox /> |
63 |
| - </Form.Item> |
64 |
| - <Form.Item |
65 |
| - extra={t('llm.customModelCards.modelConfig.vision.extra')} |
66 |
| - label={t('llm.customModelCards.modelConfig.vision.title')} |
67 |
| - name={'vision'} |
68 |
| - > |
69 |
| - <Checkbox /> |
70 |
| - </Form.Item> |
71 |
| - <Form.Item |
72 |
| - extra={t('llm.customModelCards.modelConfig.files.extra')} |
73 |
| - label={t('llm.customModelCards.modelConfig.files.title')} |
74 |
| - name={'files'} |
| 60 | + <Form |
| 61 | + colon={false} |
| 62 | + form={formInstance} |
| 63 | + initialValues={modelCard} |
| 64 | + labelCol={{ span: 4 }} |
| 65 | + style={{ marginTop: 16 }} |
| 66 | + wrapperCol={{ offset: 1, span: 18 }} |
75 | 67 | >
|
76 |
| - <Checkbox /> |
77 |
| - </Form.Item> |
78 |
| - </Form> |
| 68 | + <Form.Item label={t('llm.customModelCards.modelConfig.id.title')} name={'id'}> |
| 69 | + <Input placeholder={t('llm.customModelCards.modelConfig.id.placeholder')} /> |
| 70 | + </Form.Item> |
| 71 | + <Form.Item |
| 72 | + label={t('llm.customModelCards.modelConfig.displayName.title')} |
| 73 | + name={'displayName'} |
| 74 | + > |
| 75 | + <Input placeholder={t('llm.customModelCards.modelConfig.displayName.placeholder')} /> |
| 76 | + </Form.Item> |
| 77 | + <Form.Item label={t('llm.customModelCards.modelConfig.tokens.title')} name={'tokens'}> |
| 78 | + <MaxTokenSlider /> |
| 79 | + </Form.Item> |
| 80 | + <Form.Item |
| 81 | + extra={t('llm.customModelCards.modelConfig.functionCall.extra')} |
| 82 | + label={t('llm.customModelCards.modelConfig.functionCall.title')} |
| 83 | + name={'functionCall'} |
| 84 | + valuePropName={'checked'} |
| 85 | + > |
| 86 | + <Checkbox /> |
| 87 | + </Form.Item> |
| 88 | + <Form.Item |
| 89 | + extra={t('llm.customModelCards.modelConfig.vision.extra')} |
| 90 | + label={t('llm.customModelCards.modelConfig.vision.title')} |
| 91 | + name={'vision'} |
| 92 | + valuePropName={'checked'} |
| 93 | + > |
| 94 | + <Checkbox /> |
| 95 | + </Form.Item> |
| 96 | + <Form.Item |
| 97 | + extra={t('llm.customModelCards.modelConfig.files.extra')} |
| 98 | + label={t('llm.customModelCards.modelConfig.files.title')} |
| 99 | + name={'files'} |
| 100 | + valuePropName={'checked'} |
| 101 | + > |
| 102 | + <Checkbox /> |
| 103 | + </Form.Item> |
| 104 | + </Form> |
| 105 | + </div> |
79 | 106 | </Modal>
|
80 | 107 | );
|
81 | 108 | });
|
|
0 commit comments