feat: 表单配置支持设定各项高级参数

This commit is contained in:
arvinxx
2023-07-25 00:21:29 +08:00
parent ad389be6e6
commit 6949cc6ab4
6 changed files with 35 additions and 85 deletions

View File

@@ -15,7 +15,7 @@ import type { LobeAgentConfig } from '@/types/session';
type SettingItemGroup = ItemGroup & {
children: {
name?: keyof LobeAgentConfig;
name?: keyof LobeAgentConfig | string[];
}[];
};
@@ -26,8 +26,6 @@ const AgentConfig = () => {
const [updateAgentConfig] = useSessionStore((s) => [s.updateAgentConfig], shallow);
// TODO: setting 结构嵌套,现在是扁平的 params: { temperature: 0.6 }
// @ts-ignore
const chat: SettingItemGroup = useMemo(
() => ({
children: [
@@ -42,13 +40,13 @@ const AgentConfig = () => {
),
label: t('settingChat.chatStyleType.title'),
minWidth: undefined,
name: 'chatStyleType',
name: 'displayMode',
},
{
children: <Input placeholder={t('settingChat.inputTemplate.placeholder')} />,
desc: t('settingChat.inputTemplate.desc'),
label: t('settingChat.inputTemplate.title'),
name: 'enableHistoryCount',
name: 'inputTemplate',
},
{
children: <Switch />,
@@ -60,8 +58,7 @@ const AgentConfig = () => {
{
children: <SliderWithInput max={32} min={0} />,
desc: t('settingChat.historyCount.desc'),
// @ts-ignore
hidden: !config.params.enableHistoryCount,
hidden: !config.enableHistoryCount,
label: t('settingChat.historyCount.title'),
name: 'historyCount',
},
@@ -75,8 +72,7 @@ const AgentConfig = () => {
{
children: <SliderWithInput max={32} min={0} />,
desc: t('settingChat.compressThreshold.desc'),
// @ts-ignore
hidden: !config.params.enableCompressThreshold,
hidden: !config.enableCompressThreshold,
label: t('settingChat.compressThreshold.title'),
name: 'compressThreshold',
},
@@ -87,8 +83,6 @@ const AgentConfig = () => {
[config],
);
// TODO: setting 结构嵌套,现在是扁平的 params: { temperature: 0.6 }
// @ts-ignore
const model: SettingItemGroup = useMemo(
() => ({
children: [
@@ -110,28 +104,28 @@ const AgentConfig = () => {
children: <SliderWithInput max={1} min={0} step={0.1} />,
desc: t('settingModel.temperature.desc'),
label: t('settingModel.temperature.title'),
name: 'temperature',
name: ['params', 'temperature'],
tag: 'temperature',
},
{
children: <SliderWithInput max={1} min={0} step={0.1} />,
desc: t('settingModel.topP.desc'),
label: t('settingModel.topP.title'),
name: 'topP',
name: ['params', 'top_p'],
tag: 'top_p',
},
{
children: <SliderWithInput max={2} min={-2} step={0.1} />,
desc: t('settingModel.presencePenalty.desc'),
label: t('settingModel.presencePenalty.title'),
name: 'presencePenalty',
name: ['params', 'presence_penalty'],
tag: 'presence_penalty',
},
{
children: <SliderWithInput max={2} min={-2} step={0.1} />,
desc: t('settingModel.frequencyPenalty.desc'),
label: t('settingModel.frequencyPenalty.title'),
name: 'frequencyPenalty',
name: ['params', 'frequency_penalty'],
tag: 'frequency_penalty',
},
{
@@ -144,11 +138,9 @@ const AgentConfig = () => {
{
children: <SliderWithInput max={32_000} min={0} step={100} />,
desc: t('settingModel.maxTokens.desc'),
// TODO
// @ts-ignore
hidden: !config?.params?.enableMaxTokens,
hidden: !config?.enableMaxTokens,
label: t('settingModel.maxTokens.title'),
name: 'params.maxTokens',
name: ['params', 'max_tokens'],
tag: 'max_tokens',
},
],
@@ -158,12 +150,10 @@ const AgentConfig = () => {
[config],
);
const items = useMemo(() => [chat, model], [config]);
return (
<Form
initialValues={config}
items={items}
items={[chat, model]}
onValuesChange={debounce(updateAgentConfig, 100)}
{...FORM_STYLE}
/>

View File

@@ -1,26 +0,0 @@
import { createStyles } from 'antd-style';
import { ReactNode, memo } from 'react';
import { Flexbox } from 'react-layout-kit';
const useStyles = createStyles(({ css, token }) => ({
header: css``,
title: css`
color: ${token.colorTextSecondary};
`,
}));
interface FormItemProps {
children: ReactNode;
label: string;
}
export const FormItem = memo<FormItemProps>(({ label, children }) => {
const { styles } = useStyles();
return (
<Flexbox className={styles.header} gap={12}>
<Flexbox className={styles.title}>{label}</Flexbox>
<Flexbox>{children}</Flexbox>
</Flexbox>
);
});

View File

@@ -1,34 +0,0 @@
import { createStyles } from 'antd-style';
export const useStyles = createStyles(({ css, token }) => ({
collapseHeader: css`
.ant-collapse-header {
align-items: center !important;
}
`,
footer: css`
position: sticky;
bottom: 0;
border-top: 1px solid ${token.colorBorder};
`,
form: css`
overflow-y: auto;
`,
header: css`
background: ${token.colorBgContainer};
border-bottom: 1px solid ${token.colorSplit};
`,
profile: css`
font-size: 20px;
font-weight: bold;
color: ${token.colorText};
`,
prompt: css`
padding: 12px;
background: ${token.colorFillTertiary};
`,
title: css`
font-size: 16px;
font-weight: 500;
`,
}));

View File

@@ -102,7 +102,11 @@ export const sessionsReducer = (state: LobeSessions, payload: SessionDispatch):
const chat = draft[id];
if (!chat) return;
chat.config = { ...chat.config, ...config };
chat.config = {
...chat.config,
...config,
params: { ...chat.config.params, ...config.params },
};
});
}

View File

@@ -7,8 +7,8 @@ export const DEFAULT_SETTINGS: ConfigSettings = {
accessCode: '',
avatar: '',
compressThreshold: 24,
enableCompressThreshold: true,
enableHistoryCount: true,
enableCompressThreshold: false,
enableHistoryCount: false,
enableMaxTokens: true,
endpoint: '',
fontSize: 14,

View File

@@ -26,10 +26,26 @@ interface LobeSessionBase extends BaseDataModel {
}
export interface LobeAgentConfig {
compressThreshold?: number;
displayMode?: 'chat' | 'docs';
/**
* 历史消息长度压缩阈值
*/
enableCompressThreshold?: boolean;
/**
* 开启历史记录条数
*/
enableHistoryCount?: boolean;
enableMaxTokens?: boolean;
/**
* 语言模型示例
*/
example?: LLMExample;
/**
* 历史消息条数
*/
historyCount?: number;
inputTemplate?: string;
/**
* 角色所使用的语言模型
* @default gpt-3.5-turbo