feat: create chunk and edit chunk and delete chunk (#58)

* feat: create chunk and edit chunk

* feat: delete chunk

* feat: search chunks

* feat: delete chunks in batches

* feat: set whether chunks are available in batches
This commit is contained in:
balibabu
2024-02-07 18:04:25 +08:00
committed by GitHub
parent 97d4387982
commit eb8254e688
16 changed files with 613 additions and 248 deletions

View File

@ -1,5 +1,6 @@
import showDeleteConfirm from '@/components/deleting-confirm';
import { IKnowledge } from '@/interfaces/database/knowledge';
import { useCallback } from 'react';
import { useDispatch, useSearchParams, useSelector } from 'umi';
export const useKnowledgeBaseId = (): string => {
@ -46,3 +47,33 @@ export const useGetDocumentDefaultParser = (knowledgeBaseId: string) => {
parserConfig: item?.parser_config ?? '',
};
};
export const useDeleteChunkByIds = (): {
removeChunk: (chunkIds: string[], documentId: string) => Promise<number>;
} => {
const dispatch = useDispatch();
const removeChunk = useCallback(
(chunkIds: string[], documentId: string) => () => {
return dispatch({
type: 'chunkModel/rm_chunk',
payload: {
chunk_ids: chunkIds,
doc_id: documentId,
},
});
},
[dispatch],
);
const onRemoveChunk = useCallback(
(chunkIds: string[], documentId: string): Promise<number> => {
return showDeleteConfirm({ onOk: removeChunk(chunkIds, documentId) });
},
[removeChunk],
);
return {
removeChunk: onRemoveChunk,
};
};