From 1137b04154a4b0c19ec279552719987388e67e06 Mon Sep 17 00:00:00 2001 From: balibabu Date: Mon, 24 Feb 2025 14:22:15 +0800 Subject: [PATCH] Feat: Disable Max_token by default #5283 (#5290) ### What problem does this PR solve? Feat: Disable Max_token by default #5283 ### Type of change - [x] New Feature (non-breaking change which adds functionality) --- web/src/constants/chat.ts | 18 +++++--- .../model-setting.tsx | 10 ++++- web/src/pages/flow/constant.tsx | 10 ++++- web/src/pages/flow/hooks.tsx | 43 ++----------------- web/src/utils/chat.ts | 11 ++++- 5 files changed, 42 insertions(+), 50 deletions(-) diff --git a/web/src/constants/chat.ts b/web/src/constants/chat.ts index 977c727c4..53f99b15a 100644 --- a/web/src/constants/chat.ts +++ b/web/src/constants/chat.ts @@ -3,12 +3,20 @@ export enum MessageType { User = 'user', } +export enum ChatVariableEnabledField { + TemperatureEnabled = 'temperatureEnabled', + TopPEnabled = 'topPEnabled', + PresencePenaltyEnabled = 'presencePenaltyEnabled', + FrequencyPenaltyEnabled = 'frequencyPenaltyEnabled', + MaxTokensEnabled = 'maxTokensEnabled', +} + export const variableEnabledFieldMap = { - temperatureEnabled: 'temperature', - topPEnabled: 'top_p', - presencePenaltyEnabled: 'presence_penalty', - frequencyPenaltyEnabled: 'frequency_penalty', - maxTokensEnabled: 'max_tokens', + [ChatVariableEnabledField.TemperatureEnabled]: 'temperature', + [ChatVariableEnabledField.TopPEnabled]: 'top_p', + [ChatVariableEnabledField.PresencePenaltyEnabled]: 'presence_penalty', + [ChatVariableEnabledField.FrequencyPenaltyEnabled]: 'frequency_penalty', + [ChatVariableEnabledField.MaxTokensEnabled]: 'max_tokens', }; export enum SharedFrom { 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 6c0c9d13b..a890bbbbe 100644 --- a/web/src/pages/chat/chat-configuration-modal/model-setting.tsx +++ b/web/src/pages/chat/chat-configuration-modal/model-setting.tsx @@ -3,8 +3,12 @@ import { useEffect } from 'react'; import { ISegmentedContentProps } from '../interface'; import LlmSettingItems from '@/components/llm-setting-items'; -import { variableEnabledFieldMap } from '@/constants/chat'; +import { + ChatVariableEnabledField, + variableEnabledFieldMap, +} from '@/constants/chat'; import { Variable } from '@/interfaces/database/chat'; +import { setInitialChatVariableEnabledFieldValue } from '@/utils/chat'; import styles from './index.less'; const ModelSetting = ({ @@ -23,7 +27,9 @@ const ModelSetting = ({ >((pre, field) => { pre[field] = initialLlmSetting === undefined - ? true + ? setInitialChatVariableEnabledFieldValue( + field as ChatVariableEnabledField, + ) : !!initialLlmSetting[ variableEnabledFieldMap[ field as keyof typeof variableEnabledFieldMap diff --git a/web/src/pages/flow/constant.tsx b/web/src/pages/flow/constant.tsx index ba34e7a2c..132f8ff74 100644 --- a/web/src/pages/flow/constant.tsx +++ b/web/src/pages/flow/constant.tsx @@ -30,8 +30,12 @@ import { ReactComponent as YahooFinanceIcon } from '@/assets/svg/yahoo-finance.s // 邮件功能 -import { variableEnabledFieldMap } from '@/constants/chat'; +import { + ChatVariableEnabledField, + variableEnabledFieldMap, +} from '@/constants/chat'; import i18n from '@/locales/config'; +import { setInitialChatVariableEnabledFieldValue } from '@/utils/chat'; // DuckDuckGo's channel options export enum Channel { @@ -403,7 +407,9 @@ export const initialBeginValues = { export const variableCheckBoxFieldMap = Object.keys( variableEnabledFieldMap, ).reduce>((pre, cur) => { - pre[cur] = true; + pre[cur] = setInitialChatVariableEnabledFieldValue( + cur as ChatVariableEnabledField, + ); return pre; }, {}); diff --git a/web/src/pages/flow/hooks.tsx b/web/src/pages/flow/hooks.tsx index eecd3b4cd..0430170a0 100644 --- a/web/src/pages/flow/hooks.tsx +++ b/web/src/pages/flow/hooks.tsx @@ -13,22 +13,17 @@ import React, { useState, } from 'react'; // import { shallow } from 'zustand/shallow'; -import { variableEnabledFieldMap } from '@/constants/chat'; -import { - ModelVariableType, - settledModelVariableMap, -} from '@/constants/knowledge'; +import { settledModelVariableMap } from '@/constants/knowledge'; import { useFetchModelId } from '@/hooks/logic-hooks'; -import { Variable } from '@/interfaces/database/chat'; import { ICategorizeForm, IRelevantForm, ISwitchForm, RAGFlowNodeType, } from '@/interfaces/database/flow'; -import { FormInstance, message } from 'antd'; +import { message } from 'antd'; import { humanId } from 'human-id'; -import { get, isEmpty, lowerFirst, pick } from 'lodash'; +import { get, lowerFirst } from 'lodash'; import trim from 'lodash/trim'; import { useTranslation } from 'react-i18next'; import { v4 as uuid } from 'uuid'; @@ -291,38 +286,6 @@ export const useHandleFormValuesChange = (id?: string) => { return { handleValuesChange }; }; -export const useSetLlmSetting = ( - form?: FormInstance, - formData?: Record, -) => { - const initialLlmSetting = pick( - formData, - Object.values(variableEnabledFieldMap), - ); - useEffect(() => { - const switchBoxValues = Object.keys(variableEnabledFieldMap).reduce< - Record - >((pre, field) => { - pre[field] = isEmpty(initialLlmSetting) - ? true - : !!initialLlmSetting[ - variableEnabledFieldMap[ - field as keyof typeof variableEnabledFieldMap - ] as keyof Variable - ]; - return pre; - }, {}); - let otherValues = settledModelVariableMap[ModelVariableType.Precise]; - if (!isEmpty(initialLlmSetting)) { - otherValues = initialLlmSetting; - } - form?.setFieldsValue({ - ...switchBoxValues, - ...otherValues, - }); - }, [form, initialLlmSetting]); -}; - export const useValidateConnection = () => { const { edges, getOperatorTypeFromId, getParentIdById } = useGraphStore( (state) => state, diff --git a/web/src/utils/chat.ts b/web/src/utils/chat.ts index 7a4f66e79..245a9f976 100644 --- a/web/src/utils/chat.ts +++ b/web/src/utils/chat.ts @@ -1,4 +1,7 @@ -import { EmptyConversationId } from '@/constants/chat'; +import { + ChatVariableEnabledField, + EmptyConversationId, +} from '@/constants/chat'; import { Message } from '@/interfaces/database/chat'; import { IMessage } from '@/pages/chat/interface'; import { omit } from 'lodash'; @@ -57,3 +60,9 @@ export function replaceThinkToSection(text: string = '') { return result; } + +export function setInitialChatVariableEnabledFieldValue( + field: ChatVariableEnabledField, +) { + return field !== ChatVariableEnabledField.MaxTokensEnabled; +}