mirror of
https://git.mirrors.martin98.com/https://github.com/infiniflow/ragflow.git
synced 2025-08-14 00:05:55 +08:00
### What problem does this PR solve? Feat: Construct RetrievalForm with original fields #3221 ### Type of change - [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
parent
e64da8b2aa
commit
4cd0df0567
@ -13,15 +13,7 @@ import {
|
|||||||
FormLabel,
|
FormLabel,
|
||||||
FormMessage,
|
FormMessage,
|
||||||
} from './ui/form';
|
} from './ui/form';
|
||||||
import {
|
import { RAGFlowSelect } from './ui/select';
|
||||||
Select,
|
|
||||||
SelectContent,
|
|
||||||
SelectGroup,
|
|
||||||
SelectItem,
|
|
||||||
SelectLabel,
|
|
||||||
SelectTrigger,
|
|
||||||
SelectValue,
|
|
||||||
} from './ui/select';
|
|
||||||
|
|
||||||
type FieldType = {
|
type FieldType = {
|
||||||
rerank_id?: string;
|
rerank_id?: string;
|
||||||
@ -117,32 +109,11 @@ function RerankFormField() {
|
|||||||
<FormItem>
|
<FormItem>
|
||||||
<FormLabel tooltip={t('rerankTip')}>{t('rerankModel')}</FormLabel>
|
<FormLabel tooltip={t('rerankTip')}>{t('rerankModel')}</FormLabel>
|
||||||
<FormControl>
|
<FormControl>
|
||||||
<Select onValueChange={field.onChange} {...field}>
|
<RAGFlowSelect
|
||||||
<SelectTrigger
|
allowClear
|
||||||
value={field.value}
|
{...field}
|
||||||
onReset={() => {
|
options={options}
|
||||||
form.resetField(RerankId);
|
></RAGFlowSelect>
|
||||||
}}
|
|
||||||
>
|
|
||||||
<SelectValue placeholder={t('rerankPlaceholder')} />
|
|
||||||
</SelectTrigger>
|
|
||||||
<SelectContent>
|
|
||||||
{options.map((x) => (
|
|
||||||
<SelectGroup key={x.label}>
|
|
||||||
<SelectLabel>{x.label}</SelectLabel>
|
|
||||||
{x.options.map((y) => (
|
|
||||||
<SelectItem
|
|
||||||
value={y.value}
|
|
||||||
key={y.value}
|
|
||||||
disabled={y.disabled}
|
|
||||||
>
|
|
||||||
{y.label}
|
|
||||||
</SelectItem>
|
|
||||||
))}
|
|
||||||
</SelectGroup>
|
|
||||||
))}
|
|
||||||
</SelectContent>
|
|
||||||
</Select>
|
|
||||||
</FormControl>
|
</FormControl>
|
||||||
<FormMessage />
|
<FormMessage />
|
||||||
</FormItem>
|
</FormItem>
|
||||||
|
@ -1278,6 +1278,7 @@ This delimiter is used to split the input text into several text pieces echo of
|
|||||||
modeTip: 'The mode defines how the workflow is initiated.',
|
modeTip: 'The mode defines how the workflow is initiated.',
|
||||||
beginInputTip:
|
beginInputTip:
|
||||||
'By defining input parameters, this content can be accessed by other components in subsequent processes.',
|
'By defining input parameters, this content can be accessed by other components in subsequent processes.',
|
||||||
|
query: 'Query variables',
|
||||||
},
|
},
|
||||||
llmTools: {
|
llmTools: {
|
||||||
bad_calculator: {
|
bad_calculator: {
|
||||||
|
@ -1231,6 +1231,7 @@ General:实体和关系提取提示来自 GitHub - microsoft/graphrag:基于
|
|||||||
openingSwitchTip: '您的用户将在开始时看到此欢迎消息。',
|
openingSwitchTip: '您的用户将在开始时看到此欢迎消息。',
|
||||||
modeTip: '模式定义了工作流的启动方式。',
|
modeTip: '模式定义了工作流的启动方式。',
|
||||||
beginInputTip: '通过定义输入参数,此内容可以被后续流程中的其他组件访问。',
|
beginInputTip: '通过定义输入参数,此内容可以被后续流程中的其他组件访问。',
|
||||||
|
query: '查询变量',
|
||||||
},
|
},
|
||||||
footer: {
|
footer: {
|
||||||
profile: 'All rights reserved @ React',
|
profile: 'All rights reserved @ React',
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
import { BlockButton, Button } from '@/components/ui/button';
|
import { Button } from '@/components/ui/button';
|
||||||
import {
|
import {
|
||||||
FormControl,
|
FormControl,
|
||||||
FormField,
|
FormField,
|
||||||
@ -59,13 +59,6 @@ const DynamicExample = ({ name }: DynamicExampleProps) => {
|
|||||||
)}
|
)}
|
||||||
</div>
|
</div>
|
||||||
))}
|
))}
|
||||||
|
|
||||||
<BlockButton
|
|
||||||
type="button"
|
|
||||||
onClick={() => append({ value: '' })} // "" will cause the inability to add, refer to: https://github.com/orgs/react-hook-form/discussions/8485#discussioncomment-2961861
|
|
||||||
>
|
|
||||||
{t('flow.addMessage')}
|
|
||||||
</BlockButton>
|
|
||||||
</div>
|
</div>
|
||||||
<FormMessage />
|
<FormMessage />
|
||||||
</FormItem>
|
</FormItem>
|
||||||
|
@ -2,20 +2,13 @@ import { FormContainer } from '@/components/form-container';
|
|||||||
import { LargeModelFormField } from '@/components/large-model-form-field';
|
import { LargeModelFormField } from '@/components/large-model-form-field';
|
||||||
import { LlmSettingSchema } from '@/components/llm-setting-items/next';
|
import { LlmSettingSchema } from '@/components/llm-setting-items/next';
|
||||||
import { MessageHistoryWindowSizeFormField } from '@/components/message-history-window-size-item';
|
import { MessageHistoryWindowSizeFormField } from '@/components/message-history-window-size-item';
|
||||||
import { SelectWithSearch } from '@/components/originui/select-with-search';
|
import { Form } from '@/components/ui/form';
|
||||||
import {
|
|
||||||
Form,
|
|
||||||
FormControl,
|
|
||||||
FormField,
|
|
||||||
FormItem,
|
|
||||||
FormLabel,
|
|
||||||
FormMessage,
|
|
||||||
} from '@/components/ui/form';
|
|
||||||
import { zodResolver } from '@hookform/resolvers/zod';
|
import { zodResolver } from '@hookform/resolvers/zod';
|
||||||
import { useForm } from 'react-hook-form';
|
import { useForm } from 'react-hook-form';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
import { z } from 'zod';
|
import { z } from 'zod';
|
||||||
import { INextOperatorForm } from '../../interface';
|
import { INextOperatorForm } from '../../interface';
|
||||||
|
import { QueryVariable } from '../components/query-variable';
|
||||||
import DynamicCategorize from './dynamic-categorize';
|
import DynamicCategorize from './dynamic-categorize';
|
||||||
import { useValues } from './use-values';
|
import { useValues } from './use-values';
|
||||||
import { useWatchFormChange } from './use-watch-change';
|
import { useWatchFormChange } from './use-watch-change';
|
||||||
@ -26,7 +19,7 @@ const CategorizeForm = ({ node }: INextOperatorForm) => {
|
|||||||
const values = useValues(node);
|
const values = useValues(node);
|
||||||
|
|
||||||
const FormSchema = z.object({
|
const FormSchema = z.object({
|
||||||
input: z.string().optional(),
|
query: z.string().optional(),
|
||||||
parameter: z.string().optional(),
|
parameter: z.string().optional(),
|
||||||
...LlmSettingSchema,
|
...LlmSettingSchema,
|
||||||
message_history_window_size: z.coerce.number(),
|
message_history_window_size: z.coerce.number(),
|
||||||
@ -63,22 +56,7 @@ const CategorizeForm = ({ node }: INextOperatorForm) => {
|
|||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<FormContainer>
|
<FormContainer>
|
||||||
<FormField
|
<QueryVariable></QueryVariable>
|
||||||
control={form.control}
|
|
||||||
name="input"
|
|
||||||
render={({ field }) => (
|
|
||||||
<FormItem>
|
|
||||||
<FormLabel tooltip={t('chat.modelTip')}>
|
|
||||||
{t('chat.input')}
|
|
||||||
</FormLabel>
|
|
||||||
<FormControl>
|
|
||||||
<SelectWithSearch {...field}></SelectWithSearch>
|
|
||||||
</FormControl>
|
|
||||||
<FormMessage />
|
|
||||||
</FormItem>
|
|
||||||
)}
|
|
||||||
/>
|
|
||||||
|
|
||||||
<LargeModelFormField></LargeModelFormField>
|
<LargeModelFormField></LargeModelFormField>
|
||||||
</FormContainer>
|
</FormContainer>
|
||||||
<MessageHistoryWindowSizeFormField
|
<MessageHistoryWindowSizeFormField
|
||||||
|
31
web/src/pages/agent/form/components/query-variable.tsx
Normal file
31
web/src/pages/agent/form/components/query-variable.tsx
Normal file
@ -0,0 +1,31 @@
|
|||||||
|
import { SelectWithSearch } from '@/components/originui/select-with-search';
|
||||||
|
import {
|
||||||
|
FormControl,
|
||||||
|
FormField,
|
||||||
|
FormItem,
|
||||||
|
FormLabel,
|
||||||
|
FormMessage,
|
||||||
|
} from '@/components/ui/form';
|
||||||
|
import { useFormContext } from 'react-hook-form';
|
||||||
|
import { useTranslation } from 'react-i18next';
|
||||||
|
|
||||||
|
export function QueryVariable() {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
const form = useFormContext();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="query"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel tooltip={t('chat.modelTip')}>{t('flow.query')}</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<SelectWithSearch {...field}></SelectWithSearch>
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
@ -1,6 +1,12 @@
|
|||||||
|
import { FormContainer } from '@/components/form-container';
|
||||||
import { KnowledgeBaseFormField } from '@/components/knowledge-base-item';
|
import { KnowledgeBaseFormField } from '@/components/knowledge-base-item';
|
||||||
|
import { LargeModelFormField } from '@/components/large-model-form-field';
|
||||||
import { RerankFormFields } from '@/components/rerank';
|
import { RerankFormFields } from '@/components/rerank';
|
||||||
import { SimilaritySliderFormField } from '@/components/similarity-slider';
|
import {
|
||||||
|
initialKeywordsSimilarityWeightValue,
|
||||||
|
initialSimilarityThresholdValue,
|
||||||
|
SimilaritySliderFormField,
|
||||||
|
} from '@/components/similarity-slider';
|
||||||
import { TopNFormField } from '@/components/top-n-item';
|
import { TopNFormField } from '@/components/top-n-item';
|
||||||
import {
|
import {
|
||||||
Form,
|
Form,
|
||||||
@ -11,46 +17,82 @@ import {
|
|||||||
FormMessage,
|
FormMessage,
|
||||||
} from '@/components/ui/form';
|
} from '@/components/ui/form';
|
||||||
import { Textarea } from '@/components/ui/textarea';
|
import { Textarea } from '@/components/ui/textarea';
|
||||||
|
import { zodResolver } from '@hookform/resolvers/zod';
|
||||||
|
import { useForm } from 'react-hook-form';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
import { z } from 'zod';
|
||||||
import { INextOperatorForm } from '../../interface';
|
import { INextOperatorForm } from '../../interface';
|
||||||
import { DynamicInputVariable } from '../components/next-dynamic-input-variable';
|
import { QueryVariable } from '../components/query-variable';
|
||||||
|
|
||||||
const RetrievalForm = ({ form, node }: INextOperatorForm) => {
|
const FormSchema = z.object({
|
||||||
|
query: z.string().optional(),
|
||||||
|
similarity_threshold: z.coerce.number(),
|
||||||
|
keywords_similarity_weight: z.coerce.number(),
|
||||||
|
top_n: z.coerce.number(),
|
||||||
|
top_k: z.coerce.number(),
|
||||||
|
kb_ids: z.array(z.string()),
|
||||||
|
rerank_id: z.string(),
|
||||||
|
empty_response: z.string(),
|
||||||
|
});
|
||||||
|
|
||||||
|
const defaultValues = {
|
||||||
|
query: '',
|
||||||
|
top_n: 0.2,
|
||||||
|
top_k: 1024,
|
||||||
|
kb_ids: [],
|
||||||
|
rerank_id: '',
|
||||||
|
empty_response: '',
|
||||||
|
...initialSimilarityThresholdValue,
|
||||||
|
...initialKeywordsSimilarityWeightValue,
|
||||||
|
};
|
||||||
|
|
||||||
|
const RetrievalForm = ({ node }: INextOperatorForm) => {
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
|
||||||
|
const form = useForm({
|
||||||
|
defaultValues: defaultValues,
|
||||||
|
resolver: zodResolver(FormSchema),
|
||||||
|
});
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Form {...form}>
|
<Form {...form}>
|
||||||
<form
|
<form
|
||||||
className="space-y-6"
|
className="space-y-6 p-4"
|
||||||
onSubmit={(e) => {
|
onSubmit={(e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<DynamicInputVariable node={node}></DynamicInputVariable>
|
<FormContainer>
|
||||||
<SimilaritySliderFormField
|
<QueryVariable></QueryVariable>
|
||||||
vectorSimilarityWeightName="keywords_similarity_weight"
|
<LargeModelFormField></LargeModelFormField>
|
||||||
isTooltipShown
|
</FormContainer>
|
||||||
></SimilaritySliderFormField>
|
<FormContainer>
|
||||||
<TopNFormField></TopNFormField>
|
<SimilaritySliderFormField
|
||||||
<RerankFormFields></RerankFormFields>
|
vectorSimilarityWeightName="keywords_similarity_weight"
|
||||||
<KnowledgeBaseFormField></KnowledgeBaseFormField>
|
isTooltipShown
|
||||||
<FormField
|
></SimilaritySliderFormField>
|
||||||
control={form.control}
|
<TopNFormField></TopNFormField>
|
||||||
name="empty_response"
|
<RerankFormFields></RerankFormFields>
|
||||||
render={({ field }) => (
|
<KnowledgeBaseFormField></KnowledgeBaseFormField>
|
||||||
<FormItem>
|
<FormField
|
||||||
<FormLabel>{t('chat.emptyResponse')}</FormLabel>
|
control={form.control}
|
||||||
<FormControl>
|
name="empty_response"
|
||||||
<Textarea
|
render={({ field }) => (
|
||||||
placeholder={t('common.namePlaceholder')}
|
<FormItem>
|
||||||
{...field}
|
<FormLabel>{t('chat.emptyResponse')}</FormLabel>
|
||||||
autoComplete="off"
|
<FormControl>
|
||||||
rows={4}
|
<Textarea
|
||||||
/>
|
placeholder={t('common.namePlaceholder')}
|
||||||
</FormControl>
|
{...field}
|
||||||
<FormMessage />
|
autoComplete="off"
|
||||||
</FormItem>
|
rows={4}
|
||||||
)}
|
/>
|
||||||
/>
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
</FormContainer>
|
||||||
</form>
|
</form>
|
||||||
</Form>
|
</Form>
|
||||||
);
|
);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user