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)
This commit is contained in:
balibabu 2025-02-24 14:22:15 +08:00 committed by GitHub
parent ec96426c00
commit 1137b04154
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
5 changed files with 42 additions and 50 deletions

View File

@ -3,12 +3,20 @@ export enum MessageType {
User = 'user', User = 'user',
} }
export enum ChatVariableEnabledField {
TemperatureEnabled = 'temperatureEnabled',
TopPEnabled = 'topPEnabled',
PresencePenaltyEnabled = 'presencePenaltyEnabled',
FrequencyPenaltyEnabled = 'frequencyPenaltyEnabled',
MaxTokensEnabled = 'maxTokensEnabled',
}
export const variableEnabledFieldMap = { export const variableEnabledFieldMap = {
temperatureEnabled: 'temperature', [ChatVariableEnabledField.TemperatureEnabled]: 'temperature',
topPEnabled: 'top_p', [ChatVariableEnabledField.TopPEnabled]: 'top_p',
presencePenaltyEnabled: 'presence_penalty', [ChatVariableEnabledField.PresencePenaltyEnabled]: 'presence_penalty',
frequencyPenaltyEnabled: 'frequency_penalty', [ChatVariableEnabledField.FrequencyPenaltyEnabled]: 'frequency_penalty',
maxTokensEnabled: 'max_tokens', [ChatVariableEnabledField.MaxTokensEnabled]: 'max_tokens',
}; };
export enum SharedFrom { export enum SharedFrom {

View File

@ -3,8 +3,12 @@ import { useEffect } from 'react';
import { ISegmentedContentProps } from '../interface'; import { ISegmentedContentProps } from '../interface';
import LlmSettingItems from '@/components/llm-setting-items'; 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 { Variable } from '@/interfaces/database/chat';
import { setInitialChatVariableEnabledFieldValue } from '@/utils/chat';
import styles from './index.less'; import styles from './index.less';
const ModelSetting = ({ const ModelSetting = ({
@ -23,7 +27,9 @@ const ModelSetting = ({
>((pre, field) => { >((pre, field) => {
pre[field] = pre[field] =
initialLlmSetting === undefined initialLlmSetting === undefined
? true ? setInitialChatVariableEnabledFieldValue(
field as ChatVariableEnabledField,
)
: !!initialLlmSetting[ : !!initialLlmSetting[
variableEnabledFieldMap[ variableEnabledFieldMap[
field as keyof typeof variableEnabledFieldMap field as keyof typeof variableEnabledFieldMap

View File

@ -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 i18n from '@/locales/config';
import { setInitialChatVariableEnabledFieldValue } from '@/utils/chat';
// DuckDuckGo's channel options // DuckDuckGo's channel options
export enum Channel { export enum Channel {
@ -403,7 +407,9 @@ export const initialBeginValues = {
export const variableCheckBoxFieldMap = Object.keys( export const variableCheckBoxFieldMap = Object.keys(
variableEnabledFieldMap, variableEnabledFieldMap,
).reduce<Record<string, boolean>>((pre, cur) => { ).reduce<Record<string, boolean>>((pre, cur) => {
pre[cur] = true; pre[cur] = setInitialChatVariableEnabledFieldValue(
cur as ChatVariableEnabledField,
);
return pre; return pre;
}, {}); }, {});

View File

@ -13,22 +13,17 @@ import React, {
useState, useState,
} from 'react'; } from 'react';
// import { shallow } from 'zustand/shallow'; // import { shallow } from 'zustand/shallow';
import { variableEnabledFieldMap } from '@/constants/chat'; import { settledModelVariableMap } from '@/constants/knowledge';
import {
ModelVariableType,
settledModelVariableMap,
} from '@/constants/knowledge';
import { useFetchModelId } from '@/hooks/logic-hooks'; import { useFetchModelId } from '@/hooks/logic-hooks';
import { Variable } from '@/interfaces/database/chat';
import { import {
ICategorizeForm, ICategorizeForm,
IRelevantForm, IRelevantForm,
ISwitchForm, ISwitchForm,
RAGFlowNodeType, RAGFlowNodeType,
} from '@/interfaces/database/flow'; } from '@/interfaces/database/flow';
import { FormInstance, message } from 'antd'; import { message } from 'antd';
import { humanId } from 'human-id'; import { humanId } from 'human-id';
import { get, isEmpty, lowerFirst, pick } from 'lodash'; import { get, lowerFirst } from 'lodash';
import trim from 'lodash/trim'; import trim from 'lodash/trim';
import { useTranslation } from 'react-i18next'; import { useTranslation } from 'react-i18next';
import { v4 as uuid } from 'uuid'; import { v4 as uuid } from 'uuid';
@ -291,38 +286,6 @@ export const useHandleFormValuesChange = (id?: string) => {
return { handleValuesChange }; return { handleValuesChange };
}; };
export const useSetLlmSetting = (
form?: FormInstance,
formData?: Record<string, any>,
) => {
const initialLlmSetting = pick(
formData,
Object.values(variableEnabledFieldMap),
);
useEffect(() => {
const switchBoxValues = Object.keys(variableEnabledFieldMap).reduce<
Record<string, boolean>
>((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 = () => { export const useValidateConnection = () => {
const { edges, getOperatorTypeFromId, getParentIdById } = useGraphStore( const { edges, getOperatorTypeFromId, getParentIdById } = useGraphStore(
(state) => state, (state) => state,

View File

@ -1,4 +1,7 @@
import { EmptyConversationId } from '@/constants/chat'; import {
ChatVariableEnabledField,
EmptyConversationId,
} from '@/constants/chat';
import { Message } from '@/interfaces/database/chat'; import { Message } from '@/interfaces/database/chat';
import { IMessage } from '@/pages/chat/interface'; import { IMessage } from '@/pages/chat/interface';
import { omit } from 'lodash'; import { omit } from 'lodash';
@ -57,3 +60,9 @@ export function replaceThinkToSection(text: string = '') {
return result; return result;
} }
export function setInitialChatVariableEnabledFieldValue(
field: ChatVariableEnabledField,
) {
return field !== ChatVariableEnabledField.MaxTokensEnabled;
}