feat: 实现会话展示模式切换,并优化默认创建角色的配置

This commit is contained in:
arvinxx
2023-07-25 00:52:18 +08:00
parent 86291c311f
commit 27ae82ff96
8 changed files with 46 additions and 19 deletions

View File

@@ -63,7 +63,7 @@
"@commitlint/cli": "^17",
"@emoji-mart/data": "^1",
"@emoji-mart/react": "^1",
"@lobehub/ui": "^1",
"@lobehub/ui": "latest",
"@vercel/analytics": "^1",
"ahooks": "^3",
"ai": "^2",

View File

@@ -48,7 +48,7 @@ export default {
chatStyleType: {
title: '聊天窗口样式',
type: {
bubble: '气泡模式',
chat: '对话模式',
docs: '文档模式',
},
},

View File

@@ -3,7 +3,7 @@ import isEqual from 'fast-deep-equal';
import { ReactNode, memo } from 'react';
import { shallow } from 'zustand/shallow';
import { chatSelectors, useSessionStore } from '@/store/session';
import { agentSelectors, chatSelectors, useSessionStore } from '@/store/session';
import { isFunctionMessage } from '@/utils/message';
import FunctionMessage from './FunctionMessage';
@@ -11,8 +11,13 @@ import MessageExtra from './MessageExtra';
const List = () => {
const data = useSessionStore(chatSelectors.currentChats, isEqual);
const [deleteMessage, resendMessage, dispatchMessage] = useSessionStore(
(s) => [s.deleteMessage, s.resendMessage, s.dispatchMessage],
const [displayMode, deleteMessage, resendMessage, dispatchMessage] = useSessionStore(
(s) => [
agentSelectors.currentAgentConfigSafe(s).displayMode,
s.deleteMessage,
s.resendMessage,
s.dispatchMessage,
],
shallow,
);
@@ -45,6 +50,7 @@ const List = () => {
renderMessage={renderMessage}
renderMessageExtra={MessageExtra}
style={{ marginTop: 24 }}
type={displayMode}
/>
);
};

View File

@@ -1,5 +1,6 @@
import { Form, ItemGroup } from '@lobehub/ui';
import { Input, Segmented, Select, Switch } from 'antd';
import { ConfigProvider, Input, Segmented, Select, Switch } from 'antd';
import { useTheme } from 'antd-style';
import isEqual from 'fast-deep-equal';
import { debounce } from 'lodash-es';
import { BrainCog, MessagesSquare } from 'lucide-react';
@@ -21,6 +22,7 @@ type SettingItemGroup = ItemGroup & {
const AgentConfig = () => {
const { t } = useTranslation('setting');
const theme = useTheme();
const config = useSessionStore(agentSelectors.currentAgentConfigSafe, isEqual);
@@ -33,7 +35,7 @@ const AgentConfig = () => {
children: (
<Segmented
options={[
{ label: t('settingChat.chatStyleType.type.bubble'), value: 'chat' },
{ label: t('settingChat.chatStyleType.type.chat'), value: 'chat' },
{ label: t('settingChat.chatStyleType.type.docs'), value: 'docs' },
]}
/>
@@ -151,12 +153,22 @@ const AgentConfig = () => {
);
return (
<Form
initialValues={config}
items={[chat, model]}
onValuesChange={debounce(updateAgentConfig, 100)}
{...FORM_STYLE}
/>
<ConfigProvider
theme={{
components: {
Segmented: {
colorBgLayout: theme.isDarkMode ? '#111' : '#f1f1f1',
},
},
}}
>
<Form
initialValues={config}
items={[chat, model]}
onValuesChange={debounce(updateAgentConfig, 100)}
{...FORM_STYLE}
/>
</ConfigProvider>
);
};

View File

@@ -1,5 +1,6 @@
import { merge } from 'lodash-es';
import { initialLobeAgentConfig } from '@/store/session';
import type { OpenAIStreamPayload } from '@/types/openai';
import { URLS } from './url';
@@ -13,12 +14,9 @@ export const fetchChatModel = (
) => {
const payload = merge(
{
frequency_penalty: 0,
model: 'gpt-3.5-turbo',
presence_penalty: 0,
model: initialLobeAgentConfig.model,
stream: true,
temperature: 0.6,
top_p: 1,
...initialLobeAgentConfig.params,
},
params,
);

View File

@@ -32,4 +32,5 @@ export const useSessionStore = create<SessionStore>()(
);
export * from './selectors';
export { initialLobeAgentConfig } from './slices/agentConfig';
export type { SessionStore } from './store';

View File

@@ -11,8 +11,15 @@ export interface AgentConfigState {
}
export const initialLobeAgentConfig: LobeAgentConfig = {
displayMode: 'chat',
model: LanguageModel.GPT3_5,
params: { temperature: 0.6 },
params: {
frequency_penalty: 0,
presence_penalty: 0,
temperature: 0.6,
top_p: 1,
},
plugins: [],
systemRole: '',
};

View File

@@ -18,6 +18,7 @@ export enum LanguageModel {
export interface LLMParams {
/**
* 控制生成文本中的惩罚系数,用于减少重复性
* @default 0
*/
frequency_penalty?: number;
/**
@@ -26,6 +27,7 @@ export interface LLMParams {
max_tokens?: number;
/**
* 控制生成文本中的惩罚系数,用于减少主题的变化
* @default 0
*/
presence_penalty?: number;
/**
@@ -35,6 +37,7 @@ export interface LLMParams {
temperature?: number;
/**
* 控制生成文本中最高概率的单个 token
* @default 1
*/
top_p?: number;
}