mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-18 19:46:44 +08:00
### What problem does this PR solve? feat(dataset): Added data pipeline configuration functionality #9869 - Added a data pipeline selection component to link data pipelines with knowledge bases - Added file filtering functionality, supporting custom file filtering rules - Optimized the configuration interface layout, adjusting style and spacing - Introduced new icons and buttons to enhance the user experience ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue)
90 lines
2.6 KiB
TypeScript
90 lines
2.6 KiB
TypeScript
import { LlmModelType } from '@/constants/knowledge';
|
|
import { useSetModalState } from '@/hooks/common-hooks';
|
|
|
|
import { useSelectLlmOptionsByModelType } from '@/hooks/llm-hooks';
|
|
import { useFetchKnowledgeBaseConfiguration } from '@/hooks/use-knowledge-request';
|
|
import { useSelectParserList } from '@/hooks/user-setting-hooks';
|
|
import { useIsFetching } from '@tanstack/react-query';
|
|
import { pick } from 'lodash';
|
|
import { useCallback, useEffect, useState } from 'react';
|
|
import { UseFormReturn } from 'react-hook-form';
|
|
import { z } from 'zod';
|
|
import { formSchema } from './form-schema';
|
|
|
|
// The value that does not need to be displayed in the analysis method Select
|
|
const HiddenFields = ['email', 'picture', 'audio'];
|
|
|
|
export function useSelectChunkMethodList() {
|
|
const parserList = useSelectParserList();
|
|
|
|
return parserList.filter((x) => !HiddenFields.some((y) => y === x.value));
|
|
}
|
|
|
|
export function useSelectEmbeddingModelOptions() {
|
|
const allOptions = useSelectLlmOptionsByModelType();
|
|
return allOptions[LlmModelType.Embedding];
|
|
}
|
|
|
|
export function useHasParsedDocument(isEdit?: boolean) {
|
|
const { data: knowledgeDetails } = useFetchKnowledgeBaseConfiguration({
|
|
isEdit,
|
|
});
|
|
return knowledgeDetails.chunk_num > 0;
|
|
}
|
|
|
|
export const useFetchKnowledgeConfigurationOnMount = (
|
|
form: UseFormReturn<z.infer<typeof formSchema>, any, undefined>,
|
|
) => {
|
|
const { data: knowledgeDetails } = useFetchKnowledgeBaseConfiguration();
|
|
|
|
useEffect(() => {
|
|
const parser_config = {
|
|
...form.formState?.defaultValues?.parser_config,
|
|
...knowledgeDetails.parser_config,
|
|
};
|
|
const formValues = {
|
|
...pick({ ...knowledgeDetails, parser_config: parser_config }, [
|
|
'description',
|
|
'name',
|
|
'permission',
|
|
'embd_id',
|
|
'parser_id',
|
|
'language',
|
|
'parser_config',
|
|
'pagerank',
|
|
'avatar',
|
|
]),
|
|
} as z.infer<typeof formSchema>;
|
|
form.reset(formValues);
|
|
}, [form, knowledgeDetails]);
|
|
|
|
return knowledgeDetails;
|
|
};
|
|
|
|
export const useSelectKnowledgeDetailsLoading = () =>
|
|
useIsFetching({ queryKey: ['fetchKnowledgeDetail'] }) > 0;
|
|
|
|
export const useRenameKnowledgeTag = () => {
|
|
const [tag, setTag] = useState<string>('');
|
|
const {
|
|
visible: tagRenameVisible,
|
|
hideModal: hideTagRenameModal,
|
|
showModal: showFileRenameModal,
|
|
} = useSetModalState();
|
|
|
|
const handleShowTagRenameModal = useCallback(
|
|
(record: string) => {
|
|
setTag(record);
|
|
showFileRenameModal();
|
|
},
|
|
[showFileRenameModal],
|
|
);
|
|
|
|
return {
|
|
initialName: tag,
|
|
tagRenameVisible,
|
|
hideTagRenameModal,
|
|
showTagRenameModal: handleShowTagRenameModal,
|
|
};
|
|
};
|