diff --git a/web/src/components/rerank.tsx b/web/src/components/rerank.tsx index 3ef89b877cc..5e1a0a3178a 100644 --- a/web/src/components/rerank.tsx +++ b/web/src/components/rerank.tsx @@ -1,7 +1,25 @@ import { LlmModelType } from '@/constants/knowledge'; import { useTranslate } from '@/hooks/common-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 = { rerank_id?: string; @@ -18,7 +36,7 @@ export const RerankItem = () => { name={'rerank_id'} tooltip={t('rerankTip')} > - + { + form.resetField(RerankId); + }} + > + + + + {options.map((x) => ( + + {x.label} + {x.options.map((y) => ( + + {y.label} + + ))} + + ))} + + + + + + )} + /> + ); +} + +export function RerankFormFields() { + const { control, watch } = useFormContext(); + const { t } = useTranslate('knowledgeDetails'); + const rerankId = watch(RerankId); + + return ( + <> + + {rerankId && ( + ( + + {t('topK')} + + + + + + )} + /> + )} + + ); +} diff --git a/web/src/components/similarity-slider/index.tsx b/web/src/components/similarity-slider/index.tsx index a23fb2e603c..308b496c795 100644 --- a/web/src/components/similarity-slider/index.tsx +++ b/web/src/components/similarity-slider/index.tsx @@ -1,5 +1,14 @@ import { useTranslate } from '@/hooks/common-hooks'; 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 = { similarity_threshold?: number; @@ -40,3 +49,30 @@ const SimilaritySlider = ({ }; export default SimilaritySlider; + +interface SimilaritySliderFormFieldProps { + name?: string; +} + +export function SimilaritySliderFormField({ + name = 'vector_similarity_weight', +}: SimilaritySliderFormFieldProps) { + const form = useFormContext(); + const { t } = useTranslate('knowledgeDetails'); + + return ( + ( + + {t('vectorSimilarityWeight')} + + + + + + )} + /> + ); +} diff --git a/web/src/pages/next-chats/chat/app-settings/switch-fom-field.tsx b/web/src/components/switch-fom-field.tsx similarity index 100% rename from web/src/pages/next-chats/chat/app-settings/switch-fom-field.tsx rename to web/src/components/switch-fom-field.tsx diff --git a/web/src/components/top-n-item.tsx b/web/src/components/top-n-item.tsx index 86afdb82348..8c1c52d589f 100644 --- a/web/src/components/top-n-item.tsx +++ b/web/src/components/top-n-item.tsx @@ -1,5 +1,14 @@ import { useTranslate } from '@/hooks/common-hooks'; 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 = { top_n?: number; @@ -26,3 +35,28 @@ const TopNItem = ({ initialValue = 8, max = 30 }: IProps) => { }; export default TopNItem; + +interface SimilaritySliderFormFieldProps { + max?: number; +} + +export function TopNFormField({ max = 30 }: SimilaritySliderFormFieldProps) { + const form = useFormContext(); + const { t } = useTranslate('chat'); + + return ( + ( + + {t('topN')} + + + + + + )} + /> + ); +} diff --git a/web/src/components/use-knowledge-graph-item.tsx b/web/src/components/use-knowledge-graph-item.tsx index b5da3dc1a2e..5cf8914752c 100644 --- a/web/src/components/use-knowledge-graph-item.tsx +++ b/web/src/components/use-knowledge-graph-item.tsx @@ -1,5 +1,6 @@ import { Form, Switch } from 'antd'; import { useTranslation } from 'react-i18next'; +import { SwitchFormField } from './switch-fom-field'; type IProps = { filedName: string[]; @@ -19,3 +20,20 @@ export function UseKnowledgeGraphItem({ filedName }: IProps) { ); } + +interface UseKnowledgeGraphFormFieldProps { + name: string; +} + +export function UseKnowledgeGraphFormField({ + name, +}: UseKnowledgeGraphFormFieldProps) { + const { t } = useTranslation(); + + return ( + + ); +} diff --git a/web/src/pages/next-chats/chat/app-settings/chat-basic-settings.tsx b/web/src/pages/next-chats/chat/app-settings/chat-basic-settings.tsx index 5b19b470947..afc2f1d805c 100644 --- a/web/src/pages/next-chats/chat/app-settings/chat-basic-settings.tsx +++ b/web/src/pages/next-chats/chat/app-settings/chat-basic-settings.tsx @@ -1,13 +1,9 @@ '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 { KnowledgeBaseFormField } from '@/components/knowledge-base-item'; +import { SwitchFormField } from '@/components/switch-fom-field'; import { - Form, FormControl, FormField, FormItem, @@ -16,148 +12,107 @@ import { } from '@/components/ui/form'; import { Input } from '@/components/ui/input'; import { useTranslate } from '@/hooks/common-hooks'; +import { useFormContext } from 'react-hook-form'; import { Subhead } from './subhead'; -import { SwitchFormField } from './switch-fom-field'; export default function ChatBasicSetting() { 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(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>({ - resolver: zodResolver(formSchema), - defaultValues: { - name: '', - language: 'English', - prompt_config: { - quote: true, - keyword: false, - tts: false, - }, - }, - }); - - function onSubmit(values: z.infer) { - console.log(values); - } + const form = useFormContext(); return (
Basic settings -
- - ( -
- - {t('assistantAvatar')} - - - - - -
- )} - /> - ( - - {t('assistantName')} - - - - - - )} - /> - ( - - {t('description')} - - - - - - )} - /> - ( - - {t('emptyResponse')} - - - - - - )} - /> - ( - - {t('setAnOpener')} +
+ ( +
+ + {t('assistantAvatar')} - + - )} - /> - - - - - - +
+ )} + /> + ( + + {t('assistantName')} + + + + + + )} + /> + ( + + {t('description')} + + + + + + )} + /> + ( + + {t('emptyResponse')} + + + + + + )} + /> + ( + + {t('setAnOpener')} + + + + + + )} + /> + + + + +
); } diff --git a/web/src/pages/next-chats/chat/app-settings/chat-prompt-engine.tsx b/web/src/pages/next-chats/chat/app-settings/chat-prompt-engine.tsx index 75491825a9c..738004537f1 100644 --- a/web/src/pages/next-chats/chat/app-settings/chat-prompt-engine.tsx +++ b/web/src/pages/next-chats/chat/app-settings/chat-prompt-engine.tsx @@ -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'; export function ChatPromptEngine() { + const { t } = useTranslate('chat'); + const form = useFormContext(); + return (
Prompt Engine +
+ ( + + {t('system')} + +