Feat: Metadata in documents for improve the prompt #3690 (#4462)

### What problem does this PR solve?

Feat: Metadata in documents for improve the prompt #3690

### Type of change


- [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
balibabu
2025-01-13 17:13:37 +08:00
committed by GitHub
parent 46c52d65b7
commit d8346cb7a6
12 changed files with 270 additions and 13 deletions

View File

@ -1,7 +1,10 @@
import { IReferenceChunk } from '@/interfaces/database/chat';
import { IDocumentInfo } from '@/interfaces/database/document';
import { IChunk } from '@/interfaces/database/knowledge';
import { IChangeParserConfigRequestBody } from '@/interfaces/request/document';
import {
IChangeParserConfigRequestBody,
IDocumentMetaRequestBody,
} from '@/interfaces/request/document';
import i18n from '@/locales/config';
import chatService from '@/services/chat-service';
import kbService from '@/services/knowledge-service';
@ -396,7 +399,6 @@ export const useRemoveNextDocument = () => {
};
export const useDeleteDocument = () => {
// const queryClient = useQueryClient();
const {
data,
isPending: loading,
@ -405,9 +407,7 @@ export const useDeleteDocument = () => {
mutationKey: ['deleteDocument'],
mutationFn: async (documentIds: string[]) => {
const data = await kbService.document_delete({ doc_ids: documentIds });
// if (data.code === 0) {
// queryClient.invalidateQueries({ queryKey: ['fetchFlowList'] });
// }
return data;
},
});
@ -441,9 +441,7 @@ export const useUploadAndParseDocument = (uploadMethod: string) => {
}
const data = await chatService.uploadAndParseExternal(formData);
return data?.data;
} catch (error) {
console.log('🚀 ~ useUploadAndParseDocument ~ error:', error);
}
} catch (error) {}
},
});
@ -465,7 +463,6 @@ export const useParseDocument = () => {
}
return data;
} catch (error) {
console.log('🚀 ~ mutationFn: ~ error:', error);
message.error('error');
}
},
@ -473,3 +470,34 @@ export const useParseDocument = () => {
return { parseDocument: mutateAsync, data, loading };
};
export const useSetDocumentMeta = () => {
const queryClient = useQueryClient();
const {
data,
isPending: loading,
mutateAsync,
} = useMutation({
mutationKey: ['setDocumentMeta'],
mutationFn: async (params: IDocumentMetaRequestBody) => {
try {
const { data } = await kbService.setMeta({
meta: params.meta,
doc_id: params.documentId,
});
if (data?.code === 0) {
queryClient.invalidateQueries({ queryKey: ['fetchDocumentList'] });
message.success(i18n.t('message.modified'));
}
return data?.code;
} catch (error) {
message.error('error');
}
},
});
return { setDocumentMeta: mutateAsync, data, loading };
};