2024-02-18 18:18:20 +08:00
|
|
|
import {
|
|
|
|
useFetchKnowledgeBaseConfiguration,
|
|
|
|
useKnowledgeBaseId,
|
|
|
|
} from '@/hooks/knowledgeHook';
|
2024-03-06 19:17:45 +08:00
|
|
|
import {
|
|
|
|
useFetchTenantInfo,
|
|
|
|
useSelectParserList,
|
|
|
|
} from '@/hooks/userSettingHook';
|
|
|
|
|
2024-02-18 18:18:20 +08:00
|
|
|
import {
|
|
|
|
Button,
|
|
|
|
Divider,
|
|
|
|
Form,
|
|
|
|
Input,
|
|
|
|
Radio,
|
|
|
|
Select,
|
|
|
|
Space,
|
|
|
|
Typography,
|
|
|
|
Upload,
|
|
|
|
UploadFile,
|
|
|
|
} from 'antd';
|
|
|
|
import pick from 'lodash/pick';
|
2024-02-20 18:10:20 +08:00
|
|
|
import { useEffect } from 'react';
|
2024-02-18 18:18:20 +08:00
|
|
|
import { useDispatch, useSelector } from 'umi';
|
|
|
|
|
2024-02-20 18:10:20 +08:00
|
|
|
import { useFetchLlmList, useSelectLlmOptions } from '@/hooks/llmHooks';
|
2024-02-18 18:18:20 +08:00
|
|
|
import { useOneNamespaceEffectsLoading } from '@/hooks/storeHooks';
|
|
|
|
import { IKnowledge } from '@/interfaces/database/knowledge';
|
2024-03-08 17:09:07 +08:00
|
|
|
import {
|
|
|
|
getBase64FromUploadFileList,
|
|
|
|
getUploadFileListFromBase64,
|
|
|
|
normFile,
|
|
|
|
} from '@/utils/fileUtil';
|
2024-02-18 18:18:20 +08:00
|
|
|
import { PlusOutlined } from '@ant-design/icons';
|
2024-02-20 18:10:20 +08:00
|
|
|
import { LlmModelType } from '../../constant';
|
2024-02-18 18:18:20 +08:00
|
|
|
import styles from './index.less';
|
|
|
|
|
|
|
|
const { Title } = Typography;
|
|
|
|
const { Option } = Select;
|
|
|
|
|
|
|
|
const Configuration = () => {
|
|
|
|
const [form] = Form.useForm();
|
|
|
|
const dispatch = useDispatch();
|
|
|
|
const knowledgeBaseId = useKnowledgeBaseId();
|
|
|
|
const loading = useOneNamespaceEffectsLoading('kSModel', ['updateKb']);
|
|
|
|
|
|
|
|
const knowledgeDetails: IKnowledge = useSelector(
|
|
|
|
(state: any) => state.kSModel.knowledgeDetails,
|
|
|
|
);
|
|
|
|
|
|
|
|
const parserList = useSelectParserList();
|
|
|
|
|
2024-02-20 18:10:20 +08:00
|
|
|
const embeddingModelOptions = useSelectLlmOptions();
|
2024-02-18 18:18:20 +08:00
|
|
|
|
|
|
|
const onFinish = async (values: any) => {
|
2024-03-08 17:09:07 +08:00
|
|
|
const avatar = getBase64FromUploadFileList(values.avatar);
|
2024-02-18 18:18:20 +08:00
|
|
|
dispatch({
|
|
|
|
type: 'kSModel/updateKb',
|
|
|
|
payload: {
|
|
|
|
...values,
|
|
|
|
avatar,
|
|
|
|
kb_id: knowledgeBaseId,
|
|
|
|
},
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const onFinishFailed = (errorInfo: any) => {
|
|
|
|
console.log('Failed:', errorInfo);
|
|
|
|
};
|
|
|
|
|
|
|
|
useEffect(() => {
|
2024-03-08 17:09:07 +08:00
|
|
|
const fileList: UploadFile[] = getUploadFileListFromBase64(
|
|
|
|
knowledgeDetails.avatar,
|
|
|
|
);
|
2024-02-18 18:18:20 +08:00
|
|
|
|
|
|
|
form.setFieldsValue({
|
|
|
|
...pick(knowledgeDetails, [
|
|
|
|
'description',
|
|
|
|
'name',
|
|
|
|
'permission',
|
|
|
|
'embd_id',
|
|
|
|
'parser_id',
|
|
|
|
]),
|
|
|
|
avatar: fileList,
|
|
|
|
});
|
|
|
|
}, [form, knowledgeDetails]);
|
|
|
|
|
2024-03-06 19:17:45 +08:00
|
|
|
useFetchTenantInfo();
|
2024-02-18 18:18:20 +08:00
|
|
|
useFetchKnowledgeBaseConfiguration();
|
|
|
|
|
2024-02-20 18:10:20 +08:00
|
|
|
useFetchLlmList(LlmModelType.Embedding);
|
2024-02-18 18:18:20 +08:00
|
|
|
|
|
|
|
return (
|
|
|
|
<div className={styles.configurationWrapper}>
|
|
|
|
<Title level={5}>Configuration</Title>
|
|
|
|
<p>Update your knowledge base details especially parsing method here.</p>
|
|
|
|
<Divider></Divider>
|
|
|
|
<Form
|
|
|
|
form={form}
|
|
|
|
name="validateOnly"
|
|
|
|
layout="vertical"
|
|
|
|
autoComplete="off"
|
|
|
|
onFinish={onFinish}
|
|
|
|
onFinishFailed={onFinishFailed}
|
|
|
|
>
|
|
|
|
<Form.Item
|
|
|
|
name="name"
|
|
|
|
label="Knowledge base name"
|
|
|
|
rules={[{ required: true }]}
|
|
|
|
>
|
|
|
|
<Input />
|
|
|
|
</Form.Item>
|
|
|
|
<Form.Item
|
|
|
|
name="avatar"
|
|
|
|
label="Knowledge base photo"
|
|
|
|
valuePropName="fileList"
|
|
|
|
getValueFromEvent={normFile}
|
|
|
|
>
|
|
|
|
<Upload
|
|
|
|
listType="picture-card"
|
|
|
|
maxCount={1}
|
|
|
|
showUploadList={{ showPreviewIcon: false, showRemoveIcon: false }}
|
|
|
|
>
|
|
|
|
<button style={{ border: 0, background: 'none' }} type="button">
|
|
|
|
<PlusOutlined />
|
|
|
|
<div style={{ marginTop: 8 }}>Upload</div>
|
|
|
|
</button>
|
|
|
|
</Upload>
|
|
|
|
</Form.Item>
|
|
|
|
<Form.Item name="description" label="Knowledge base bio">
|
|
|
|
<Input />
|
|
|
|
</Form.Item>
|
|
|
|
<Form.Item
|
|
|
|
name="permission"
|
|
|
|
label="Permissions"
|
|
|
|
rules={[{ required: true }]}
|
|
|
|
>
|
|
|
|
<Radio.Group>
|
|
|
|
<Radio value="me">Only me</Radio>
|
|
|
|
<Radio value="team">Team</Radio>
|
|
|
|
</Radio.Group>
|
|
|
|
</Form.Item>
|
|
|
|
<Form.Item
|
|
|
|
name="embd_id"
|
|
|
|
label="Embedding Model"
|
|
|
|
rules={[{ required: true }]}
|
|
|
|
>
|
|
|
|
<Select
|
|
|
|
placeholder="Please select a country"
|
|
|
|
options={embeddingModelOptions}
|
|
|
|
></Select>
|
|
|
|
</Form.Item>
|
|
|
|
<Form.Item
|
|
|
|
name="parser_id"
|
|
|
|
label="Knowledge base category"
|
|
|
|
rules={[{ required: true }]}
|
|
|
|
>
|
|
|
|
<Select placeholder="Please select a country">
|
|
|
|
{parserList.map((x) => (
|
|
|
|
<Option value={x.value} key={x.value}>
|
|
|
|
{x.label}
|
|
|
|
</Option>
|
|
|
|
))}
|
|
|
|
</Select>
|
|
|
|
</Form.Item>
|
|
|
|
<Form.Item>
|
|
|
|
<div className={styles.buttonWrapper}>
|
|
|
|
<Space>
|
|
|
|
<Button htmlType="reset" size={'middle'}>
|
|
|
|
Cancel
|
|
|
|
</Button>
|
|
|
|
<Button
|
|
|
|
htmlType="submit"
|
|
|
|
type="primary"
|
|
|
|
size={'middle'}
|
|
|
|
loading={loading}
|
|
|
|
>
|
|
|
|
Save
|
|
|
|
</Button>
|
|
|
|
</Space>
|
|
|
|
</div>
|
|
|
|
</Form.Item>
|
|
|
|
</Form>
|
|
|
|
</div>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
export default Configuration;
|