浏览代码

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)
tags/v0.17.0
balibabu 8 个月前
父节点
当前提交
1137b04154
没有帐户链接到提交者的电子邮件

+ 13
- 5
web/src/constants/chat.ts 查看文件

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',
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 { export enum SharedFrom {

+ 8
- 2
web/src/pages/chat/chat-configuration-modal/model-setting.tsx 查看文件

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 = ({
>((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

+ 8
- 2
web/src/pages/flow/constant.tsx 查看文件



// 邮件功能 // 邮件功能


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 {
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;
}, {}); }, {});



+ 3
- 40
web/src/pages/flow/hooks.tsx 查看文件

useState, useState,
} from 'react'; } from 'react';
// import { shallow } from 'zustand/shallow'; // 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 { 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';
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,

+ 10
- 1
web/src/utils/chat.ts 查看文件

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';


return result; return result;
} }

export function setInitialChatVariableEnabledFieldValue(
field: ChatVariableEnabledField,
) {
return field !== ChatVariableEnabledField.MaxTokensEnabled;
}

正在加载...
取消
保存