balibabu
commited on
Commit
·
8ef29dd
1
Parent(s):
5bd5c21
fix: use @tanstack/react-query to get knowledge base data #1306 (#1609)
Browse files### What problem does this PR solve?
fix: use @tanstack/react-query to get knowledge base data #1306
### Type of change
- [x] Bug Fix (non-breaking change which fixes an issue)
- web/src/hooks/knowledge-hooks.ts +30 -66
- web/src/pages/add-knowledge/components/knowledge-dataset/knowledge-upload-file/index.less +0 -86
- web/src/pages/add-knowledge/components/knowledge-dataset/knowledge-upload-file/index.tsx +0 -310
- web/src/pages/add-knowledge/components/knowledge-setting/hooks.ts +11 -13
- web/src/pages/add-knowledge/components/knowledge-setting/model.ts +0 -49
- web/src/pages/add-knowledge/components/knowledge-sidebar/index.tsx +2 -6
- web/src/pages/knowledge/model.ts +0 -63
- web/src/routes.ts +0 -5
- web/typings.d.ts +35 -39
web/src/hooks/knowledge-hooks.ts
CHANGED
|
@@ -6,7 +6,6 @@ import { useMutation, useQuery, useQueryClient } from '@tanstack/react-query';
|
|
| 6 |
import { message } from 'antd';
|
| 7 |
import { useCallback, useEffect } from 'react';
|
| 8 |
import { useDispatch, useSearchParams, useSelector } from 'umi';
|
| 9 |
-
import { useGetKnowledgeSearchParams } from './route-hook';
|
| 10 |
|
| 11 |
export const useKnowledgeBaseId = (): string => {
|
| 12 |
const [searchParams] = useSearchParams();
|
|
@@ -41,44 +40,6 @@ export const useDeleteDocumentById = (): {
|
|
| 41 |
};
|
| 42 |
};
|
| 43 |
|
| 44 |
-
export const useFetchKnowledgeDetail = () => {
|
| 45 |
-
const dispatch = useDispatch();
|
| 46 |
-
const { knowledgeId } = useGetKnowledgeSearchParams();
|
| 47 |
-
|
| 48 |
-
const fetchKnowledgeDetail = useCallback(
|
| 49 |
-
(knowledgeId: string) => {
|
| 50 |
-
dispatch({
|
| 51 |
-
type: 'knowledgeModel/getKnowledgeDetail',
|
| 52 |
-
payload: { kb_id: knowledgeId },
|
| 53 |
-
});
|
| 54 |
-
},
|
| 55 |
-
[dispatch],
|
| 56 |
-
);
|
| 57 |
-
|
| 58 |
-
useEffect(() => {
|
| 59 |
-
fetchKnowledgeDetail(knowledgeId);
|
| 60 |
-
}, [fetchKnowledgeDetail, knowledgeId]);
|
| 61 |
-
|
| 62 |
-
return fetchKnowledgeDetail;
|
| 63 |
-
};
|
| 64 |
-
|
| 65 |
-
export const useSelectKnowledgeDetail = () => {
|
| 66 |
-
const knowledge: IKnowledge = useSelector(
|
| 67 |
-
(state: any) => state.knowledgeModel.knowledge,
|
| 68 |
-
);
|
| 69 |
-
|
| 70 |
-
return knowledge;
|
| 71 |
-
};
|
| 72 |
-
|
| 73 |
-
export const useGetDocumentDefaultParser = () => {
|
| 74 |
-
const item = useSelectKnowledgeDetail();
|
| 75 |
-
|
| 76 |
-
return {
|
| 77 |
-
defaultParserId: item?.parser_id ?? '',
|
| 78 |
-
parserConfig: item?.parser_config ?? '',
|
| 79 |
-
};
|
| 80 |
-
};
|
| 81 |
-
|
| 82 |
export const useDeleteChunkByIds = (): {
|
| 83 |
removeChunk: (chunkIds: string[], documentId: string) => Promise<number>;
|
| 84 |
} => {
|
|
@@ -111,21 +72,21 @@ export const useDeleteChunkByIds = (): {
|
|
| 111 |
};
|
| 112 |
|
| 113 |
export const useFetchKnowledgeBaseConfiguration = () => {
|
| 114 |
-
const dispatch = useDispatch();
|
| 115 |
const knowledgeBaseId = useKnowledgeBaseId();
|
| 116 |
|
| 117 |
-
const
|
| 118 |
-
|
| 119 |
-
|
| 120 |
-
|
|
|
|
|
|
|
| 121 |
kb_id: knowledgeBaseId,
|
| 122 |
-
}
|
| 123 |
-
|
| 124 |
-
|
|
|
|
| 125 |
|
| 126 |
-
|
| 127 |
-
fetchKnowledgeBaseConfiguration();
|
| 128 |
-
}, [fetchKnowledgeBaseConfiguration]);
|
| 129 |
};
|
| 130 |
|
| 131 |
export const useNextFetchKnowledgeList = (
|
|
@@ -228,27 +189,30 @@ export const useFetchFileThumbnails = (docIds?: Array<string>) => {
|
|
| 228 |
//#region knowledge configuration
|
| 229 |
|
| 230 |
export const useUpdateKnowledge = () => {
|
| 231 |
-
const
|
| 232 |
-
|
| 233 |
-
const
|
| 234 |
-
|
| 235 |
-
|
| 236 |
-
|
| 237 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 238 |
});
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 239 |
},
|
| 240 |
-
|
| 241 |
-
);
|
| 242 |
|
| 243 |
-
return saveKnowledgeConfiguration;
|
| 244 |
};
|
| 245 |
|
| 246 |
-
export const useSelectKnowledgeDetails = () => {
|
| 247 |
-
const knowledgeDetails: IKnowledge = useSelector(
|
| 248 |
-
(state: any) => state.kSModel.knowledgeDetails,
|
| 249 |
-
);
|
| 250 |
-
return knowledgeDetails;
|
| 251 |
-
};
|
| 252 |
//#endregion
|
| 253 |
|
| 254 |
//#region Retrieval testing
|
|
|
|
| 6 |
import { message } from 'antd';
|
| 7 |
import { useCallback, useEffect } from 'react';
|
| 8 |
import { useDispatch, useSearchParams, useSelector } from 'umi';
|
|
|
|
| 9 |
|
| 10 |
export const useKnowledgeBaseId = (): string => {
|
| 11 |
const [searchParams] = useSearchParams();
|
|
|
|
| 40 |
};
|
| 41 |
};
|
| 42 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 43 |
export const useDeleteChunkByIds = (): {
|
| 44 |
removeChunk: (chunkIds: string[], documentId: string) => Promise<number>;
|
| 45 |
} => {
|
|
|
|
| 72 |
};
|
| 73 |
|
| 74 |
export const useFetchKnowledgeBaseConfiguration = () => {
|
|
|
|
| 75 |
const knowledgeBaseId = useKnowledgeBaseId();
|
| 76 |
|
| 77 |
+
const { data, isFetching: loading } = useQuery({
|
| 78 |
+
queryKey: ['fetchKnowledgeDetail'],
|
| 79 |
+
initialData: {},
|
| 80 |
+
gcTime: 0,
|
| 81 |
+
queryFn: async () => {
|
| 82 |
+
const { data } = await kbService.get_kb_detail({
|
| 83 |
kb_id: knowledgeBaseId,
|
| 84 |
+
});
|
| 85 |
+
return data?.data ?? {};
|
| 86 |
+
},
|
| 87 |
+
});
|
| 88 |
|
| 89 |
+
return { data, loading };
|
|
|
|
|
|
|
| 90 |
};
|
| 91 |
|
| 92 |
export const useNextFetchKnowledgeList = (
|
|
|
|
| 189 |
//#region knowledge configuration
|
| 190 |
|
| 191 |
export const useUpdateKnowledge = () => {
|
| 192 |
+
const knowledgeBaseId = useKnowledgeBaseId();
|
| 193 |
+
const queryClient = useQueryClient();
|
| 194 |
+
const {
|
| 195 |
+
data,
|
| 196 |
+
isPending: loading,
|
| 197 |
+
mutateAsync,
|
| 198 |
+
} = useMutation({
|
| 199 |
+
mutationKey: ['saveKnowledge'],
|
| 200 |
+
mutationFn: async (params: Record<string, any>) => {
|
| 201 |
+
const { data = {} } = await kbService.updateKb({
|
| 202 |
+
kb_id: knowledgeBaseId,
|
| 203 |
+
...params,
|
| 204 |
});
|
| 205 |
+
if (data.retcode === 0) {
|
| 206 |
+
message.success(i18n.t(`message.updated`));
|
| 207 |
+
queryClient.invalidateQueries({ queryKey: ['fetchKnowledgeDetail'] });
|
| 208 |
+
}
|
| 209 |
+
return data;
|
| 210 |
},
|
| 211 |
+
});
|
|
|
|
| 212 |
|
| 213 |
+
return { data, loading, saveKnowledgeConfiguration: mutateAsync };
|
| 214 |
};
|
| 215 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 216 |
//#endregion
|
| 217 |
|
| 218 |
//#region Retrieval testing
|
web/src/pages/add-knowledge/components/knowledge-dataset/knowledge-upload-file/index.less
DELETED
|
@@ -1,86 +0,0 @@
|
|
| 1 |
-
.uploadWrapper {
|
| 2 |
-
display: flex;
|
| 3 |
-
flex-direction: column;
|
| 4 |
-
padding: 64px 32px 32px;
|
| 5 |
-
height: 100%;
|
| 6 |
-
.backToList {
|
| 7 |
-
display: none;
|
| 8 |
-
padding-bottom: 60px;
|
| 9 |
-
}
|
| 10 |
-
.footer {
|
| 11 |
-
text-align: center;
|
| 12 |
-
padding-top: 16px;
|
| 13 |
-
.nextButton {
|
| 14 |
-
// background-color: @purple;
|
| 15 |
-
font-weight: 700;
|
| 16 |
-
font-size: 24px;
|
| 17 |
-
display: inline-flex;
|
| 18 |
-
align-items: center;
|
| 19 |
-
padding: 26px 40px;
|
| 20 |
-
justify-content: center;
|
| 21 |
-
width: 10%;
|
| 22 |
-
}
|
| 23 |
-
}
|
| 24 |
-
.uploadContent {
|
| 25 |
-
flex: 1;
|
| 26 |
-
padding-top: 60px;
|
| 27 |
-
}
|
| 28 |
-
.uploader {
|
| 29 |
-
:global(.ant-upload) {
|
| 30 |
-
height: 126px;
|
| 31 |
-
}
|
| 32 |
-
}
|
| 33 |
-
.hiddenUploader {
|
| 34 |
-
:global(.ant-upload-drag) {
|
| 35 |
-
display: none;
|
| 36 |
-
}
|
| 37 |
-
}
|
| 38 |
-
.fileIcon {
|
| 39 |
-
font-size: 40px;
|
| 40 |
-
align-items: end;
|
| 41 |
-
}
|
| 42 |
-
.uploaderButton {
|
| 43 |
-
padding: 10px;
|
| 44 |
-
vertical-align: middle;
|
| 45 |
-
height: 40px;
|
| 46 |
-
}
|
| 47 |
-
.uploaderIcon {
|
| 48 |
-
svg {
|
| 49 |
-
width: 20px;
|
| 50 |
-
height: 20px;
|
| 51 |
-
}
|
| 52 |
-
}
|
| 53 |
-
.deleteIcon {
|
| 54 |
-
font-size: 20px;
|
| 55 |
-
}
|
| 56 |
-
.uploaderItem {
|
| 57 |
-
margin-top: 16px;
|
| 58 |
-
:global(.ant-card-body) {
|
| 59 |
-
padding: 16px;
|
| 60 |
-
}
|
| 61 |
-
}
|
| 62 |
-
.uploaderItemProgress {
|
| 63 |
-
padding-left: 50px;
|
| 64 |
-
}
|
| 65 |
-
.uploaderItemTextWrapper {
|
| 66 |
-
flex: 1;
|
| 67 |
-
text-align: left;
|
| 68 |
-
padding-left: 10px;
|
| 69 |
-
}
|
| 70 |
-
}
|
| 71 |
-
|
| 72 |
-
.progressWrapper {
|
| 73 |
-
text-align: center;
|
| 74 |
-
}
|
| 75 |
-
|
| 76 |
-
.progress {
|
| 77 |
-
width: 50%;
|
| 78 |
-
margin: 0;
|
| 79 |
-
}
|
| 80 |
-
|
| 81 |
-
.selectFilesText {
|
| 82 |
-
transform: translateX(10%);
|
| 83 |
-
}
|
| 84 |
-
.changeSpecificCategoryText {
|
| 85 |
-
transform: translateX(30%);
|
| 86 |
-
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
web/src/pages/add-knowledge/components/knowledge-dataset/knowledge-upload-file/index.tsx
DELETED
|
@@ -1,310 +0,0 @@
|
|
| 1 |
-
import { ReactComponent as SelectFilesEndIcon } from '@/assets/svg/select-files-end.svg';
|
| 2 |
-
import { ReactComponent as SelectFilesStartIcon } from '@/assets/svg/select-files-start.svg';
|
| 3 |
-
import ChunkMethodModal from '@/components/chunk-method-modal';
|
| 4 |
-
import { KnowledgeRouteKey } from '@/constants/knowledge';
|
| 5 |
-
import {
|
| 6 |
-
useRunDocument,
|
| 7 |
-
useSelectDocumentList,
|
| 8 |
-
useUploadDocument,
|
| 9 |
-
} from '@/hooks/document-hooks';
|
| 10 |
-
import {
|
| 11 |
-
useDeleteDocumentById,
|
| 12 |
-
useFetchKnowledgeDetail,
|
| 13 |
-
useKnowledgeBaseId,
|
| 14 |
-
} from '@/hooks/knowledge-hooks';
|
| 15 |
-
import {
|
| 16 |
-
useChangeDocumentParser,
|
| 17 |
-
useSetSelectedRecord,
|
| 18 |
-
} from '@/hooks/logic-hooks';
|
| 19 |
-
import { useFetchTenantInfo } from '@/hooks/user-setting-hooks';
|
| 20 |
-
import { IKnowledgeFile } from '@/interfaces/database/knowledge';
|
| 21 |
-
import { getExtension, isFileUploadDone } from '@/utils/documentUtils';
|
| 22 |
-
import {
|
| 23 |
-
ArrowLeftOutlined,
|
| 24 |
-
CloudUploadOutlined,
|
| 25 |
-
DeleteOutlined,
|
| 26 |
-
EditOutlined,
|
| 27 |
-
FileDoneOutlined,
|
| 28 |
-
} from '@ant-design/icons';
|
| 29 |
-
import {
|
| 30 |
-
Button,
|
| 31 |
-
Card,
|
| 32 |
-
Flex,
|
| 33 |
-
Progress,
|
| 34 |
-
Space,
|
| 35 |
-
Upload,
|
| 36 |
-
UploadFile,
|
| 37 |
-
UploadProps,
|
| 38 |
-
} from 'antd';
|
| 39 |
-
import classNames from 'classnames';
|
| 40 |
-
import { ReactElement, useCallback, useMemo, useRef, useState } from 'react';
|
| 41 |
-
import { Link, useNavigate } from 'umi';
|
| 42 |
-
|
| 43 |
-
import { useTranslate } from '@/hooks/common-hooks';
|
| 44 |
-
import styles from './index.less';
|
| 45 |
-
|
| 46 |
-
const { Dragger } = Upload;
|
| 47 |
-
|
| 48 |
-
type UploadRequestOption = Parameters<
|
| 49 |
-
NonNullable<UploadProps['customRequest']>
|
| 50 |
-
>[0];
|
| 51 |
-
|
| 52 |
-
const UploaderItem = ({
|
| 53 |
-
file,
|
| 54 |
-
isUpload,
|
| 55 |
-
remove,
|
| 56 |
-
handleEdit,
|
| 57 |
-
}: {
|
| 58 |
-
isUpload: boolean;
|
| 59 |
-
originNode: ReactElement;
|
| 60 |
-
file: UploadFile;
|
| 61 |
-
fileList: object[];
|
| 62 |
-
showModal: () => void;
|
| 63 |
-
remove: (id: string) => void;
|
| 64 |
-
setRecord: (record: IKnowledgeFile) => void;
|
| 65 |
-
handleEdit: (id: string) => void;
|
| 66 |
-
}) => {
|
| 67 |
-
const { removeDocument } = useDeleteDocumentById();
|
| 68 |
-
|
| 69 |
-
const documentId = file?.response?.id;
|
| 70 |
-
|
| 71 |
-
const handleRemove = async () => {
|
| 72 |
-
if (file.status === 'error') {
|
| 73 |
-
remove(documentId);
|
| 74 |
-
} else {
|
| 75 |
-
const ret: any = await removeDocument(documentId);
|
| 76 |
-
if (ret === 0) {
|
| 77 |
-
remove(documentId);
|
| 78 |
-
}
|
| 79 |
-
}
|
| 80 |
-
};
|
| 81 |
-
|
| 82 |
-
const handleEditClick = () => {
|
| 83 |
-
if (file.status === 'done') {
|
| 84 |
-
handleEdit(documentId);
|
| 85 |
-
}
|
| 86 |
-
};
|
| 87 |
-
|
| 88 |
-
return (
|
| 89 |
-
<Card className={styles.uploaderItem}>
|
| 90 |
-
<Flex justify="space-between">
|
| 91 |
-
<FileDoneOutlined className={styles.fileIcon} />
|
| 92 |
-
<section className={styles.uploaderItemTextWrapper}>
|
| 93 |
-
<div>
|
| 94 |
-
<b>{file.name}</b>
|
| 95 |
-
</div>
|
| 96 |
-
<span>{file.size}</span>
|
| 97 |
-
</section>
|
| 98 |
-
{isUpload ? (
|
| 99 |
-
<DeleteOutlined
|
| 100 |
-
className={styles.deleteIcon}
|
| 101 |
-
onClick={handleRemove}
|
| 102 |
-
/>
|
| 103 |
-
) : (
|
| 104 |
-
<EditOutlined onClick={handleEditClick} />
|
| 105 |
-
)}
|
| 106 |
-
</Flex>
|
| 107 |
-
<Flex>
|
| 108 |
-
<Progress
|
| 109 |
-
showInfo={false}
|
| 110 |
-
percent={100}
|
| 111 |
-
className={styles.uploaderItemProgress}
|
| 112 |
-
strokeColor="
|
| 113 |
-
rgba(127, 86, 217, 1)
|
| 114 |
-
"
|
| 115 |
-
/>
|
| 116 |
-
<span>100%</span>
|
| 117 |
-
</Flex>
|
| 118 |
-
</Card>
|
| 119 |
-
);
|
| 120 |
-
};
|
| 121 |
-
|
| 122 |
-
const KnowledgeUploadFile = () => {
|
| 123 |
-
const knowledgeBaseId = useKnowledgeBaseId();
|
| 124 |
-
const [isUpload, setIsUpload] = useState(true);
|
| 125 |
-
const [uploadedFileIds, setUploadedFileIds] = useState<string[]>([]);
|
| 126 |
-
const fileListRef = useRef<UploadFile[]>([]);
|
| 127 |
-
const navigate = useNavigate();
|
| 128 |
-
const { currentRecord, setRecord } = useSetSelectedRecord();
|
| 129 |
-
const {
|
| 130 |
-
changeParserLoading,
|
| 131 |
-
onChangeParserOk,
|
| 132 |
-
changeParserVisible,
|
| 133 |
-
hideChangeParserModal,
|
| 134 |
-
showChangeParserModal,
|
| 135 |
-
} = useChangeDocumentParser(currentRecord.id);
|
| 136 |
-
const documentList = useSelectDocumentList();
|
| 137 |
-
const runDocumentByIds = useRunDocument();
|
| 138 |
-
const uploadDocument = useUploadDocument();
|
| 139 |
-
const { t } = useTranslate('knowledgeDetails');
|
| 140 |
-
|
| 141 |
-
const enabled = useMemo(() => {
|
| 142 |
-
if (isUpload) {
|
| 143 |
-
return (
|
| 144 |
-
uploadedFileIds.length > 0 &&
|
| 145 |
-
fileListRef.current.filter((x) => isFileUploadDone(x)).length ===
|
| 146 |
-
uploadedFileIds.length
|
| 147 |
-
);
|
| 148 |
-
}
|
| 149 |
-
return true;
|
| 150 |
-
}, [uploadedFileIds, isUpload]);
|
| 151 |
-
|
| 152 |
-
const createRequest: (props: UploadRequestOption) => void = async function ({
|
| 153 |
-
file,
|
| 154 |
-
onSuccess,
|
| 155 |
-
onError,
|
| 156 |
-
// onProgress,
|
| 157 |
-
}) {
|
| 158 |
-
const data = await uploadDocument(file as UploadFile);
|
| 159 |
-
if (data?.retcode === 0) {
|
| 160 |
-
setUploadedFileIds((pre) => {
|
| 161 |
-
return pre.concat(data.data.id);
|
| 162 |
-
});
|
| 163 |
-
if (onSuccess) {
|
| 164 |
-
onSuccess(data.data);
|
| 165 |
-
}
|
| 166 |
-
} else {
|
| 167 |
-
if (onError) {
|
| 168 |
-
onError(data?.data);
|
| 169 |
-
}
|
| 170 |
-
}
|
| 171 |
-
};
|
| 172 |
-
|
| 173 |
-
const removeIdFromUploadedIds = useCallback((id: string) => {
|
| 174 |
-
setUploadedFileIds((pre) => {
|
| 175 |
-
return pre.filter((x) => x !== id);
|
| 176 |
-
});
|
| 177 |
-
}, []);
|
| 178 |
-
|
| 179 |
-
const handleItemEdit = useCallback(
|
| 180 |
-
(id: string) => {
|
| 181 |
-
const document = documentList.find((x) => x.id === id);
|
| 182 |
-
if (document) {
|
| 183 |
-
setRecord(document);
|
| 184 |
-
}
|
| 185 |
-
showChangeParserModal();
|
| 186 |
-
},
|
| 187 |
-
[documentList, showChangeParserModal, setRecord],
|
| 188 |
-
);
|
| 189 |
-
|
| 190 |
-
const props: UploadProps = {
|
| 191 |
-
name: 'file',
|
| 192 |
-
multiple: true,
|
| 193 |
-
itemRender(originNode, file, fileList, actions) {
|
| 194 |
-
fileListRef.current = fileList;
|
| 195 |
-
const remove = (id: string) => {
|
| 196 |
-
if (isFileUploadDone(file)) {
|
| 197 |
-
removeIdFromUploadedIds(id);
|
| 198 |
-
}
|
| 199 |
-
actions.remove();
|
| 200 |
-
};
|
| 201 |
-
return (
|
| 202 |
-
<UploaderItem
|
| 203 |
-
isUpload={isUpload}
|
| 204 |
-
file={file}
|
| 205 |
-
fileList={fileList}
|
| 206 |
-
originNode={originNode}
|
| 207 |
-
remove={remove}
|
| 208 |
-
showModal={showChangeParserModal}
|
| 209 |
-
setRecord={setRecord}
|
| 210 |
-
handleEdit={handleItemEdit}
|
| 211 |
-
></UploaderItem>
|
| 212 |
-
);
|
| 213 |
-
},
|
| 214 |
-
customRequest: createRequest,
|
| 215 |
-
onDrop(e) {
|
| 216 |
-
console.log('Dropped files', e.dataTransfer.files);
|
| 217 |
-
},
|
| 218 |
-
};
|
| 219 |
-
|
| 220 |
-
const runSelectedDocument = () => {
|
| 221 |
-
const ids = fileListRef.current.map((x) => x.response.id);
|
| 222 |
-
runDocumentByIds({ doc_ids: ids, run: 1 });
|
| 223 |
-
};
|
| 224 |
-
|
| 225 |
-
const handleNextClick = () => {
|
| 226 |
-
if (!isUpload) {
|
| 227 |
-
runSelectedDocument();
|
| 228 |
-
navigate(`/knowledge/${KnowledgeRouteKey.Dataset}?id=${knowledgeBaseId}`);
|
| 229 |
-
} else {
|
| 230 |
-
setIsUpload(false);
|
| 231 |
-
}
|
| 232 |
-
};
|
| 233 |
-
|
| 234 |
-
useFetchTenantInfo();
|
| 235 |
-
useFetchKnowledgeDetail();
|
| 236 |
-
|
| 237 |
-
return (
|
| 238 |
-
<>
|
| 239 |
-
<div className={styles.uploadWrapper}>
|
| 240 |
-
<section>
|
| 241 |
-
<Space className={styles.backToList}>
|
| 242 |
-
<ArrowLeftOutlined />
|
| 243 |
-
<Link to={`/knowledge/dataset?id=${knowledgeBaseId}`}>
|
| 244 |
-
Back to select files
|
| 245 |
-
</Link>
|
| 246 |
-
</Space>
|
| 247 |
-
<div className={styles.progressWrapper}>
|
| 248 |
-
<Flex align="center" justify="center">
|
| 249 |
-
<SelectFilesStartIcon></SelectFilesStartIcon>
|
| 250 |
-
<Progress
|
| 251 |
-
percent={100}
|
| 252 |
-
showInfo={false}
|
| 253 |
-
className={styles.progress}
|
| 254 |
-
strokeColor="
|
| 255 |
-
rgba(127, 86, 217, 1)
|
| 256 |
-
"
|
| 257 |
-
/>
|
| 258 |
-
<SelectFilesEndIcon></SelectFilesEndIcon>
|
| 259 |
-
</Flex>
|
| 260 |
-
<Flex justify="space-around">
|
| 261 |
-
<p className={styles.selectFilesText}>
|
| 262 |
-
<b>{t('selectFiles')}</b>
|
| 263 |
-
</p>
|
| 264 |
-
<p className={styles.changeSpecificCategoryText}>
|
| 265 |
-
<b>{t('changeSpecificCategory')}</b>
|
| 266 |
-
</p>
|
| 267 |
-
</Flex>
|
| 268 |
-
</div>
|
| 269 |
-
</section>
|
| 270 |
-
<section className={styles.uploadContent}>
|
| 271 |
-
<Dragger
|
| 272 |
-
{...props}
|
| 273 |
-
className={classNames(styles.uploader, {
|
| 274 |
-
[styles.hiddenUploader]: !isUpload,
|
| 275 |
-
})}
|
| 276 |
-
>
|
| 277 |
-
<Button className={styles.uploaderButton}>
|
| 278 |
-
<CloudUploadOutlined className={styles.uploaderIcon} />
|
| 279 |
-
</Button>
|
| 280 |
-
<p className="ant-upload-text">{t('uploadTitle')}</p>
|
| 281 |
-
<p className="ant-upload-hint">{t('uploadDescription')}</p>
|
| 282 |
-
</Dragger>
|
| 283 |
-
</section>
|
| 284 |
-
<section className={styles.footer}>
|
| 285 |
-
<Button
|
| 286 |
-
type="primary"
|
| 287 |
-
className={styles.nextButton}
|
| 288 |
-
onClick={handleNextClick}
|
| 289 |
-
disabled={!enabled}
|
| 290 |
-
size="large"
|
| 291 |
-
>
|
| 292 |
-
{t('next', { keyPrefix: 'common' })}
|
| 293 |
-
</Button>
|
| 294 |
-
</section>
|
| 295 |
-
</div>
|
| 296 |
-
<ChunkMethodModal
|
| 297 |
-
documentId={currentRecord.id}
|
| 298 |
-
parserId={currentRecord.parser_id}
|
| 299 |
-
parserConfig={currentRecord.parser_config}
|
| 300 |
-
documentExtension={getExtension(currentRecord.name)}
|
| 301 |
-
onOk={onChangeParserOk}
|
| 302 |
-
visible={changeParserVisible}
|
| 303 |
-
hideModal={hideChangeParserModal}
|
| 304 |
-
loading={changeParserLoading}
|
| 305 |
-
/>
|
| 306 |
-
</>
|
| 307 |
-
);
|
| 308 |
-
};
|
| 309 |
-
|
| 310 |
-
export default KnowledgeUploadFile;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
web/src/pages/add-knowledge/components/knowledge-setting/hooks.ts
CHANGED
|
@@ -1,12 +1,9 @@
|
|
| 1 |
import {
|
| 2 |
useFetchKnowledgeBaseConfiguration,
|
| 3 |
-
useKnowledgeBaseId,
|
| 4 |
-
useSelectKnowledgeDetails,
|
| 5 |
useUpdateKnowledge,
|
| 6 |
} from '@/hooks/knowledge-hooks';
|
| 7 |
import { useFetchLlmList, useSelectLlmOptions } from '@/hooks/llm-hooks';
|
| 8 |
import { useNavigateToDataset } from '@/hooks/route-hook';
|
| 9 |
-
import { useOneNamespaceEffectsLoading } from '@/hooks/store-hooks';
|
| 10 |
import {
|
| 11 |
useFetchTenantInfo,
|
| 12 |
useSelectParserList,
|
|
@@ -15,6 +12,7 @@ import {
|
|
| 15 |
getBase64FromUploadFileList,
|
| 16 |
getUploadFileListFromBase64,
|
| 17 |
} from '@/utils/fileUtil';
|
|
|
|
| 18 |
import { Form, UploadFile } from 'antd';
|
| 19 |
import { FormInstance } from 'antd/lib';
|
| 20 |
import pick from 'lodash/pick';
|
|
@@ -22,32 +20,32 @@ import { useCallback, useEffect } from 'react';
|
|
| 22 |
import { LlmModelType } from '../../constant';
|
| 23 |
|
| 24 |
export const useSubmitKnowledgeConfiguration = (form: FormInstance) => {
|
| 25 |
-
const
|
| 26 |
-
const knowledgeBaseId = useKnowledgeBaseId();
|
| 27 |
-
const submitLoading = useOneNamespaceEffectsLoading('kSModel', ['updateKb']);
|
| 28 |
const navigateToDataset = useNavigateToDataset();
|
| 29 |
|
| 30 |
const submitKnowledgeConfiguration = useCallback(async () => {
|
| 31 |
const values = await form.validateFields();
|
| 32 |
const avatar = await getBase64FromUploadFileList(values.avatar);
|
| 33 |
-
|
| 34 |
...values,
|
| 35 |
avatar,
|
| 36 |
-
kb_id: knowledgeBaseId,
|
| 37 |
});
|
| 38 |
navigateToDataset();
|
| 39 |
-
}, [
|
| 40 |
|
| 41 |
-
return {
|
|
|
|
|
|
|
|
|
|
|
|
|
| 42 |
};
|
| 43 |
|
| 44 |
export const useFetchKnowledgeConfigurationOnMount = (form: FormInstance) => {
|
| 45 |
-
const knowledgeDetails = useSelectKnowledgeDetails();
|
| 46 |
const parserList = useSelectParserList();
|
| 47 |
const embeddingModelOptions = useSelectLlmOptions();
|
| 48 |
|
| 49 |
useFetchTenantInfo();
|
| 50 |
-
useFetchKnowledgeBaseConfiguration();
|
| 51 |
useFetchLlmList(LlmModelType.Embedding);
|
| 52 |
|
| 53 |
useEffect(() => {
|
|
@@ -76,7 +74,7 @@ export const useFetchKnowledgeConfigurationOnMount = (form: FormInstance) => {
|
|
| 76 |
};
|
| 77 |
|
| 78 |
export const useSelectKnowledgeDetailsLoading = () =>
|
| 79 |
-
|
| 80 |
|
| 81 |
export const useHandleChunkMethodChange = () => {
|
| 82 |
const [form] = Form.useForm();
|
|
|
|
| 1 |
import {
|
| 2 |
useFetchKnowledgeBaseConfiguration,
|
|
|
|
|
|
|
| 3 |
useUpdateKnowledge,
|
| 4 |
} from '@/hooks/knowledge-hooks';
|
| 5 |
import { useFetchLlmList, useSelectLlmOptions } from '@/hooks/llm-hooks';
|
| 6 |
import { useNavigateToDataset } from '@/hooks/route-hook';
|
|
|
|
| 7 |
import {
|
| 8 |
useFetchTenantInfo,
|
| 9 |
useSelectParserList,
|
|
|
|
| 12 |
getBase64FromUploadFileList,
|
| 13 |
getUploadFileListFromBase64,
|
| 14 |
} from '@/utils/fileUtil';
|
| 15 |
+
import { useIsFetching } from '@tanstack/react-query';
|
| 16 |
import { Form, UploadFile } from 'antd';
|
| 17 |
import { FormInstance } from 'antd/lib';
|
| 18 |
import pick from 'lodash/pick';
|
|
|
|
| 20 |
import { LlmModelType } from '../../constant';
|
| 21 |
|
| 22 |
export const useSubmitKnowledgeConfiguration = (form: FormInstance) => {
|
| 23 |
+
const { saveKnowledgeConfiguration, loading } = useUpdateKnowledge();
|
|
|
|
|
|
|
| 24 |
const navigateToDataset = useNavigateToDataset();
|
| 25 |
|
| 26 |
const submitKnowledgeConfiguration = useCallback(async () => {
|
| 27 |
const values = await form.validateFields();
|
| 28 |
const avatar = await getBase64FromUploadFileList(values.avatar);
|
| 29 |
+
saveKnowledgeConfiguration({
|
| 30 |
...values,
|
| 31 |
avatar,
|
|
|
|
| 32 |
});
|
| 33 |
navigateToDataset();
|
| 34 |
+
}, [saveKnowledgeConfiguration, form, navigateToDataset]);
|
| 35 |
|
| 36 |
+
return {
|
| 37 |
+
submitKnowledgeConfiguration,
|
| 38 |
+
submitLoading: loading,
|
| 39 |
+
navigateToDataset,
|
| 40 |
+
};
|
| 41 |
};
|
| 42 |
|
| 43 |
export const useFetchKnowledgeConfigurationOnMount = (form: FormInstance) => {
|
|
|
|
| 44 |
const parserList = useSelectParserList();
|
| 45 |
const embeddingModelOptions = useSelectLlmOptions();
|
| 46 |
|
| 47 |
useFetchTenantInfo();
|
| 48 |
+
const { data: knowledgeDetails } = useFetchKnowledgeBaseConfiguration();
|
| 49 |
useFetchLlmList(LlmModelType.Embedding);
|
| 50 |
|
| 51 |
useEffect(() => {
|
|
|
|
| 74 |
};
|
| 75 |
|
| 76 |
export const useSelectKnowledgeDetailsLoading = () =>
|
| 77 |
+
useIsFetching({ queryKey: ['fetchKnowledgeDetail'] }) > 0;
|
| 78 |
|
| 79 |
export const useHandleChunkMethodChange = () => {
|
| 80 |
const [form] = Form.useForm();
|
web/src/pages/add-knowledge/components/knowledge-setting/model.ts
DELETED
|
@@ -1,49 +0,0 @@
|
|
| 1 |
-
import { IKnowledge } from '@/interfaces/database/knowledge';
|
| 2 |
-
import i18n from '@/locales/config';
|
| 3 |
-
import kbService from '@/services/knowledge-service';
|
| 4 |
-
import { message } from 'antd';
|
| 5 |
-
import { DvaModel } from 'umi';
|
| 6 |
-
|
| 7 |
-
export interface KSModelState {
|
| 8 |
-
isShowPSwModal: boolean;
|
| 9 |
-
tenantIfo: any;
|
| 10 |
-
knowledgeDetails: IKnowledge;
|
| 11 |
-
}
|
| 12 |
-
|
| 13 |
-
const model: DvaModel<KSModelState> = {
|
| 14 |
-
namespace: 'kSModel',
|
| 15 |
-
state: {
|
| 16 |
-
isShowPSwModal: false,
|
| 17 |
-
tenantIfo: {},
|
| 18 |
-
knowledgeDetails: {} as any,
|
| 19 |
-
},
|
| 20 |
-
reducers: {
|
| 21 |
-
updateState(state, { payload }) {
|
| 22 |
-
return {
|
| 23 |
-
...state,
|
| 24 |
-
...payload,
|
| 25 |
-
};
|
| 26 |
-
},
|
| 27 |
-
setKnowledgeDetails(state, { payload }) {
|
| 28 |
-
return { ...state, knowledgeDetails: payload };
|
| 29 |
-
},
|
| 30 |
-
},
|
| 31 |
-
effects: {
|
| 32 |
-
*updateKb({ payload = {} }, { call, put }) {
|
| 33 |
-
const { data } = yield call(kbService.updateKb, payload);
|
| 34 |
-
const { retcode } = data;
|
| 35 |
-
if (retcode === 0) {
|
| 36 |
-
yield put({ type: 'getKbDetail', payload: { kb_id: payload.kb_id } });
|
| 37 |
-
message.success(i18n.t('message.updated'));
|
| 38 |
-
}
|
| 39 |
-
},
|
| 40 |
-
*getKbDetail({ payload = {} }, { call, put }) {
|
| 41 |
-
const { data } = yield call(kbService.get_kb_detail, payload);
|
| 42 |
-
if (data.retcode === 0) {
|
| 43 |
-
yield put({ type: 'setKnowledgeDetails', payload: data.data });
|
| 44 |
-
}
|
| 45 |
-
return data;
|
| 46 |
-
},
|
| 47 |
-
},
|
| 48 |
-
};
|
| 49 |
-
export default model;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
web/src/pages/add-knowledge/components/knowledge-sidebar/index.tsx
CHANGED
|
@@ -3,7 +3,6 @@ import { ReactComponent as DatasetIcon } from '@/assets/svg/knowledge-dataset.sv
|
|
| 3 |
import { ReactComponent as TestingIcon } from '@/assets/svg/knowledge-testing.svg';
|
| 4 |
import { useFetchKnowledgeBaseConfiguration } from '@/hooks/knowledge-hooks';
|
| 5 |
import { useSecondPathName } from '@/hooks/route-hook';
|
| 6 |
-
import { IKnowledge } from '@/interfaces/database/knowledge';
|
| 7 |
import { getWidth } from '@/utils';
|
| 8 |
import { Avatar, Menu, MenuProps, Space } from 'antd';
|
| 9 |
import classNames from 'classnames';
|
|
@@ -11,6 +10,7 @@ import { useCallback, useEffect, useMemo, useState } from 'react';
|
|
| 11 |
import { useTranslation } from 'react-i18next';
|
| 12 |
import { useNavigate, useSelector } from 'umi';
|
| 13 |
import { KnowledgeRouteKey } from '../../constant';
|
|
|
|
| 14 |
import styles from './index.less';
|
| 15 |
|
| 16 |
const KnowledgeSidebar = () => {
|
|
@@ -18,13 +18,11 @@ const KnowledgeSidebar = () => {
|
|
| 18 |
const { id } = kAModel;
|
| 19 |
let navigate = useNavigate();
|
| 20 |
const activeKey = useSecondPathName();
|
| 21 |
-
const knowledgeDetails: IKnowledge = useSelector(
|
| 22 |
-
(state: any) => state.kSModel.knowledgeDetails,
|
| 23 |
-
);
|
| 24 |
|
| 25 |
const [windowWidth, setWindowWidth] = useState(getWidth());
|
| 26 |
const [collapsed, setCollapsed] = useState(false);
|
| 27 |
const { t } = useTranslation();
|
|
|
|
| 28 |
|
| 29 |
const handleSelect: MenuProps['onSelect'] = (e) => {
|
| 30 |
navigate(`/knowledge/${e.key}?id=${id}`);
|
|
@@ -94,8 +92,6 @@ const KnowledgeSidebar = () => {
|
|
| 94 |
};
|
| 95 |
}, []);
|
| 96 |
|
| 97 |
-
useFetchKnowledgeBaseConfiguration();
|
| 98 |
-
|
| 99 |
return (
|
| 100 |
<div className={styles.sidebarWrapper}>
|
| 101 |
<div className={styles.sidebarTop}>
|
|
|
|
| 3 |
import { ReactComponent as TestingIcon } from '@/assets/svg/knowledge-testing.svg';
|
| 4 |
import { useFetchKnowledgeBaseConfiguration } from '@/hooks/knowledge-hooks';
|
| 5 |
import { useSecondPathName } from '@/hooks/route-hook';
|
|
|
|
| 6 |
import { getWidth } from '@/utils';
|
| 7 |
import { Avatar, Menu, MenuProps, Space } from 'antd';
|
| 8 |
import classNames from 'classnames';
|
|
|
|
| 10 |
import { useTranslation } from 'react-i18next';
|
| 11 |
import { useNavigate, useSelector } from 'umi';
|
| 12 |
import { KnowledgeRouteKey } from '../../constant';
|
| 13 |
+
|
| 14 |
import styles from './index.less';
|
| 15 |
|
| 16 |
const KnowledgeSidebar = () => {
|
|
|
|
| 18 |
const { id } = kAModel;
|
| 19 |
let navigate = useNavigate();
|
| 20 |
const activeKey = useSecondPathName();
|
|
|
|
|
|
|
|
|
|
| 21 |
|
| 22 |
const [windowWidth, setWindowWidth] = useState(getWidth());
|
| 23 |
const [collapsed, setCollapsed] = useState(false);
|
| 24 |
const { t } = useTranslation();
|
| 25 |
+
const { data: knowledgeDetails } = useFetchKnowledgeBaseConfiguration();
|
| 26 |
|
| 27 |
const handleSelect: MenuProps['onSelect'] = (e) => {
|
| 28 |
navigate(`/knowledge/${e.key}?id=${id}`);
|
|
|
|
| 92 |
};
|
| 93 |
}, []);
|
| 94 |
|
|
|
|
|
|
|
| 95 |
return (
|
| 96 |
<div className={styles.sidebarWrapper}>
|
| 97 |
<div className={styles.sidebarTop}>
|
web/src/pages/knowledge/model.ts
DELETED
|
@@ -1,63 +0,0 @@
|
|
| 1 |
-
import { IKnowledge } from '@/interfaces/database/knowledge';
|
| 2 |
-
import kbService from '@/services/knowledge-service';
|
| 3 |
-
import { DvaModel } from 'umi';
|
| 4 |
-
|
| 5 |
-
export interface KnowledgeModelState {
|
| 6 |
-
data: IKnowledge[];
|
| 7 |
-
knowledge: IKnowledge;
|
| 8 |
-
}
|
| 9 |
-
|
| 10 |
-
const model: DvaModel<KnowledgeModelState> = {
|
| 11 |
-
namespace: 'knowledgeModel',
|
| 12 |
-
state: {
|
| 13 |
-
data: [],
|
| 14 |
-
knowledge: {} as IKnowledge,
|
| 15 |
-
},
|
| 16 |
-
reducers: {
|
| 17 |
-
updateState(state, { payload }) {
|
| 18 |
-
return {
|
| 19 |
-
...state,
|
| 20 |
-
...payload,
|
| 21 |
-
};
|
| 22 |
-
},
|
| 23 |
-
setKnowledge(state, { payload }) {
|
| 24 |
-
return {
|
| 25 |
-
...state,
|
| 26 |
-
knowledge: payload,
|
| 27 |
-
};
|
| 28 |
-
},
|
| 29 |
-
},
|
| 30 |
-
effects: {
|
| 31 |
-
*rmKb({ payload = {} }, { call, put }) {
|
| 32 |
-
const { data } = yield call(kbService.rmKb, payload);
|
| 33 |
-
const { retcode } = data;
|
| 34 |
-
if (retcode === 0) {
|
| 35 |
-
yield put({
|
| 36 |
-
type: 'getList',
|
| 37 |
-
payload: {},
|
| 38 |
-
});
|
| 39 |
-
}
|
| 40 |
-
},
|
| 41 |
-
*getList({ payload = {} }, { call, put }) {
|
| 42 |
-
const { data } = yield call(kbService.getList, payload);
|
| 43 |
-
const { retcode, data: res } = data;
|
| 44 |
-
|
| 45 |
-
if (retcode === 0) {
|
| 46 |
-
yield put({
|
| 47 |
-
type: 'updateState',
|
| 48 |
-
payload: {
|
| 49 |
-
data: res,
|
| 50 |
-
},
|
| 51 |
-
});
|
| 52 |
-
}
|
| 53 |
-
},
|
| 54 |
-
*getKnowledgeDetail({ payload = {} }, { call, put }) {
|
| 55 |
-
const { data } = yield call(kbService.get_kb_detail, payload);
|
| 56 |
-
if (data.retcode === 0) {
|
| 57 |
-
yield put({ type: 'setKnowledge', payload: data.data });
|
| 58 |
-
}
|
| 59 |
-
return data.retcode;
|
| 60 |
-
},
|
| 61 |
-
},
|
| 62 |
-
};
|
| 63 |
-
export default model;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
web/src/routes.ts
CHANGED
|
@@ -32,11 +32,6 @@ const routes = [
|
|
| 32 |
path: '/knowledge/dataset',
|
| 33 |
component: '@/pages/add-knowledge/components/knowledge-file',
|
| 34 |
},
|
| 35 |
-
{
|
| 36 |
-
path: '/knowledge/dataset/upload',
|
| 37 |
-
component:
|
| 38 |
-
'@/pages/add-knowledge/components/knowledge-dataset/knowledge-upload-file',
|
| 39 |
-
},
|
| 40 |
{
|
| 41 |
path: '/knowledge/dataset/chunk',
|
| 42 |
component: '@/pages/add-knowledge/components/knowledge-chunk',
|
|
|
|
| 32 |
path: '/knowledge/dataset',
|
| 33 |
component: '@/pages/add-knowledge/components/knowledge-file',
|
| 34 |
},
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 35 |
{
|
| 36 |
path: '/knowledge/dataset/chunk',
|
| 37 |
component: '@/pages/add-knowledge/components/knowledge-chunk',
|
web/typings.d.ts
CHANGED
|
@@ -1,39 +1,35 @@
|
|
| 1 |
-
import { ChunkModelState } from '@/pages/add-knowledge/components/knowledge-chunk/model';
|
| 2 |
-
import { KFModelState } from '@/pages/add-knowledge/components/knowledge-file/model';
|
| 3 |
-
import {
|
| 4 |
-
import {
|
| 5 |
-
import {
|
| 6 |
-
import {
|
| 7 |
-
import {
|
| 8 |
-
import {
|
| 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 |
-
declare
|
| 34 |
-
|
| 35 |
-
}
|
| 36 |
-
|
| 37 |
-
declare module 'umi' {
|
| 38 |
-
export { useSelector };
|
| 39 |
-
}
|
|
|
|
| 1 |
+
import { ChunkModelState } from '@/pages/add-knowledge/components/knowledge-chunk/model';
|
| 2 |
+
import { KFModelState } from '@/pages/add-knowledge/components/knowledge-file/model';
|
| 3 |
+
import { TestingModelState } from '@/pages/add-knowledge/components/knowledge-testing/model';
|
| 4 |
+
import { kAModelState } from '@/pages/add-knowledge/model';
|
| 5 |
+
import { ChatModelState } from '@/pages/chat/model';
|
| 6 |
+
import { FileManagerModelState } from '@/pages/file-manager/model';
|
| 7 |
+
import { LoginModelState } from '@/pages/login/model';
|
| 8 |
+
import { SettingModelState } from '@/pages/user-setting/model';
|
| 9 |
+
|
| 10 |
+
declare module 'lodash';
|
| 11 |
+
|
| 12 |
+
function useSelector<TState = RootState, TSelected = unknown>(
|
| 13 |
+
selector: (state: TState) => TSelected,
|
| 14 |
+
equalityFn?: (left: TSelected, right: TSelected) => boolean,
|
| 15 |
+
): TSelected;
|
| 16 |
+
|
| 17 |
+
export interface RootState {
|
| 18 |
+
// loading: Loading;
|
| 19 |
+
fileManager: FileManagerModelState;
|
| 20 |
+
chatModel: ChatModelState;
|
| 21 |
+
loginModel: LoginModelState;
|
| 22 |
+
settingModel: SettingModelState;
|
| 23 |
+
kFModel: KFModelState;
|
| 24 |
+
kAModel: kAModelState;
|
| 25 |
+
chunkModel: ChunkModelState;
|
| 26 |
+
testingModel: TestingModelState;
|
| 27 |
+
}
|
| 28 |
+
|
| 29 |
+
declare global {
|
| 30 |
+
type Nullable<T> = T | null;
|
| 31 |
+
}
|
| 32 |
+
|
| 33 |
+
declare module 'umi' {
|
| 34 |
+
export { useSelector };
|
| 35 |
+
}
|
|
|
|
|
|
|
|
|
|
|
|