| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212 |
- import * as React from 'react';
- import { Modal, Spin, Form, Input, Select, message } from 'antd';
- import { apis, CreateOrModifyKnowledgeLibApiParams } from '@/apis';
- const FormItem = Form.Item;
- const { Option } = Select;
- const { TextArea } = Input;
- interface Props {
- id: string,
- open: boolean,
- onClickConfirm: (id: string, data: CreateOrModifyKnowledgeLibApiParams) => Promise<any>,
- onClickCancel: () => void,
- };
- const InfoModal: React.FC<Props> = (props: Props) => {
- const {
- id,
- open,
- onClickConfirm,
- onClickCancel
- } = props;
- const [form] = Form.useForm();
- const [loading, setLoading] = React.useState<boolean>(false);
- type EmbeddingList = {
- label: string,
- value: string,
- }[];
- type AppTypeList = {
- label: string,
- value: string,
- children: {
- label: string,
- value: string,
- }[],
- }[];
- const [embeddingList, setEmbeddingList] = React.useState<EmbeddingList>([]);
- const [appVisibleList, setAppVisibleList] = React.useState<AppTypeList>([]); // 是否公开
- const getTitle = () => {
- if (id) {
- return '修改知识库';
- } else {
- return '创建知识库';
- }
- };
- // 获取向量化模型列表
- const fetchEmbeddingList = async () => {
- try {
- const res = await apis.fetchEmbeddingList();
- const list = res.data.list.map((item: any) => {
- return {
- label: item.name,
- value: item.id,
- }
- });
- setEmbeddingList(list);
- } catch (error: any) {
- console.error(error);
- }
- }
- // 获取知识库详情
- const fetchDetail = async () => {
- try {
- const res = await apis.fetchTakaiKnowledgeLibDetail(props.id);
- const { name, embeddingId, description,visible } = res.data;
- form.setFieldsValue({
- name: name,
- embeddingId: embeddingId,
- description: description,
- visible: visible, // 是否公开
- });
- } catch (error: any) {
- message.error(error.msg);
- }
- };
- // 获取是否公开类型
- const fetchAppVisible = async (id: string) => {
- try {
- const res = await apis.fetchTakaiAppTypeList('app_visible');
- console.log('res.data', res.data)
- const list = res.data.map((item: any) => {
- return {
- label: item.dictLabel,
- value: item.dictValue,
- }
- });
- setAppVisibleList(list);
- if (!id) {
- form.setFieldsValue({
- visible: list[0]?.value
- });
- }
- } catch (error: any) {
- console.error(error);
- }
- }
- const init = async () => {
- setLoading(true);
- // await fetchEmbeddingList();
- if (props.id) {
- await fetchDetail();
- }
- await fetchAppVisible(props.id);
- setLoading(false);
- };
- React.useEffect(() => {
- init();
- }, []);
- // 点击确定
- const handleClickConfirm = () => {
- form.validateFields().then(async (values) => {
- const data = { ...values };
- await onClickConfirm(props.id, data);
- }).catch((error) => {
- console.error(error);
- });
- };
- return (
- <Modal
- width={500}
- title={getTitle()}
- destroyOnClose={true}
- maskClosable={false}
- centered={true}
- open={open}
- onOk={handleClickConfirm}
- onCancel={onClickCancel}
- >
- <Spin spinning={loading}>
- <Form form={form} layout='vertical'>
- <FormItem
- label='知识库名称'
- name='name'
- rules={[{ required: true, message: '知识库名称不能为空', whitespace: true }]}
- >
- <Input placeholder='请输入知识库名称' />
- </FormItem>
- <FormItem
- label='向量化模型'
- name='embeddingId'
- rules={[{ required: true, message: '向量化模型不能为空' }]}
- >
- {
- getTitle() === '创建知识库' &&
- <Select
- style={{ width: '100%' }}
- placeholder='请选择向量化模型'
- allowClear={true}
- >
- <Option value='multilingual-e5-large-instruct'>multilingual-e5-large-instruct</Option>
- </Select>
- }
- {
- getTitle() === '修改知识库' &&
- <Select
- style={{ width: '100%' }}
- placeholder='请选择向量化模型'
- allowClear={true}
- disabled={true}
- >
- <Option value='multilingual-e5-large-instruct'>multilingual-e5-large-instruct</Option>
- </Select>
- }
- </FormItem>
- <FormItem
- label='是否公开'
- name='visible'
- >
- <Select
- placeholder='请选择是否公开'
- allowClear={true}
- >
- {
- appVisibleList.map((item, index) => {
- return <Option value={item.value} key={index}>
- {item.label}
- </Option>
- })
- }
- </Select>
- </FormItem>
- <FormItem
- label='知识库描述'
- name='description'
- rules={[{ required: true, message: '知识库描述不能为空', whitespace: true }]}
- >
- <TextArea
- placeholder='知识库描述需要描述清楚知识库中的文件内容,搭建应用时模型会将此作为判断是否获取知识库内容的依据'
- showCount={true}
- rows={4}
- maxLength={100}
- />
- </FormItem>
- <div style={{ width: '100%', height: 10 }}></div>
- </Form>
- </Spin>
- </Modal>
- );
- };
- export default InfoModal;
|