2024-03-15 19:35:59 +08:00
|
|
|
import { IModalManagerChildrenProps } from '@/components/modal-manager';
|
2024-03-18 16:45:01 +08:00
|
|
|
import { LlmModelType } from '@/constants/knowledge';
|
2024-07-17 19:07:34 +08:00
|
|
|
import { useTranslate } from '@/hooks/common-hooks';
|
|
|
|
|
import { ISystemModelSettingSavingParams } from '@/hooks/llm-hooks';
|
2024-03-15 19:35:59 +08:00
|
|
|
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();
|
2024-03-18 16:45:01 +08:00
|
|
|
const { systemSetting: initialValues, allOptions } =
|
|
|
|
|
useFetchSystemModelSettingOnMount(visible);
|
2024-04-07 17:41:29 +08:00
|
|
|
const { t } = useTranslate('setting');
|
2024-03-15 19:35:59 +08:00
|
|
|
|
|
|
|
|
const handleOk = async () => {
|
|
|
|
|
const values = await form.validateFields();
|
|
|
|
|
onOk(values);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
2024-04-08 19:13:45 +08:00
|
|
|
if (visible) {
|
|
|
|
|
form.setFieldsValue(initialValues);
|
|
|
|
|
}
|
|
|
|
|
}, [form, initialValues, visible]);
|
2024-03-15 19:35:59 +08:00
|
|
|
|
|
|
|
|
const onFormLayoutChange = () => {};
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<Modal
|
2024-04-07 17:41:29 +08:00
|
|
|
title={t('systemModelSettings')}
|
2024-03-15 19:35:59 +08:00
|
|
|
open={visible}
|
|
|
|
|
onOk={handleOk}
|
|
|
|
|
onCancel={hideModal}
|
|
|
|
|
okButtonProps={{ loading }}
|
|
|
|
|
confirmLoading={loading}
|
|
|
|
|
>
|
|
|
|
|
<Form form={form} onValuesChange={onFormLayoutChange} layout={'vertical'}>
|
2024-04-07 17:41:29 +08:00
|
|
|
<Form.Item
|
|
|
|
|
label={t('chatModel')}
|
|
|
|
|
name="llm_id"
|
|
|
|
|
tooltip={t('chatModelTip')}
|
|
|
|
|
>
|
2024-03-22 15:35:06 +08:00
|
|
|
<Select options={allOptions[LlmModelType.Chat]} />
|
2024-03-15 19:35:59 +08:00
|
|
|
</Form.Item>
|
2024-04-07 17:41:29 +08:00
|
|
|
<Form.Item
|
|
|
|
|
label={t('embeddingModel')}
|
|
|
|
|
name="embd_id"
|
|
|
|
|
tooltip={t('embeddingModelTip')}
|
|
|
|
|
>
|
2024-03-18 16:45:01 +08:00
|
|
|
<Select options={allOptions[LlmModelType.Embedding]} />
|
2024-03-15 19:35:59 +08:00
|
|
|
</Form.Item>
|
2024-03-20 18:20:42 +08:00
|
|
|
<Form.Item
|
2024-04-07 17:41:29 +08:00
|
|
|
label={t('img2txtModel')}
|
2024-03-20 18:20:42 +08:00
|
|
|
name="img2txt_id"
|
2024-04-07 17:41:29 +08:00
|
|
|
tooltip={t('img2txtModelTip')}
|
2024-03-20 18:20:42 +08:00
|
|
|
>
|
2024-03-18 16:45:01 +08:00
|
|
|
<Select options={allOptions[LlmModelType.Image2text]} />
|
2024-03-15 19:35:59 +08:00
|
|
|
</Form.Item>
|
2024-04-07 17:41:29 +08:00
|
|
|
|
2024-03-22 15:35:06 +08:00
|
|
|
<Form.Item
|
2024-04-07 17:41:29 +08:00
|
|
|
label={t('sequence2txtModel')}
|
2024-03-22 15:35:06 +08:00
|
|
|
name="asr_id"
|
2024-04-07 17:41:29 +08:00
|
|
|
tooltip={t('sequence2txtModelTip')}
|
2024-03-22 15:35:06 +08:00
|
|
|
>
|
|
|
|
|
<Select options={allOptions[LlmModelType.Speech2text]} />
|
2024-03-15 19:35:59 +08:00
|
|
|
</Form.Item>
|
2024-05-29 16:19:08 +08:00
|
|
|
<Form.Item
|
|
|
|
|
label={t('rerankModel')}
|
|
|
|
|
name="rerank_id"
|
|
|
|
|
tooltip={t('rerankModelTip')}
|
|
|
|
|
>
|
|
|
|
|
<Select options={allOptions[LlmModelType.Rerank]} />
|
|
|
|
|
</Form.Item>
|
2024-03-15 19:35:59 +08:00
|
|
|
</Form>
|
|
|
|
|
</Modal>
|
|
|
|
|
);
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
export default SystemModelSettingModal;
|