Skip to content

🤯 LobeHub - Super-Agents on Your Team. Add super-agents to the chats your team already uses.They take on work by themselves and get better every week.

🐛 fix(ChatInput): add missing MaxTokens setting to params popover (#11412)

zerone0x3db438940b85
diff --git a/src/features/ChatInput/ActionBar/Params/Controls.tsx b/src/features/ChatInput/ActionBar/Params/Controls.tsx
index ea11fabaedc..0aadb6ce2ed 100644
--- a/src/features/ChatInput/ActionBar/Params/Controls.tsx
+++ b/src/features/ChatInput/ActionBar/Params/Controls.tsx
@@ -1,6 +1,6 @@
-import { Form, type FormItemProps, Tag } from '@lobehub/ui';
+import { Form, type FormItemProps, SliderWithInput, Tag } from '@lobehub/ui';
import { Checkbox, Flexbox } from '@lobehub/ui';
-import { Form as AntdForm } from 'antd';
+import { Form as AntdForm, Switch } from 'antd';
import { createStaticStyles } from 'antd-style';
import { debounce } from 'es-toolkit/compat';
import isEqual from 'fast-deep-equal';
@@ -151,6 +151,7 @@ const Controls = memo<ControlsProps>(({ setUpdating }) => {
const config = useAgentStore((s) => agentByIdSelectors.getAgentConfigById(agentId)(s), isEqual);
const [form] = Form.useForm();
+ const enableMaxTokens = AntdForm.useWatch(['chatConfig', 'enableMaxTokens'], form);
const { frequency_penalty, presence_penalty, temperature, top_p } = config.params ?? {};
const lastValuesRef = useRef<Record<ParamKey, number | undefined>>({
@@ -289,6 +290,40 @@ const Controls = memo<ControlsProps>(({ setUpdating }) => {
} satisfies FormItemProps;
});
+ // MaxTokens items
+ const maxTokensItems: FormItemProps[] = [
+ {
+ children: <Switch />,
+ label: (
+ <Flexbox align={'center'} className={styles.label} gap={8} horizontal>
+ {t('settingModel.enableMaxTokens.title')}
+ </Flexbox>
+ ),
+ name: ['chatConfig', 'enableMaxTokens'],
+ tag: 'max_tokens',
+ valuePropName: 'checked',
+ },
+ ...(enableMaxTokens
+ ? [
+ {
+ children: (
+ <SliderWithInput max={32_000} min={0} step={100} unlimitedInput />
+ ),
+ label: (
+ <Flexbox align={'center'} className={styles.label} gap={8} horizontal>
+ {t('settingModel.maxTokens.title')}
+ <InfoTooltip title={t('settingModel.maxTokens.desc')} />
+ </Flexbox>
+ ),
+ name: ['params', 'max_tokens'],
+ tag: 'max_tokens',
+ } satisfies FormItemProps,
+ ]
+ : []),
+ ];
+
+ const allItems = [...baseItems, ...maxTokensItems];
+
return (
<Form
form={form}
@@ -296,11 +331,11 @@ const Controls = memo<ControlsProps>(({ setUpdating }) => {
itemMinWidth={220}
items={
mobile
- ? baseItems
- : baseItems.map(({ tag, ...item }) => ({
- ...item,
- desc: <Tag size={'small'}>{tag}</Tag>,
- }))
+ ? allItems
+ : allItems.map(({ tag, ...item }) => ({
+ ...item,
+ desc: <Tag size={'small'}>{tag}</Tag>,
+ }))
}
itemsType={'flat'}
onValuesChange={handleValuesChange}