From 9098efb8aa982bcf9cdf5f45773e227dc2a8b91b Mon Sep 17 00:00:00 2001 From: balibabu Date: Wed, 13 Aug 2025 10:26:26 +0800 Subject: [PATCH] Feat: Fixed the issue where some fields in the chat configuration could not be displayed #3221 (#9430) ### What problem does this PR solve? Feat: Fixed the issue where some fields in the chat configuration could not be displayed #3221 ### Type of change - [x] New Feature (non-breaking change which adds functionality) --- api/db/services/dialog_service.py | 1 + web/src/components/llm-setting-items/next.tsx | 34 +++---- .../components/llm-setting-items/slider.tsx | 7 +- .../llm-setting-items/use-watch-change.ts | 11 ++- web/src/components/rerank.tsx | 11 ++- .../components/similarity-slider/index.tsx | 22 ++++- .../components/slider-input-form-field.tsx | 11 +-- web/src/components/top-n-item.tsx | 5 ++ web/src/locales/en.ts | 4 +- web/src/locales/zh.ts | 2 +- .../chat/app-settings/chat-model-settings.tsx | 30 ------- .../chat/app-settings/chat-prompt-engine.tsx | 8 +- .../chat/app-settings/chat-settings.tsx | 75 ++++++++++------ .../chat/app-settings/dynamic-variable.tsx | 89 +++++++++++++++++++ .../app-settings/use-chat-setting-schema.tsx | 25 ++++-- web/src/pages/next-chats/chat/sessions.tsx | 2 +- 16 files changed, 227 insertions(+), 110 deletions(-) create mode 100644 web/src/pages/next-chats/chat/app-settings/dynamic-variable.tsx diff --git a/api/db/services/dialog_service.py b/api/db/services/dialog_service.py index cbbc8ba9e..62372c7c3 100644 --- a/api/db/services/dialog_service.py +++ b/api/db/services/dialog_service.py @@ -121,6 +121,7 @@ class DialogService(CommonService): cls.model.do_refer, cls.model.rerank_id, cls.model.kb_ids, + cls.model.icon, cls.model.status, User.nickname, User.avatar.alias("tenant_avatar"), diff --git a/web/src/components/llm-setting-items/next.tsx b/web/src/components/llm-setting-items/next.tsx index ac582657c..51a332dd4 100644 --- a/web/src/components/llm-setting-items/next.tsx +++ b/web/src/components/llm-setting-items/next.tsx @@ -30,15 +30,16 @@ interface LlmSettingFieldItemsProps { export const LlmSettingSchema = { llm_id: z.string(), - temperature: z.coerce.number(), - top_p: z.string(), - presence_penalty: z.coerce.number(), - frequency_penalty: z.coerce.number(), - temperatureEnabled: z.boolean(), - topPEnabled: z.boolean(), - presencePenaltyEnabled: z.boolean(), - frequencyPenaltyEnabled: z.boolean(), - maxTokensEnabled: z.boolean(), + temperature: z.coerce.number().optional(), + top_p: z.number().optional(), + presence_penalty: z.coerce.number().optional(), + frequency_penalty: z.coerce.number().optional(), + temperatureEnabled: z.boolean().optional(), + topPEnabled: z.boolean().optional(), + presencePenaltyEnabled: z.boolean().optional(), + frequencyPenaltyEnabled: z.boolean().optional(), + maxTokensEnabled: z.boolean().optional(), + max_tokens: z.number().optional(), }; export function LlmSettingFieldItems({ @@ -53,13 +54,6 @@ export function LlmSettingFieldItems({ LlmModelType.Image2text, ]); - const handleChange = useHandleFreedomChange(); - - const parameterOptions = Object.values(ModelVariableType).map((x) => ({ - label: t(camelCase(x)), - value: x, - })); - const getFieldWithPrefix = useCallback( (name: string) => { return prefix ? `${prefix}.${name}` : name; @@ -67,6 +61,13 @@ export function LlmSettingFieldItems({ [prefix], ); + const handleChange = useHandleFreedomChange(getFieldWithPrefix); + + const parameterOptions = Object.values(ModelVariableType).map((x) => ({ + label: t(camelCase(x)), + value: x, + })); + return (
{t('model')} diff --git a/web/src/components/llm-setting-items/slider.tsx b/web/src/components/llm-setting-items/slider.tsx index a9137b353..baea5ea31 100644 --- a/web/src/components/llm-setting-items/slider.tsx +++ b/web/src/components/llm-setting-items/slider.tsx @@ -9,7 +9,7 @@ import { FormLabel, FormMessage, } from '../ui/form'; -import { Input } from '../ui/input'; +import { NumberInput } from '../ui/input'; import { Switch } from '../ui/switch'; type SliderInputSwitchFormFieldProps = { @@ -73,15 +73,14 @@ export function SliderInputSwitchFormField({ > - + >
diff --git a/web/src/components/llm-setting-items/use-watch-change.ts b/web/src/components/llm-setting-items/use-watch-change.ts index bf3fa595c..5731a98ef 100644 --- a/web/src/components/llm-setting-items/use-watch-change.ts +++ b/web/src/components/llm-setting-items/use-watch-change.ts @@ -4,7 +4,9 @@ import useGraphStore from '@/pages/agent/store'; import { useCallback, useContext } from 'react'; import { useFormContext } from 'react-hook-form'; -export function useHandleFreedomChange() { +export function useHandleFreedomChange( + getFieldWithPrefix: (name: string) => string, +) { const form = useFormContext(); const node = useContext(AgentFormContext); const updateNodeForm = useGraphStore((state) => state.updateNodeForm); @@ -25,13 +27,14 @@ export function useHandleFreedomChange() { for (const key in values) { if (Object.prototype.hasOwnProperty.call(values, key)) { - const element = values[key]; + const realKey = getFieldWithPrefix(key); + const element = values[key as keyof typeof values]; - form.setValue(key, element); + form.setValue(realKey, element); } } }, - [form, node, updateNodeForm], + [form, getFieldWithPrefix, node?.id, updateNodeForm], ); return handleChange; diff --git a/web/src/components/rerank.tsx b/web/src/components/rerank.tsx index c872a9238..ca7f3bc2c 100644 --- a/web/src/components/rerank.tsx +++ b/web/src/components/rerank.tsx @@ -5,6 +5,7 @@ import { Select as AntSelect, Form, message, Slider } from 'antd'; import { useCallback } from 'react'; import { useFormContext } from 'react-hook-form'; import { z } from 'zod'; +import { SelectWithSearch } from './originui/select-with-search'; import { SliderInputFormField } from './slider-input-form-field'; import { FormControl, @@ -13,7 +14,6 @@ import { FormLabel, FormMessage, } from './ui/form'; -import { RAGFlowSelect } from './ui/select'; type FieldType = { rerank_id?: string; @@ -109,11 +109,11 @@ function RerankFormField() { {t('rerankModel')} - + > @@ -122,6 +122,11 @@ function RerankFormField() { ); } +export const rerankFormSchema = { + [RerankId]: z.string().optional(), + top_k: z.coerce.number().optional(), +}; + export function RerankFormFields() { const { watch } = useFormContext(); const { t } = useTranslate('knowledgeDetails'); diff --git a/web/src/components/similarity-slider/index.tsx b/web/src/components/similarity-slider/index.tsx index 4dbab5e74..796d2415e 100644 --- a/web/src/components/similarity-slider/index.tsx +++ b/web/src/components/similarity-slider/index.tsx @@ -61,11 +61,20 @@ export const keywordsSimilarityWeightSchema = { keywords_similarity_weight: z.number(), }; +export const vectorSimilarityWeightSchema = { + vector_similarity_weight: z.number(), +}; + +export const initialVectorSimilarityWeightValue = { + vector_similarity_weight: 0.3, +}; + export function SimilaritySliderFormField({ vectorSimilarityWeightName = 'vector_similarity_weight', isTooltipShown, }: SimilaritySliderFormFieldProps) { const { t } = useTranslate('knowledgeDetails'); + const isVector = vectorSimilarityWeightName === 'vector_similarity_weight'; return ( <> @@ -78,10 +87,19 @@ export function SimilaritySliderFormField({ > ); diff --git a/web/src/components/slider-input-form-field.tsx b/web/src/components/slider-input-form-field.tsx index 7e08a9c8d..5986a3075 100644 --- a/web/src/components/slider-input-form-field.tsx +++ b/web/src/components/slider-input-form-field.tsx @@ -10,7 +10,7 @@ import { FormLabel, FormMessage, } from './ui/form'; -import { Input } from './ui/input'; +import { NumberInput } from './ui/input'; export type FormLayoutType = { layout?: FormLayout; @@ -79,19 +79,14 @@ export function SliderInputFormField({ > - { - const value = ev.target.value; - field.onChange(value === '' ? 0 : Number(value)); // convert to number - }} // defaultValue={defaultValue} - > + > diff --git a/web/src/components/top-n-item.tsx b/web/src/components/top-n-item.tsx index f433771d2..c826c3700 100644 --- a/web/src/components/top-n-item.tsx +++ b/web/src/components/top-n-item.tsx @@ -1,5 +1,6 @@ import { useTranslate } from '@/hooks/common-hooks'; import { Form, Slider } from 'antd'; +import { z } from 'zod'; import { SliderInputFormField } from './slider-input-form-field'; type FieldType = { @@ -32,6 +33,10 @@ interface SimilaritySliderFormFieldProps { max?: number; } +export const topnSchema = { + top_n: z.number().optional(), +}; + export function TopNFormField({ max = 30 }: SimilaritySliderFormFieldProps) { const { t } = useTranslate('chat'); diff --git a/web/src/locales/en.ts b/web/src/locales/en.ts index df297aaa8..3250a3674 100644 --- a/web/src/locales/en.ts +++ b/web/src/locales/en.ts @@ -124,9 +124,11 @@ export default { similarityThreshold: 'Similarity threshold', similarityThresholdTip: 'RAGFlow employs either a combination of weighted keyword similarity and weighted vector cosine similarity, or a combination of weighted keyword similarity and weighted reranking score during retrieval. This parameter sets the threshold for similarities between the user query and chunks. Any chunk with a similarity score below this threshold will be excluded from the results. By default, the threshold is set to 0.2. This means that only chunks with hybrid similarity score of 20 or higher will be retrieved.', - vectorSimilarityWeight: 'Keyword similarity weight', + vectorSimilarityWeight: 'Vector similarity weight', vectorSimilarityWeightTip: 'This sets the weight of keyword similarity in the combined similarity score, either used with vector cosine similarity or with reranking score. The total of the two weights must equal 1.0.', + keywordSimilarityWeight: 'Keyword similarity weight', + keywordSimilarityWeightTip: '', testText: 'Test text', testTextPlaceholder: 'Input your question here!', testingLabel: 'Testing', diff --git a/web/src/locales/zh.ts b/web/src/locales/zh.ts index 031e22496..833d5d6b0 100644 --- a/web/src/locales/zh.ts +++ b/web/src/locales/zh.ts @@ -115,7 +115,7 @@ export default { similarityThreshold: '相似度阈值', similarityThresholdTip: '我们使用混合相似度得分来评估两行文本之间的距离。 它是加权关键词相似度和向量余弦相似度。 如果查询和块之间的相似度小于此阈值,则该块将被过滤掉。默认设置为 0.2,也就是说文本块的混合相似度得分至少 20 才会被召回。', - vectorSimilarityWeight: '关键字相似度权重', + vectorSimilarityWeight: '相似度相似度权重', vectorSimilarityWeightTip: '我们使用混合相似性评分来评估两行文本之间的距离。它是加权关键字相似性和矢量余弦相似性或rerank得分(0〜1)。两个权重的总和为1.0。', testText: '测试文本', diff --git a/web/src/pages/next-chats/chat/app-settings/chat-model-settings.tsx b/web/src/pages/next-chats/chat/app-settings/chat-model-settings.tsx index c8d54d03a..99629c436 100644 --- a/web/src/pages/next-chats/chat/app-settings/chat-model-settings.tsx +++ b/web/src/pages/next-chats/chat/app-settings/chat-model-settings.tsx @@ -1,38 +1,8 @@ import { LlmSettingFieldItems } from '@/components/llm-setting-items/next'; -import { - FormControl, - FormField, - FormItem, - FormLabel, - FormMessage, -} from '@/components/ui/form'; -import { Textarea } from '@/components/ui/textarea'; -import { useTranslate } from '@/hooks/common-hooks'; -import { useFormContext } from 'react-hook-form'; export function ChatModelSettings() { - const { t } = useTranslate('chat'); - const form = useFormContext(); - return (
- ( - - {t('system')} - -