mirror of
https://github.com/infiniflow/ragflow.git
synced 2025-12-19 20:16:49 +08:00
### What problem does this PR solve? Retrieval metadata filtering adds semi-automatic mode, and users can manually check the metadata key that participates in LLM to generate filter conditions. ### Type of change - [x] New Feature (non-breaking change which adds functionality)
135 lines
3.8 KiB
TypeScript
135 lines
3.8 KiB
TypeScript
'use client';
|
|
|
|
import { zodResolver } from '@hookform/resolvers/zod';
|
|
import { useForm, useWatch } from 'react-hook-form';
|
|
import { z } from 'zod';
|
|
|
|
import { CrossLanguageFormField } from '@/components/cross-language-form-field';
|
|
import { FormContainer } from '@/components/form-container';
|
|
import {
|
|
MetadataFilter,
|
|
MetadataFilterSchema,
|
|
} from '@/components/metadata-filter';
|
|
import {
|
|
RerankFormFields,
|
|
initialTopKValue,
|
|
topKSchema,
|
|
} from '@/components/rerank';
|
|
import {
|
|
SimilaritySliderFormField,
|
|
initialSimilarityThresholdValue,
|
|
initialVectorSimilarityWeightValue,
|
|
similarityThresholdSchema,
|
|
vectorSimilarityWeightSchema,
|
|
} from '@/components/similarity-slider';
|
|
import { ButtonLoading } from '@/components/ui/button';
|
|
import {
|
|
Form,
|
|
FormControl,
|
|
FormField,
|
|
FormItem,
|
|
FormMessage,
|
|
} from '@/components/ui/form';
|
|
import { Textarea } from '@/components/ui/textarea';
|
|
import { UseKnowledgeGraphFormField } from '@/components/use-knowledge-graph-item';
|
|
import { useTestRetrieval } from '@/hooks/use-knowledge-request';
|
|
import { trim } from 'lodash';
|
|
import { Send } from 'lucide-react';
|
|
import { useEffect } from 'react';
|
|
import { useTranslation } from 'react-i18next';
|
|
import { useParams } from 'umi';
|
|
|
|
type TestingFormProps = Pick<
|
|
ReturnType<typeof useTestRetrieval>,
|
|
'loading' | 'refetch' | 'setValues'
|
|
>;
|
|
|
|
export default function TestingForm({
|
|
loading,
|
|
refetch,
|
|
setValues,
|
|
}: TestingFormProps) {
|
|
const { t } = useTranslation();
|
|
const { id } = useParams(); // 正确解构出id参数
|
|
const knowledgeBaseId = id; // 现在knowledgeBaseId是字符串类型
|
|
|
|
const formSchema = z.object({
|
|
question: z.string().min(1, {
|
|
message: t('knowledgeDetails.testTextPlaceholder'),
|
|
}),
|
|
...similarityThresholdSchema,
|
|
...vectorSimilarityWeightSchema,
|
|
...topKSchema,
|
|
use_kg: z.boolean().optional(),
|
|
kb_ids: z.array(z.string()).optional(),
|
|
...MetadataFilterSchema,
|
|
});
|
|
|
|
const form = useForm<z.infer<typeof formSchema>>({
|
|
resolver: zodResolver(formSchema),
|
|
defaultValues: {
|
|
...initialSimilarityThresholdValue,
|
|
...initialVectorSimilarityWeightValue,
|
|
...initialTopKValue,
|
|
use_kg: false,
|
|
kb_ids: [knowledgeBaseId],
|
|
},
|
|
});
|
|
|
|
const question = form.watch('question');
|
|
|
|
const values = useWatch({ control: form.control });
|
|
|
|
useEffect(() => {
|
|
setValues(values as Required<z.infer<typeof formSchema>>);
|
|
}, [setValues, values]);
|
|
|
|
function onSubmit() {
|
|
refetch();
|
|
}
|
|
|
|
return (
|
|
<Form {...form}>
|
|
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-8">
|
|
<FormContainer className="p-10">
|
|
<SimilaritySliderFormField
|
|
isTooltipShown={true}
|
|
></SimilaritySliderFormField>
|
|
<RerankFormFields></RerankFormFields>
|
|
<UseKnowledgeGraphFormField name="use_kg"></UseKnowledgeGraphFormField>
|
|
<CrossLanguageFormField
|
|
name={'cross_languages'}
|
|
></CrossLanguageFormField>
|
|
{/* 添加元数据过滤组件 */}
|
|
<MetadataFilter prefix=""></MetadataFilter>
|
|
</FormContainer>
|
|
<FormField
|
|
control={form.control}
|
|
name="question"
|
|
render={({ field }) => (
|
|
<FormItem>
|
|
{/* <FormLabel>{t('knowledgeDetails.testText')}</FormLabel> */}
|
|
<FormControl>
|
|
<Textarea {...field}></Textarea>
|
|
</FormControl>
|
|
|
|
<FormMessage />
|
|
</FormItem>
|
|
)}
|
|
/>
|
|
<div className="flex justify-end">
|
|
<ButtonLoading
|
|
type="submit"
|
|
disabled={!!!trim(question)}
|
|
loading={loading}
|
|
>
|
|
{/* {!loading && <CirclePlay />} */}
|
|
{t('knowledgeDetails.testingLabel')}
|
|
<Send />
|
|
</ButtonLoading>
|
|
</div>
|
|
</form>
|
|
</Form>
|
|
);
|
|
}
|