File size: 3,011 Bytes
7ccbbf8
d80b399
68ed806
 
7ccbbf8
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
d80b399
598945f
88e5a61
7ccbbf8
 
 
777daee
 
 
 
 
 
 
7ccbbf8
 
 
21cf732
 
 
 
7ccbbf8
 
 
 
 
88e5a61
7ccbbf8
 
 
 
 
 
 
88e5a61
 
 
 
 
777daee
7ccbbf8
88e5a61
 
 
 
 
777daee
7ccbbf8
84f80c5
88e5a61
84f80c5
88e5a61
84f80c5
777daee
7ccbbf8
88e5a61
b7adc24
88e5a61
b7adc24
88e5a61
b7adc24
777daee
7ccbbf8
d594e0f
 
 
 
 
777daee
d594e0f
e10ed78
 
 
 
 
777daee
e10ed78
7ccbbf8
 
 
 
 
 
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
import { IModalManagerChildrenProps } from '@/components/modal-manager';
import { LlmModelType } from '@/constants/knowledge';
import { useTranslate } from '@/hooks/common-hooks';
import { ISystemModelSettingSavingParams } from '@/hooks/llm-hooks';
import { Form, Modal, Select } from 'antd';
import { useEffect } from 'react';
import { useFetchSystemModelSettingOnMount } from '../hooks';

interface IProps extends Omit<IModalManagerChildrenProps, 'showModal'> {
  loading: boolean;
  onOk: (
    payload: Omit<ISystemModelSettingSavingParams, 'tenant_id' | 'name'>,
  ) => void;
}

const SystemModelSettingModal = ({
  visible,
  hideModal,
  onOk,
  loading,
}: IProps) => {
  const [form] = Form.useForm();
  const { systemSetting: initialValues, allOptions } =
    useFetchSystemModelSettingOnMount();
  const { t } = useTranslate('setting');

  const handleOk = async () => {
    const values = await form.validateFields();
    onOk({
      ...values,
      asr_id: values.asr_id ?? '',
      embd_id: values.embd_id ?? '',
      img2txt_id: values.img2txt_id ?? '',
      llm_id: values.llm_id ?? '',
    });
  };

  useEffect(() => {
    if (visible) {
      form.setFieldsValue(initialValues);
    }
  }, [form, initialValues, visible]);

  const onFormLayoutChange = () => {};

  return (
    <Modal
      title={t('systemModelSettings')}
      open={visible}
      onOk={handleOk}
      onCancel={hideModal}
      okButtonProps={{ loading }}
      confirmLoading={loading}
    >
      <Form form={form} onValuesChange={onFormLayoutChange} layout={'vertical'}>
        <Form.Item
          label={t('chatModel')}
          name="llm_id"
          tooltip={t('chatModelTip')}
        >
          <Select options={allOptions[LlmModelType.Chat]} allowClear />
        </Form.Item>
        <Form.Item
          label={t('embeddingModel')}
          name="embd_id"
          tooltip={t('embeddingModelTip')}
        >
          <Select options={allOptions[LlmModelType.Embedding]} allowClear />
        </Form.Item>
        <Form.Item
          label={t('img2txtModel')}
          name="img2txt_id"
          tooltip={t('img2txtModelTip')}
        >
          <Select options={allOptions[LlmModelType.Image2text]} allowClear />
        </Form.Item>

        <Form.Item
          label={t('sequence2txtModel')}
          name="asr_id"
          tooltip={t('sequence2txtModelTip')}
        >
          <Select options={allOptions[LlmModelType.Speech2text]} allowClear />
        </Form.Item>
        <Form.Item
          label={t('rerankModel')}
          name="rerank_id"
          tooltip={t('rerankModelTip')}
        >
          <Select options={allOptions[LlmModelType.Rerank]} allowClear />
        </Form.Item>
        <Form.Item
          label={t('ttsModel')}
          name="tts_id"
          tooltip={t('ttsModelTip')}
        >
          <Select options={allOptions[LlmModelType.TTS]} allowClear />
        </Form.Item>
      </Form>
    </Modal>
  );
};

export default SystemModelSettingModal;