From 7059ec22987141cc1127fb6808e3bc5a6b466406 Mon Sep 17 00:00:00 2001 From: balibabu Date: Tue, 30 Apr 2024 11:27:10 +0800 Subject: [PATCH] fix: fixed the issue that ModelSetting could not be saved #614 (#617) ### What problem does this PR solve? fix: fixed the issue that ModelSetting could not be saved #614 ### Type of change - [x] Bug Fix (non-breaking change which fixes an issue) --- web/src/interfaces/database/chat.ts | 12 +- .../chat/chat-configuration-modal/index.tsx | 3 + .../model-setting.tsx | 281 +++++++++++------- 3 files changed, 179 insertions(+), 117 deletions(-) diff --git a/web/src/interfaces/database/chat.ts b/web/src/interfaces/database/chat.ts index a2c53032e8..025ce2ad14 100644 --- a/web/src/interfaces/database/chat.ts +++ b/web/src/interfaces/database/chat.ts @@ -21,11 +21,11 @@ export interface LlmSetting { } export interface Variable { - frequency_penalty: number; - max_tokens: number; - presence_penalty: number; - temperature: number; - top_p: number; + frequency_penalty?: number; + max_tokens?: number; + presence_penalty?: number; + temperature?: number; + top_p?: number; } export interface IDialog { @@ -38,7 +38,7 @@ export interface IDialog { kb_names: string[]; language: string; llm_id: string; - llm_setting: LlmSetting; + llm_setting: Variable; llm_setting_type: string; name: string; prompt_config: PromptConfig; diff --git a/web/src/pages/chat/chat-configuration-modal/index.tsx b/web/src/pages/chat/chat-configuration-modal/index.tsx index 8ddec396f7..d025ba1608 100644 --- a/web/src/pages/chat/chat-configuration-modal/index.tsx +++ b/web/src/pages/chat/chat-configuration-modal/index.tsx @@ -181,6 +181,9 @@ const ChatConfigurationModal = ({ key={key} show={key === value} form={form} + {...(key === ConfigurationSegmented.ModelSetting + ? { initialLlmSetting: initialDialog.llm_setting, visible } + : {})} {...(key === ConfigurationSegmented.PromptEngine ? { ref: promptEngineRef } : {})} diff --git a/web/src/pages/chat/chat-configuration-modal/model-setting.tsx b/web/src/pages/chat/chat-configuration-modal/model-setting.tsx index 6f2ec7745d..9d3471a1e6 100644 --- a/web/src/pages/chat/chat-configuration-modal/model-setting.tsx +++ b/web/src/pages/chat/chat-configuration-modal/model-setting.tsx @@ -11,10 +11,19 @@ import { ISegmentedContentProps } from '../interface'; import { useTranslate } from '@/hooks/commonHooks'; import { useFetchLlmList, useSelectLlmOptions } from '@/hooks/llmHooks'; +import { Variable } from '@/interfaces/database/chat'; import { variableEnabledFieldMap } from '../constants'; import styles from './index.less'; -const ModelSetting = ({ show, form }: ISegmentedContentProps) => { +const ModelSetting = ({ + show, + form, + initialLlmSetting, + visible, +}: ISegmentedContentProps & { + initialLlmSetting?: Variable; + visible?: boolean; +}) => { const { t } = useTranslate('chat'); const parameterOptions = Object.values(ModelVariableType).map((x) => ({ label: t(camelCase(x)), @@ -29,14 +38,23 @@ const ModelSetting = ({ show, form }: ISegmentedContentProps) => { }; useEffect(() => { - const values = Object.keys(variableEnabledFieldMap).reduce< - Record - >((pre, field) => { - pre[field] = true; - return pre; - }, {}); - form.setFieldsValue(values); - }, [form]); + if (visible) { + const values = Object.keys(variableEnabledFieldMap).reduce< + Record + >((pre, field) => { + pre[field] = + initialLlmSetting === undefined + ? true + : !!initialLlmSetting[ + variableEnabledFieldMap[ + field as keyof typeof variableEnabledFieldMap + ] as keyof Variable + ]; + return pre; + }, {}); + form.setFieldsValue(values); + } + }, [form, initialLlmSetting, visible]); useFetchLlmList(LlmModelType.Chat); @@ -60,7 +78,6 @@ const ModelSetting = ({ show, form }: ISegmentedContentProps) => { name="parameters" tooltip={t('freedomTip')} initialValue={ModelVariableType.Precise} - // rules={[{ required: true, message: 'Please input!' }]} > options={parameterOptions} @@ -76,26 +93,33 @@ const ModelSetting = ({ show, form }: ISegmentedContentProps) => { > - - - - - - - + + {({ getFieldValue }) => { + const disabled = !getFieldValue('temperatureEnabled'); + return ( + <> + + + + + + + + + + ); + }} @@ -104,26 +128,33 @@ const ModelSetting = ({ show, form }: ISegmentedContentProps) => { - - - - - - - + + {({ getFieldValue }) => { + const disabled = !getFieldValue('topPEnabled'); + return ( + <> + + + + + + + + + + ); + }} @@ -136,26 +167,36 @@ const ModelSetting = ({ show, form }: ISegmentedContentProps) => { > - - - - - - - + + {({ getFieldValue }) => { + const disabled = !getFieldValue('presencePenaltyEnabled'); + return ( + <> + + + + + + + + + + ); + }} @@ -171,28 +212,39 @@ const ModelSetting = ({ show, form }: ISegmentedContentProps) => { > - - - - - - - + + {({ getFieldValue }) => { + const disabled = !getFieldValue('frequencyPenaltyEnabled'); + return ( + <> + + + + + + + + + + ); + }} @@ -201,25 +253,32 @@ const ModelSetting = ({ show, form }: ISegmentedContentProps) => { - - - - - - - + + {({ getFieldValue }) => { + const disabled = !getFieldValue('maxTokensEnabled'); + + return ( + <> + + + + + + + + + + ); + }}