mirror of
https://git.mirrors.martin98.com/https://github.com/infiniflow/ragflow.git
synced 2025-08-12 06:18:58 +08:00
### What problem does this PR solve? Feat: Add hatPromptEngine component #3221 ### Type of change - [x] New Feature (non-breaking change which adds functionality)
This commit is contained in:
parent
521d25d4e6
commit
d197f33646
@ -1,7 +1,25 @@
|
|||||||
import { LlmModelType } from '@/constants/knowledge';
|
import { LlmModelType } from '@/constants/knowledge';
|
||||||
import { useTranslate } from '@/hooks/common-hooks';
|
import { useTranslate } from '@/hooks/common-hooks';
|
||||||
import { useSelectLlmOptionsByModelType } from '@/hooks/llm-hooks';
|
import { useSelectLlmOptionsByModelType } from '@/hooks/llm-hooks';
|
||||||
import { Form, Select, Slider } from 'antd';
|
import { Select as AntSelect, Form, Slider } from 'antd';
|
||||||
|
import { useFormContext } from 'react-hook-form';
|
||||||
|
import {
|
||||||
|
FormControl,
|
||||||
|
FormField,
|
||||||
|
FormItem,
|
||||||
|
FormLabel,
|
||||||
|
FormMessage,
|
||||||
|
} from './ui/form';
|
||||||
|
import {
|
||||||
|
Select,
|
||||||
|
SelectContent,
|
||||||
|
SelectGroup,
|
||||||
|
SelectItem,
|
||||||
|
SelectLabel,
|
||||||
|
SelectTrigger,
|
||||||
|
SelectValue,
|
||||||
|
} from './ui/select';
|
||||||
|
import { FormSlider } from './ui/slider';
|
||||||
|
|
||||||
type FieldType = {
|
type FieldType = {
|
||||||
rerank_id?: string;
|
rerank_id?: string;
|
||||||
@ -18,7 +36,7 @@ export const RerankItem = () => {
|
|||||||
name={'rerank_id'}
|
name={'rerank_id'}
|
||||||
tooltip={t('rerankTip')}
|
tooltip={t('rerankTip')}
|
||||||
>
|
>
|
||||||
<Select
|
<AntSelect
|
||||||
options={allOptions[LlmModelType.Rerank]}
|
options={allOptions[LlmModelType.Rerank]}
|
||||||
allowClear
|
allowClear
|
||||||
placeholder={t('rerankPlaceholder')}
|
placeholder={t('rerankPlaceholder')}
|
||||||
@ -55,3 +73,81 @@ const Rerank = () => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export default Rerank;
|
export default Rerank;
|
||||||
|
|
||||||
|
const RerankId = 'rerank_id';
|
||||||
|
|
||||||
|
function RerankFormField() {
|
||||||
|
const form = useFormContext();
|
||||||
|
const { t } = useTranslate('knowledgeDetails');
|
||||||
|
const allOptions = useSelectLlmOptionsByModelType();
|
||||||
|
const options = allOptions[LlmModelType.Rerank];
|
||||||
|
|
||||||
|
return (
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name={RerankId}
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>{t('rerankModel')}</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Select onValueChange={field.onChange} {...field}>
|
||||||
|
<SelectTrigger
|
||||||
|
className="w-[280px]"
|
||||||
|
value={field.value}
|
||||||
|
onReset={() => {
|
||||||
|
form.resetField(RerankId);
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<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>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function RerankFormFields() {
|
||||||
|
const { control, watch } = useFormContext();
|
||||||
|
const { t } = useTranslate('knowledgeDetails');
|
||||||
|
const rerankId = watch(RerankId);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<>
|
||||||
|
<RerankFormField></RerankFormField>
|
||||||
|
{rerankId && (
|
||||||
|
<FormField
|
||||||
|
control={control}
|
||||||
|
name={'top_k'}
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>{t('topK')}</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<FormSlider {...field} max={2048} min={1}></FormSlider>
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
)}
|
||||||
|
</>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
@ -1,5 +1,14 @@
|
|||||||
import { useTranslate } from '@/hooks/common-hooks';
|
import { useTranslate } from '@/hooks/common-hooks';
|
||||||
import { Form, Slider } from 'antd';
|
import { Form, Slider } from 'antd';
|
||||||
|
import { useFormContext } from 'react-hook-form';
|
||||||
|
import {
|
||||||
|
FormControl,
|
||||||
|
FormField,
|
||||||
|
FormItem,
|
||||||
|
FormLabel,
|
||||||
|
FormMessage,
|
||||||
|
} from '../ui/form';
|
||||||
|
import { FormSlider } from '../ui/slider';
|
||||||
|
|
||||||
type FieldType = {
|
type FieldType = {
|
||||||
similarity_threshold?: number;
|
similarity_threshold?: number;
|
||||||
@ -40,3 +49,30 @@ const SimilaritySlider = ({
|
|||||||
};
|
};
|
||||||
|
|
||||||
export default SimilaritySlider;
|
export default SimilaritySlider;
|
||||||
|
|
||||||
|
interface SimilaritySliderFormFieldProps {
|
||||||
|
name?: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function SimilaritySliderFormField({
|
||||||
|
name = 'vector_similarity_weight',
|
||||||
|
}: SimilaritySliderFormFieldProps) {
|
||||||
|
const form = useFormContext();
|
||||||
|
const { t } = useTranslate('knowledgeDetails');
|
||||||
|
|
||||||
|
return (
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name={name}
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>{t('vectorSimilarityWeight')}</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<FormSlider {...field}></FormSlider>
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
@ -1,5 +1,14 @@
|
|||||||
import { useTranslate } from '@/hooks/common-hooks';
|
import { useTranslate } from '@/hooks/common-hooks';
|
||||||
import { Form, Slider } from 'antd';
|
import { Form, Slider } from 'antd';
|
||||||
|
import { useFormContext } from 'react-hook-form';
|
||||||
|
import {
|
||||||
|
FormControl,
|
||||||
|
FormField,
|
||||||
|
FormItem,
|
||||||
|
FormLabel,
|
||||||
|
FormMessage,
|
||||||
|
} from './ui/form';
|
||||||
|
import { FormSlider } from './ui/slider';
|
||||||
|
|
||||||
type FieldType = {
|
type FieldType = {
|
||||||
top_n?: number;
|
top_n?: number;
|
||||||
@ -26,3 +35,28 @@ const TopNItem = ({ initialValue = 8, max = 30 }: IProps) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
export default TopNItem;
|
export default TopNItem;
|
||||||
|
|
||||||
|
interface SimilaritySliderFormFieldProps {
|
||||||
|
max?: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function TopNFormField({ max = 30 }: SimilaritySliderFormFieldProps) {
|
||||||
|
const form = useFormContext();
|
||||||
|
const { t } = useTranslate('chat');
|
||||||
|
|
||||||
|
return (
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name={'top_n'}
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>{t('topN')}</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<FormSlider {...field} max={max}></FormSlider>
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
@ -1,5 +1,6 @@
|
|||||||
import { Form, Switch } from 'antd';
|
import { Form, Switch } from 'antd';
|
||||||
import { useTranslation } from 'react-i18next';
|
import { useTranslation } from 'react-i18next';
|
||||||
|
import { SwitchFormField } from './switch-fom-field';
|
||||||
|
|
||||||
type IProps = {
|
type IProps = {
|
||||||
filedName: string[];
|
filedName: string[];
|
||||||
@ -19,3 +20,20 @@ export function UseKnowledgeGraphItem({ filedName }: IProps) {
|
|||||||
</Form.Item>
|
</Form.Item>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
interface UseKnowledgeGraphFormFieldProps {
|
||||||
|
name: string;
|
||||||
|
}
|
||||||
|
|
||||||
|
export function UseKnowledgeGraphFormField({
|
||||||
|
name,
|
||||||
|
}: UseKnowledgeGraphFormFieldProps) {
|
||||||
|
const { t } = useTranslation();
|
||||||
|
|
||||||
|
return (
|
||||||
|
<SwitchFormField
|
||||||
|
name={name}
|
||||||
|
label={t('chat.useKnowledgeGraph')}
|
||||||
|
></SwitchFormField>
|
||||||
|
);
|
||||||
|
}
|
||||||
|
@ -1,13 +1,9 @@
|
|||||||
'use client';
|
'use client';
|
||||||
|
|
||||||
import { zodResolver } from '@hookform/resolvers/zod';
|
|
||||||
import { useForm } from 'react-hook-form';
|
|
||||||
import { z } from 'zod';
|
|
||||||
|
|
||||||
import { FileUploader } from '@/components/file-uploader';
|
import { FileUploader } from '@/components/file-uploader';
|
||||||
import { KnowledgeBaseFormField } from '@/components/knowledge-base-item';
|
import { KnowledgeBaseFormField } from '@/components/knowledge-base-item';
|
||||||
|
import { SwitchFormField } from '@/components/switch-fom-field';
|
||||||
import {
|
import {
|
||||||
Form,
|
|
||||||
FormControl,
|
FormControl,
|
||||||
FormField,
|
FormField,
|
||||||
FormItem,
|
FormItem,
|
||||||
@ -16,60 +12,20 @@ import {
|
|||||||
} from '@/components/ui/form';
|
} from '@/components/ui/form';
|
||||||
import { Input } from '@/components/ui/input';
|
import { Input } from '@/components/ui/input';
|
||||||
import { useTranslate } from '@/hooks/common-hooks';
|
import { useTranslate } from '@/hooks/common-hooks';
|
||||||
|
import { useFormContext } from 'react-hook-form';
|
||||||
import { Subhead } from './subhead';
|
import { Subhead } from './subhead';
|
||||||
import { SwitchFormField } from './switch-fom-field';
|
|
||||||
|
|
||||||
export default function ChatBasicSetting() {
|
export default function ChatBasicSetting() {
|
||||||
const { t } = useTranslate('chat');
|
const { t } = useTranslate('chat');
|
||||||
|
const form = useFormContext();
|
||||||
const promptConfigSchema = z.object({
|
|
||||||
quote: z.boolean(),
|
|
||||||
keyword: z.boolean(),
|
|
||||||
tts: z.boolean(),
|
|
||||||
empty_response: z.string().min(1, {
|
|
||||||
message: t('emptyResponse'),
|
|
||||||
}),
|
|
||||||
prologue: z.string().min(2, {}),
|
|
||||||
});
|
|
||||||
|
|
||||||
const formSchema = z.object({
|
|
||||||
name: z.string().min(1, { message: t('assistantNameMessage') }),
|
|
||||||
icon: z.array(z.instanceof(File)),
|
|
||||||
language: z.string().min(1, {
|
|
||||||
message: 'Username must be at least 2 characters.',
|
|
||||||
}),
|
|
||||||
description: z.string(),
|
|
||||||
kb_ids: z.array(z.string()).min(0, {
|
|
||||||
message: 'Username must be at least 1 characters.',
|
|
||||||
}),
|
|
||||||
prompt_config: promptConfigSchema,
|
|
||||||
});
|
|
||||||
|
|
||||||
const form = useForm<z.infer<typeof formSchema>>({
|
|
||||||
resolver: zodResolver(formSchema),
|
|
||||||
defaultValues: {
|
|
||||||
name: '',
|
|
||||||
language: 'English',
|
|
||||||
prompt_config: {
|
|
||||||
quote: true,
|
|
||||||
keyword: false,
|
|
||||||
tts: false,
|
|
||||||
},
|
|
||||||
},
|
|
||||||
});
|
|
||||||
|
|
||||||
function onSubmit(values: z.infer<typeof formSchema>) {
|
|
||||||
console.log(values);
|
|
||||||
}
|
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<section>
|
<section>
|
||||||
<Subhead>Basic settings</Subhead>
|
<Subhead>Basic settings</Subhead>
|
||||||
<Form {...form}>
|
<div className="space-y-8">
|
||||||
<form onSubmit={form.handleSubmit(onSubmit)} className="space-y-8">
|
|
||||||
<FormField
|
<FormField
|
||||||
control={form.control}
|
control={form.control}
|
||||||
name="icon"
|
name={'icon'}
|
||||||
render={({ field }) => (
|
render={({ field }) => (
|
||||||
<div className="space-y-6">
|
<div className="space-y-6">
|
||||||
<FormItem className="w-full">
|
<FormItem className="w-full">
|
||||||
@ -156,8 +112,7 @@ export default function ChatBasicSetting() {
|
|||||||
label={t('tts')}
|
label={t('tts')}
|
||||||
></SwitchFormField>
|
></SwitchFormField>
|
||||||
<KnowledgeBaseFormField></KnowledgeBaseFormField>
|
<KnowledgeBaseFormField></KnowledgeBaseFormField>
|
||||||
</form>
|
</div>
|
||||||
</Form>
|
|
||||||
</section>
|
</section>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1,9 +1,56 @@
|
|||||||
|
'use client';
|
||||||
|
|
||||||
|
import { RerankFormFields } from '@/components/rerank';
|
||||||
|
import { SimilaritySliderFormField } from '@/components/similarity-slider';
|
||||||
|
import { SwitchFormField } from '@/components/switch-fom-field';
|
||||||
|
import { TopNFormField } from '@/components/top-n-item';
|
||||||
|
import {
|
||||||
|
FormControl,
|
||||||
|
FormField,
|
||||||
|
FormItem,
|
||||||
|
FormLabel,
|
||||||
|
FormMessage,
|
||||||
|
} from '@/components/ui/form';
|
||||||
|
import { Textarea } from '@/components/ui/textarea';
|
||||||
|
import { UseKnowledgeGraphFormField } from '@/components/use-knowledge-graph-item';
|
||||||
|
import { useTranslate } from '@/hooks/common-hooks';
|
||||||
|
import { useFormContext } from 'react-hook-form';
|
||||||
import { Subhead } from './subhead';
|
import { Subhead } from './subhead';
|
||||||
|
|
||||||
export function ChatPromptEngine() {
|
export function ChatPromptEngine() {
|
||||||
|
const { t } = useTranslate('chat');
|
||||||
|
const form = useFormContext();
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<section>
|
<section>
|
||||||
<Subhead>Prompt Engine</Subhead>
|
<Subhead>Prompt Engine</Subhead>
|
||||||
|
<div className="space-y-8">
|
||||||
|
<FormField
|
||||||
|
control={form.control}
|
||||||
|
name="prompt_config.system"
|
||||||
|
render={({ field }) => (
|
||||||
|
<FormItem>
|
||||||
|
<FormLabel>{t('system')}</FormLabel>
|
||||||
|
<FormControl>
|
||||||
|
<Textarea
|
||||||
|
placeholder="Tell us a little bit about yourself"
|
||||||
|
className="resize-none"
|
||||||
|
{...field}
|
||||||
|
/>
|
||||||
|
</FormControl>
|
||||||
|
<FormMessage />
|
||||||
|
</FormItem>
|
||||||
|
)}
|
||||||
|
/>
|
||||||
|
<SimilaritySliderFormField></SimilaritySliderFormField>
|
||||||
|
<TopNFormField></TopNFormField>
|
||||||
|
<SwitchFormField
|
||||||
|
name={'prompt_config.refine_multiturn'}
|
||||||
|
label={t('multiTurn')}
|
||||||
|
></SwitchFormField>
|
||||||
|
<UseKnowledgeGraphFormField name="prompt_config.use_kg"></UseKnowledgeGraphFormField>
|
||||||
|
<RerankFormFields></RerankFormFields>
|
||||||
|
</div>
|
||||||
</section>
|
</section>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -1,16 +1,49 @@
|
|||||||
|
import { zodResolver } from '@hookform/resolvers/zod';
|
||||||
|
import { FormProvider, useForm } from 'react-hook-form';
|
||||||
|
import { z } from 'zod';
|
||||||
import ChatBasicSetting from './chat-basic-settings';
|
import ChatBasicSetting from './chat-basic-settings';
|
||||||
import { ChatModelSettings } from './chat-model-settings';
|
import { ChatModelSettings } from './chat-model-settings';
|
||||||
import { ChatPromptEngine } from './chat-prompt-engine';
|
import { ChatPromptEngine } from './chat-prompt-engine';
|
||||||
|
import { useChatSettingSchema } from './use-chat-setting-schema';
|
||||||
|
|
||||||
export function AppSettings() {
|
export function AppSettings() {
|
||||||
|
const formSchema = useChatSettingSchema();
|
||||||
|
const form = useForm<z.infer<typeof formSchema>>({
|
||||||
|
resolver: zodResolver(formSchema),
|
||||||
|
defaultValues: {
|
||||||
|
name: '',
|
||||||
|
language: 'English',
|
||||||
|
prompt_config: {
|
||||||
|
quote: true,
|
||||||
|
keyword: false,
|
||||||
|
tts: false,
|
||||||
|
use_kg: false,
|
||||||
|
refine_multiturn: true,
|
||||||
|
},
|
||||||
|
top_n: 8,
|
||||||
|
vector_similarity_weight: 0.2,
|
||||||
|
top_k: 1024,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
function onSubmit(values: z.infer<typeof formSchema>) {
|
||||||
|
console.log(values);
|
||||||
|
}
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<section className="p-6 w-[500px] max-w-[25%]">
|
<section className="py-6 w-[500px] max-w-[25%] ">
|
||||||
<div className="text-2xl font-bold mb-4 text-colors-text-neutral-strong">
|
<div className="text-2xl font-bold mb-4 text-colors-text-neutral-strong px-6">
|
||||||
App settings
|
App settings
|
||||||
</div>
|
</div>
|
||||||
|
<div className="overflow-auto max-h-[88vh] px-6 space-y-6">
|
||||||
|
<FormProvider {...form}>
|
||||||
|
<form onSubmit={form.handleSubmit(onSubmit)}>
|
||||||
<ChatBasicSetting></ChatBasicSetting>
|
<ChatBasicSetting></ChatBasicSetting>
|
||||||
<ChatPromptEngine></ChatPromptEngine>
|
<ChatPromptEngine></ChatPromptEngine>
|
||||||
<ChatModelSettings></ChatModelSettings>
|
<ChatModelSettings></ChatModelSettings>
|
||||||
|
</form>
|
||||||
|
</FormProvider>
|
||||||
|
</div>
|
||||||
</section>
|
</section>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,37 @@
|
|||||||
|
import { useTranslate } from '@/hooks/common-hooks';
|
||||||
|
import { z } from 'zod';
|
||||||
|
|
||||||
|
export function useChatSettingSchema() {
|
||||||
|
const { t } = useTranslate('chat');
|
||||||
|
|
||||||
|
const promptConfigSchema = z.object({
|
||||||
|
quote: z.boolean(),
|
||||||
|
keyword: z.boolean(),
|
||||||
|
tts: z.boolean(),
|
||||||
|
empty_response: z.string().min(1, {
|
||||||
|
message: t('emptyResponse'),
|
||||||
|
}),
|
||||||
|
prologue: z.string().min(1, {}),
|
||||||
|
system: z.string().min(1, { message: t('systemMessage') }),
|
||||||
|
refine_multiturn: z.boolean(),
|
||||||
|
use_kg: z.boolean(),
|
||||||
|
});
|
||||||
|
|
||||||
|
const formSchema = z.object({
|
||||||
|
name: z.string().min(1, { message: t('assistantNameMessage') }),
|
||||||
|
icon: z.array(z.instanceof(File)),
|
||||||
|
language: z.string().min(1, {
|
||||||
|
message: 'Username must be at least 2 characters.',
|
||||||
|
}),
|
||||||
|
description: z.string(),
|
||||||
|
kb_ids: z.array(z.string()).min(0, {
|
||||||
|
message: 'Username must be at least 1 characters.',
|
||||||
|
}),
|
||||||
|
prompt_config: promptConfigSchema,
|
||||||
|
top_n: z.number(),
|
||||||
|
vector_similarity_weight: z.number(),
|
||||||
|
top_k: z.number(),
|
||||||
|
});
|
||||||
|
|
||||||
|
return formSchema;
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user