@lobehub/chat 0.102.4 → 0.103.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +50 -0
- package/locales/en_US/setting.json +9 -1
- package/locales/ja_JP/setting.json +9 -1
- package/locales/ko_KR/setting.json +9 -1
- package/locales/ru_RU/setting.json +9 -1
- package/locales/zh_CN/setting.json +8 -0
- package/locales/zh_TW/setting.json +9 -1
- package/package.json +2 -1
- package/src/app/chat/features/ChatHeader/ShareButton/Preview.tsx +1 -2
- package/src/app/chat/features/ChatInput/ActionBar/FileUpload.tsx +1 -1
- package/src/app/chat/features/ChatInput/ActionBar/ModelSwitch.tsx +1 -2
- package/src/app/chat/features/Conversation/usePluginsInit.ts +1 -1
- package/src/app/chat/settings/features/SubmitAgentButton/Inner.tsx +1 -1
- package/src/const/settings.ts +2 -0
- package/src/features/AgentSetting/AgentConfig/index.tsx +17 -1
- package/src/hooks/useSTT.ts +1 -1
- package/src/hooks/useTTS.ts +1 -1
- package/src/locales/default/setting.ts +8 -0
- package/src/services/chat.ts +3 -3
- package/src/store/global/selectors/__snapshots__/settings.test.ts.snap +60 -0
- package/src/store/global/selectors/settings.test.ts +1 -51
- package/src/store/global/slices/agent.ts +4 -2
- package/src/store/session/initialState.ts +0 -1
- package/src/store/session/selectors.ts +1 -1
- package/src/store/session/slices/{agentConfig → agent}/action.ts +14 -2
- package/src/store/session/slices/{agentConfig → agent}/index.ts +0 -1
- package/src/store/session/slices/{agentConfig → agent}/selectors.ts +9 -3
- package/src/store/session/slices/chat/actions/message.ts +6 -2
- package/src/store/session/slices/chat/actions/share.ts +1 -1
- package/src/store/session/slices/chat/selectors/chat.ts +1 -1
- package/src/store/session/slices/chat/selectors/utils.test.ts +4 -0
- package/src/store/session/slices/session/initialState.ts +6 -11
- package/src/store/session/slices/session/reducers/session.test.ts +1 -1
- package/src/store/session/store.ts +1 -1
- package/src/types/session.ts +2 -0
- package/src/store/session/slices/agentConfig/initialState.ts +0 -4
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,56 @@
|
|
|
2
2
|
|
|
3
3
|
# Changelog
|
|
4
4
|
|
|
5
|
+
### [Version 0.103.1](https://github.com/lobehub/lobe-chat/compare/v0.103.0...v0.103.1)
|
|
6
|
+
|
|
7
|
+
<sup>Released on **2023-11-21**</sup>
|
|
8
|
+
|
|
9
|
+
#### 🐛 Bug Fixes
|
|
10
|
+
|
|
11
|
+
- **misc**: Image optimization in docker standalone build.
|
|
12
|
+
|
|
13
|
+
<br/>
|
|
14
|
+
|
|
15
|
+
<details>
|
|
16
|
+
<summary><kbd>Improvements and Fixes</kbd></summary>
|
|
17
|
+
|
|
18
|
+
#### What's fixed
|
|
19
|
+
|
|
20
|
+
- **misc**: Image optimization in docker standalone build, closes [#494](https://github.com/lobehub/lobe-chat/issues/494) ([d2bcac3](https://github.com/lobehub/lobe-chat/commit/d2bcac3))
|
|
21
|
+
|
|
22
|
+
</details>
|
|
23
|
+
|
|
24
|
+
<div align="right">
|
|
25
|
+
|
|
26
|
+
[](#readme-top)
|
|
27
|
+
|
|
28
|
+
</div>
|
|
29
|
+
|
|
30
|
+
## [Version 0.103.0](https://github.com/lobehub/lobe-chat/compare/v0.102.4...v0.103.0)
|
|
31
|
+
|
|
32
|
+
<sup>Released on **2023-11-20**</sup>
|
|
33
|
+
|
|
34
|
+
#### ✨ Features
|
|
35
|
+
|
|
36
|
+
- **misc**: Support the auto create topic configuration.
|
|
37
|
+
|
|
38
|
+
<br/>
|
|
39
|
+
|
|
40
|
+
<details>
|
|
41
|
+
<summary><kbd>Improvements and Fixes</kbd></summary>
|
|
42
|
+
|
|
43
|
+
#### What's improved
|
|
44
|
+
|
|
45
|
+
- **misc**: Support the auto create topic configuration, closes [#490](https://github.com/lobehub/lobe-chat/issues/490) ([a7b7ef0](https://github.com/lobehub/lobe-chat/commit/a7b7ef0))
|
|
46
|
+
|
|
47
|
+
</details>
|
|
48
|
+
|
|
49
|
+
<div align="right">
|
|
50
|
+
|
|
51
|
+
[](#readme-top)
|
|
52
|
+
|
|
53
|
+
</div>
|
|
54
|
+
|
|
5
55
|
### [Version 0.102.4](https://github.com/lobehub/lobe-chat/compare/v0.102.3...v0.102.4)
|
|
6
56
|
|
|
7
57
|
<sup>Released on **2023-11-20**</sup>
|
|
@@ -139,7 +139,15 @@
|
|
|
139
139
|
"placeholder": "{{text}} will be replaced with real-time input information",
|
|
140
140
|
"title": "User Input Preprocessing"
|
|
141
141
|
},
|
|
142
|
-
"title": "Chat Settings"
|
|
142
|
+
"title": "Chat Settings",
|
|
143
|
+
"autoCreateTopicThreshold": {
|
|
144
|
+
"title": "Message Threshold",
|
|
145
|
+
"desc": "Automatically create a topic when the current message count exceeds this value"
|
|
146
|
+
},
|
|
147
|
+
"enableAutoCreateTopic": {
|
|
148
|
+
"title": "Enable Auto Topic Creation",
|
|
149
|
+
"desc": "Whether to automatically create a topic during the conversation, only effective in temporary topics"
|
|
150
|
+
}
|
|
143
151
|
},
|
|
144
152
|
"settingModel": {
|
|
145
153
|
"enableMaxTokens": {
|
|
@@ -139,7 +139,15 @@
|
|
|
139
139
|
"placeholder": "プリプロセステンプレート {{text}} はリアルタイムの入力情報に置き換えられます",
|
|
140
140
|
"title": "ユーザー入力のプリプロセス"
|
|
141
141
|
},
|
|
142
|
-
"title": "チャット設定"
|
|
142
|
+
"title": "チャット設定",
|
|
143
|
+
"autoCreateTopicThreshold": {
|
|
144
|
+
"desc": "現在のメッセージ数がこの値を超えると、トピックが自動的に作成されます",
|
|
145
|
+
"title": "メッセージ閾値"
|
|
146
|
+
},
|
|
147
|
+
"enableAutoCreateTopic": {
|
|
148
|
+
"desc": "会話中にトピックを自動的に作成するかどうか、一時的なトピックでのみ有効です",
|
|
149
|
+
"title": "トピックの自動作成"
|
|
150
|
+
}
|
|
143
151
|
},
|
|
144
152
|
"settingModel": {
|
|
145
153
|
"enableMaxTokens": {
|
|
@@ -139,7 +139,15 @@
|
|
|
139
139
|
"placeholder": "사전 처리 템플릿 {{text}}은(는) 실시간 입력 정보로 대체됩니다.",
|
|
140
140
|
"title": "사용자 입력 사전 처리"
|
|
141
141
|
},
|
|
142
|
-
"title": "채팅 설정"
|
|
142
|
+
"title": "채팅 설정",
|
|
143
|
+
"autoCreateTopicThreshold": {
|
|
144
|
+
"desc": "현재 메시지 수가이 값 이상이면 자동으로 주제를 만듭니다.",
|
|
145
|
+
"title": "메시지 임계값"
|
|
146
|
+
},
|
|
147
|
+
"enableAutoCreateTopic": {
|
|
148
|
+
"desc": "대화 중에 주제를 자동으로 만들지 여부를 설정합니다. 임시 주제에서만 작동합니다.",
|
|
149
|
+
"title": "주제 자동 생성"
|
|
150
|
+
}
|
|
143
151
|
},
|
|
144
152
|
"settingModel": {
|
|
145
153
|
"enableMaxTokens": {
|
|
@@ -139,7 +139,15 @@
|
|
|
139
139
|
"placeholder": "{{text}} будут заменены входной информацией, поступающей в режиме реального времени",
|
|
140
140
|
"title": "Предварительная обработка пользовательского ввода"
|
|
141
141
|
},
|
|
142
|
-
"title": "Настройки чата"
|
|
142
|
+
"title": "Настройки чата",
|
|
143
|
+
"autoCreateTopicThreshold": {
|
|
144
|
+
"desc": "Когда текущее количество сообщений превысит эту величину, будет автоматически создана тема",
|
|
145
|
+
"title": "Порог сообщений"
|
|
146
|
+
},
|
|
147
|
+
"enableAutoCreateTopic": {
|
|
148
|
+
"desc": "Автоматическое создание темы во время разговора, действует только во временной теме",
|
|
149
|
+
"title": "Включить автоматическое создание темы"
|
|
150
|
+
}
|
|
143
151
|
},
|
|
144
152
|
"settingModel": {
|
|
145
153
|
"enableMaxTokens": {
|
|
@@ -110,6 +110,10 @@
|
|
|
110
110
|
"title": "助手信息"
|
|
111
111
|
},
|
|
112
112
|
"settingChat": {
|
|
113
|
+
"autoCreateTopicThreshold": {
|
|
114
|
+
"desc": "当前消息数超过设定该值后,将自动创建话题",
|
|
115
|
+
"title": "消息阈值"
|
|
116
|
+
},
|
|
113
117
|
"chatStyleType": {
|
|
114
118
|
"title": "聊天窗口样式",
|
|
115
119
|
"type": {
|
|
@@ -121,6 +125,10 @@
|
|
|
121
125
|
"desc": "当未压缩的历史消息超过该值时,将进行压缩",
|
|
122
126
|
"title": "历史消息长度压缩阈值"
|
|
123
127
|
},
|
|
128
|
+
"enableAutoCreateTopic": {
|
|
129
|
+
"desc": "会话过程中是否自动创建话题,仅在临时话题中生效",
|
|
130
|
+
"title": "自动创建话题"
|
|
131
|
+
},
|
|
124
132
|
"enableCompressThreshold": {
|
|
125
133
|
"title": "是否开启历史消息长度压缩阈值"
|
|
126
134
|
},
|
|
@@ -139,7 +139,15 @@
|
|
|
139
139
|
"placeholder": "前置處理範本 {{text}} 將替換為即時輸入資訊",
|
|
140
140
|
"title": "使用者輸入前置處理"
|
|
141
141
|
},
|
|
142
|
-
"title": "聊天設定"
|
|
142
|
+
"title": "聊天設定",
|
|
143
|
+
"autoCreateTopicThreshold": {
|
|
144
|
+
"desc": "當前訊息數超過設定該值後,將自動創建話題",
|
|
145
|
+
"title": "訊息閾值"
|
|
146
|
+
},
|
|
147
|
+
"enableAutoCreateTopic": {
|
|
148
|
+
"desc": "會話過程中是否自動創建話題,僅在臨時話題中生效",
|
|
149
|
+
"title": "自動創建話題"
|
|
150
|
+
}
|
|
143
151
|
},
|
|
144
152
|
"settingModel": {
|
|
145
153
|
"enableMaxTokens": {
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lobehub/chat",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.103.1",
|
|
4
4
|
"description": "An open-source, extensible (Function Calling), high-performance chatbot framework. It supports one-click free deployment of your private ChatGPT/LLM web application",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"chatbot",
|
|
@@ -111,6 +111,7 @@
|
|
|
111
111
|
"remark-gfm": "^3",
|
|
112
112
|
"remark-html": "^15",
|
|
113
113
|
"semver": "^7",
|
|
114
|
+
"sharp": "^0.32.6",
|
|
114
115
|
"swr": "^2",
|
|
115
116
|
"systemjs": "^6",
|
|
116
117
|
"ts-md5": "^1",
|
|
@@ -10,8 +10,7 @@ import ChatList from 'src/app/chat/features/Conversation/ChatList';
|
|
|
10
10
|
|
|
11
11
|
import pkg from '@/../package.json';
|
|
12
12
|
import { useSessionStore } from '@/store/session';
|
|
13
|
-
import { agentSelectors } from '@/store/session/
|
|
14
|
-
import { sessionSelectors } from '@/store/session/slices/session/selectors';
|
|
13
|
+
import { agentSelectors, sessionSelectors } from '@/store/session/selectors';
|
|
15
14
|
|
|
16
15
|
import PluginTag from '../../ChatHeader/PluginTag';
|
|
17
16
|
import { useStyles } from './style';
|
|
@@ -8,7 +8,7 @@ import { Center } from 'react-layout-kit';
|
|
|
8
8
|
|
|
9
9
|
import { useFileStore } from '@/store/files';
|
|
10
10
|
import { useSessionStore } from '@/store/session';
|
|
11
|
-
import { agentSelectors } from '@/store/session/
|
|
11
|
+
import { agentSelectors } from '@/store/session/selectors';
|
|
12
12
|
|
|
13
13
|
const FileUpload = memo(() => {
|
|
14
14
|
const { t } = useTranslation('chat');
|
|
@@ -13,8 +13,7 @@ const ModelSwitch = memo(() => {
|
|
|
13
13
|
const { t } = useTranslation('setting');
|
|
14
14
|
|
|
15
15
|
const [model, updateAgentConfig] = useSessionStore((s) => {
|
|
16
|
-
|
|
17
|
-
return [config.model, s.updateAgentConfig];
|
|
16
|
+
return [agentSelectors.currentAgentModel(s), s.updateAgentConfig];
|
|
18
17
|
});
|
|
19
18
|
|
|
20
19
|
const modelList = useGlobalStore(settingsSelectors.modelList);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { usePluginStore } from '@/store/plugin';
|
|
2
2
|
import { useSessionStore } from '@/store/session';
|
|
3
|
-
import { agentSelectors } from '@/store/session/
|
|
3
|
+
import { agentSelectors } from '@/store/session/selectors';
|
|
4
4
|
|
|
5
5
|
export const usePluginsInit = () => {
|
|
6
6
|
const [plugins] = useSessionStore((s) => [agentSelectors.currentAgentPlugins(s)]);
|
|
@@ -13,7 +13,7 @@ import { AGENTS_INDEX_GITHUB_ISSUE } from '@/const/url';
|
|
|
13
13
|
import AgentInfo from '@/features/AgentInfo';
|
|
14
14
|
import { useGlobalStore } from '@/store/global';
|
|
15
15
|
import { useSessionStore } from '@/store/session';
|
|
16
|
-
import { agentSelectors } from '@/store/session/
|
|
16
|
+
import { agentSelectors } from '@/store/session/selectors';
|
|
17
17
|
|
|
18
18
|
const Inner = memo(() => {
|
|
19
19
|
const { t } = useTranslation('setting');
|
package/src/const/settings.ts
CHANGED
|
@@ -31,7 +31,9 @@ export const DEFAUTT_AGENT_TTS_CONFIG: LobeAgentTTSConfig = {
|
|
|
31
31
|
export const VISION_MODEL_DEFAULT_MAX_TOKENS = 1000;
|
|
32
32
|
|
|
33
33
|
export const DEFAULT_AGENT_CONFIG: LobeAgentConfig = {
|
|
34
|
+
autoCreateTopicThreshold: 2,
|
|
34
35
|
displayMode: 'chat',
|
|
36
|
+
enableAutoCreateTopic: true,
|
|
35
37
|
historyCount: 1,
|
|
36
38
|
model: LanguageModel.GPT3_5,
|
|
37
39
|
params: {
|
|
@@ -55,11 +55,27 @@ const AgentConfig = memo(() => {
|
|
|
55
55
|
minWidth: undefined,
|
|
56
56
|
},
|
|
57
57
|
{
|
|
58
|
-
children: <Input placeholder={t('settingChat.inputTemplate.placeholder')} />,
|
|
58
|
+
children: <Input.TextArea placeholder={t('settingChat.inputTemplate.placeholder')} />,
|
|
59
59
|
desc: t('settingChat.inputTemplate.desc'),
|
|
60
60
|
label: t('settingChat.inputTemplate.title'),
|
|
61
61
|
name: 'inputTemplate',
|
|
62
62
|
},
|
|
63
|
+
{
|
|
64
|
+
children: <Switch />,
|
|
65
|
+
desc: t('settingChat.enableAutoCreateTopic.desc'),
|
|
66
|
+
label: t('settingChat.enableAutoCreateTopic.title'),
|
|
67
|
+
minWidth: undefined,
|
|
68
|
+
name: 'enableAutoCreateTopic',
|
|
69
|
+
valuePropName: 'checked',
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
children: <SliderWithInput max={8} min={0} />,
|
|
73
|
+
desc: t('settingChat.autoCreateTopicThreshold.desc'),
|
|
74
|
+
divider: false,
|
|
75
|
+
hidden: !config.enableAutoCreateTopic,
|
|
76
|
+
label: t('settingChat.autoCreateTopicThreshold.title'),
|
|
77
|
+
name: 'autoCreateTopicThreshold',
|
|
78
|
+
},
|
|
63
79
|
{
|
|
64
80
|
children: <Switch />,
|
|
65
81
|
label: t('settingChat.enableHistoryCount.title'),
|
package/src/hooks/useSTT.ts
CHANGED
|
@@ -12,7 +12,7 @@ import { createHeaderWithOpenAI } from '@/services/_header';
|
|
|
12
12
|
import { OPENAI_URLS } from '@/services/_url';
|
|
13
13
|
import { settingsSelectors, useGlobalStore } from '@/store/global';
|
|
14
14
|
import { useSessionStore } from '@/store/session';
|
|
15
|
-
import { agentSelectors } from '@/store/session/
|
|
15
|
+
import { agentSelectors } from '@/store/session/selectors';
|
|
16
16
|
|
|
17
17
|
interface STTConfig extends SWRConfiguration {
|
|
18
18
|
onTextChange: (value: string) => void;
|
package/src/hooks/useTTS.ts
CHANGED
|
@@ -14,7 +14,7 @@ import { createHeaderWithOpenAI } from '@/services/_header';
|
|
|
14
14
|
import { OPENAI_URLS, TTS_URL } from '@/services/_url';
|
|
15
15
|
import { settingsSelectors, useGlobalStore } from '@/store/global';
|
|
16
16
|
import { useSessionStore } from '@/store/session';
|
|
17
|
-
import { agentSelectors } from '@/store/session/
|
|
17
|
+
import { agentSelectors } from '@/store/session/selectors';
|
|
18
18
|
import { TTSServer } from '@/types/session';
|
|
19
19
|
|
|
20
20
|
interface TTSConfig extends SWRConfiguration {
|
|
@@ -110,6 +110,10 @@ export default {
|
|
|
110
110
|
title: '助手信息',
|
|
111
111
|
},
|
|
112
112
|
settingChat: {
|
|
113
|
+
autoCreateTopicThreshold: {
|
|
114
|
+
desc: '当前消息数超过设定该值后,将自动创建话题',
|
|
115
|
+
title: '消息阈值',
|
|
116
|
+
},
|
|
113
117
|
chatStyleType: {
|
|
114
118
|
title: '聊天窗口样式',
|
|
115
119
|
type: {
|
|
@@ -121,6 +125,10 @@ export default {
|
|
|
121
125
|
desc: '当未压缩的历史消息超过该值时,将进行压缩',
|
|
122
126
|
title: '历史消息长度压缩阈值',
|
|
123
127
|
},
|
|
128
|
+
enableAutoCreateTopic: {
|
|
129
|
+
desc: '会话过程中是否自动创建话题,仅在临时话题中生效',
|
|
130
|
+
title: '自动创建话题',
|
|
131
|
+
},
|
|
124
132
|
enableCompressThreshold: {
|
|
125
133
|
title: '是否开启历史消息长度压缩阈值',
|
|
126
134
|
},
|
package/src/services/chat.ts
CHANGED
|
@@ -2,9 +2,9 @@ import { PluginRequestPayload, createHeadersWithPluginSettings } from '@lobehub/
|
|
|
2
2
|
import { merge } from 'lodash-es';
|
|
3
3
|
|
|
4
4
|
import { VISION_MODEL_WHITE_LIST } from '@/const/llm';
|
|
5
|
+
import { DEFAULT_AGENT_CONFIG } from '@/const/settings';
|
|
5
6
|
import { usePluginStore } from '@/store/plugin';
|
|
6
7
|
import { pluginSelectors } from '@/store/plugin/selectors';
|
|
7
|
-
import { initialLobeAgentConfig } from '@/store/session/initialState';
|
|
8
8
|
import type { OpenAIChatStreamPayload } from '@/types/openai/chat';
|
|
9
9
|
import { fetchAIFactory, getMessageError } from '@/utils/fetch';
|
|
10
10
|
|
|
@@ -22,9 +22,9 @@ class ChatService {
|
|
|
22
22
|
) => {
|
|
23
23
|
const payload = merge(
|
|
24
24
|
{
|
|
25
|
-
model:
|
|
25
|
+
model: DEFAULT_AGENT_CONFIG.model,
|
|
26
26
|
stream: true,
|
|
27
|
-
...
|
|
27
|
+
...DEFAULT_AGENT_CONFIG.params,
|
|
28
28
|
},
|
|
29
29
|
params,
|
|
30
30
|
);
|
|
@@ -0,0 +1,60 @@
|
|
|
1
|
+
// Vitest Snapshot v1, https://vitest.dev/guide/snapshot.html
|
|
2
|
+
|
|
3
|
+
exports[`settingsSelectors > currentSettings > should merge DEFAULT_SETTINGS and s.settings correctly 1`] = `
|
|
4
|
+
{
|
|
5
|
+
"avatar": "avatar.jpg",
|
|
6
|
+
"defaultAgent": {
|
|
7
|
+
"config": {
|
|
8
|
+
"autoCreateTopicThreshold": 2,
|
|
9
|
+
"displayMode": "chat",
|
|
10
|
+
"enableAutoCreateTopic": true,
|
|
11
|
+
"historyCount": 1,
|
|
12
|
+
"model": "gpt-3.5-turbo",
|
|
13
|
+
"params": {
|
|
14
|
+
"frequency_penalty": 0,
|
|
15
|
+
"presence_penalty": 0,
|
|
16
|
+
"temperature": 0.6,
|
|
17
|
+
"top_p": 1,
|
|
18
|
+
},
|
|
19
|
+
"plugins": [],
|
|
20
|
+
"systemRole": "",
|
|
21
|
+
"tts": {
|
|
22
|
+
"showAllLocaleVoice": false,
|
|
23
|
+
"sttLocale": "auto",
|
|
24
|
+
"ttsService": "openai",
|
|
25
|
+
"voice": {
|
|
26
|
+
"openai": "alloy",
|
|
27
|
+
},
|
|
28
|
+
},
|
|
29
|
+
},
|
|
30
|
+
"meta": {
|
|
31
|
+
"avatar": "Default Agent",
|
|
32
|
+
"description": "Default agent for testing",
|
|
33
|
+
},
|
|
34
|
+
},
|
|
35
|
+
"fontSize": 14,
|
|
36
|
+
"language": "en-US",
|
|
37
|
+
"languageModel": {
|
|
38
|
+
"openAI": {
|
|
39
|
+
"OPENAI_API_KEY": "openai-api-key",
|
|
40
|
+
"customModelName": undefined,
|
|
41
|
+
"endpoint": "https://openai-endpoint.com",
|
|
42
|
+
"models": [
|
|
43
|
+
"gpt-3.5-turbo",
|
|
44
|
+
],
|
|
45
|
+
},
|
|
46
|
+
},
|
|
47
|
+
"neutralColor": "sand",
|
|
48
|
+
"password": "password123",
|
|
49
|
+
"primaryColor": "blue",
|
|
50
|
+
"themeMode": "light",
|
|
51
|
+
"tts": {
|
|
52
|
+
"openAI": {
|
|
53
|
+
"sttModel": "whisper-1",
|
|
54
|
+
"ttsModel": "tts-1",
|
|
55
|
+
},
|
|
56
|
+
"sttAutoStop": true,
|
|
57
|
+
"sttServer": "openai",
|
|
58
|
+
},
|
|
59
|
+
}
|
|
60
|
+
`;
|
|
@@ -54,57 +54,7 @@ describe('settingsSelectors', () => {
|
|
|
54
54
|
|
|
55
55
|
const result = settingsSelectors.currentSettings(s);
|
|
56
56
|
|
|
57
|
-
expect(result).
|
|
58
|
-
avatar: 'avatar.jpg',
|
|
59
|
-
fontSize: 14,
|
|
60
|
-
language: 'en-US',
|
|
61
|
-
neutralColor: 'sand',
|
|
62
|
-
password: 'password123',
|
|
63
|
-
primaryColor: 'blue',
|
|
64
|
-
themeMode: 'light',
|
|
65
|
-
defaultAgent: {
|
|
66
|
-
config: {
|
|
67
|
-
displayMode: 'chat',
|
|
68
|
-
historyCount: 1,
|
|
69
|
-
systemRole: '',
|
|
70
|
-
model: LanguageModel.GPT3_5,
|
|
71
|
-
params: {
|
|
72
|
-
frequency_penalty: 0,
|
|
73
|
-
presence_penalty: 0,
|
|
74
|
-
temperature: 0.6,
|
|
75
|
-
top_p: 1,
|
|
76
|
-
},
|
|
77
|
-
plugins: [],
|
|
78
|
-
tts: {
|
|
79
|
-
showAllLocaleVoice: false,
|
|
80
|
-
sttLocale: 'auto',
|
|
81
|
-
ttsService: 'openai',
|
|
82
|
-
voice: {
|
|
83
|
-
openai: 'alloy',
|
|
84
|
-
},
|
|
85
|
-
},
|
|
86
|
-
},
|
|
87
|
-
meta: {
|
|
88
|
-
avatar: 'Default Agent',
|
|
89
|
-
description: 'Default agent for testing',
|
|
90
|
-
},
|
|
91
|
-
},
|
|
92
|
-
tts: {
|
|
93
|
-
openAI: {
|
|
94
|
-
sttModel: 'whisper-1',
|
|
95
|
-
ttsModel: 'tts-1',
|
|
96
|
-
},
|
|
97
|
-
sttAutoStop: true,
|
|
98
|
-
sttServer: 'openai',
|
|
99
|
-
},
|
|
100
|
-
languageModel: {
|
|
101
|
-
openAI: {
|
|
102
|
-
OPENAI_API_KEY: 'openai-api-key',
|
|
103
|
-
endpoint: 'https://openai-endpoint.com',
|
|
104
|
-
models: ['gpt-3.5-turbo'],
|
|
105
|
-
},
|
|
106
|
-
},
|
|
107
|
-
});
|
|
57
|
+
expect(result).toMatchSnapshot();
|
|
108
58
|
});
|
|
109
59
|
});
|
|
110
60
|
|
|
@@ -1,8 +1,10 @@
|
|
|
1
1
|
import { produce } from 'immer';
|
|
2
|
+
import { DeepPartial } from 'utility-types';
|
|
2
3
|
import type { StateCreator } from 'zustand/vanilla';
|
|
3
4
|
|
|
4
5
|
import { LobeAgentSettings } from '@/types/session';
|
|
5
6
|
import type { GlobalSettings } from '@/types/settings';
|
|
7
|
+
import { merge } from '@/utils/merge';
|
|
6
8
|
import { setNamespace } from '@/utils/storeDebug';
|
|
7
9
|
|
|
8
10
|
import type { GlobalStore } from '../store';
|
|
@@ -13,7 +15,7 @@ const t = setNamespace('settings');
|
|
|
13
15
|
* 设置操作
|
|
14
16
|
*/
|
|
15
17
|
export interface AgentAction {
|
|
16
|
-
updateDefaultAgent: (agent:
|
|
18
|
+
updateDefaultAgent: (agent: DeepPartial<LobeAgentSettings>) => void;
|
|
17
19
|
}
|
|
18
20
|
|
|
19
21
|
export const createAgentSlice: StateCreator<
|
|
@@ -24,7 +26,7 @@ export const createAgentSlice: StateCreator<
|
|
|
24
26
|
> = (set, get) => ({
|
|
25
27
|
updateDefaultAgent: (agent) => {
|
|
26
28
|
const settings = produce(get().settings, (draft: GlobalSettings) => {
|
|
27
|
-
draft.defaultAgent =
|
|
29
|
+
draft.defaultAgent = merge(draft.defaultAgent, agent);
|
|
28
30
|
});
|
|
29
31
|
|
|
30
32
|
set({ settings }, false, t('updateDefaultAgent', agent));
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { produce } from 'immer';
|
|
2
2
|
import { StateCreator } from 'zustand/vanilla';
|
|
3
3
|
|
|
4
|
+
import { useGlobalStore } from '@/store/global';
|
|
4
5
|
import { MetaData } from '@/types/meta';
|
|
5
6
|
import { LobeAgentConfig } from '@/types/session';
|
|
6
7
|
|
|
@@ -39,11 +40,22 @@ export const createAgentSlice: StateCreator<
|
|
|
39
40
|
},
|
|
40
41
|
|
|
41
42
|
updateAgentConfig: (config) => {
|
|
42
|
-
const { activeId } = get();
|
|
43
|
+
const { activeId, dispatchSession } = get();
|
|
43
44
|
const session = sessionSelectors.currentSession(get());
|
|
44
45
|
if (!activeId || !session) return;
|
|
45
46
|
|
|
46
|
-
|
|
47
|
+
// if is the inbox session, update the global config
|
|
48
|
+
if (sessionSelectors.isInboxSession(get())) {
|
|
49
|
+
useGlobalStore.getState().updateDefaultAgent({ config });
|
|
50
|
+
// NOTE: DON'T ADD RETURN HERE.
|
|
51
|
+
// we need to use `dispatchSession` below to update inbox config to trigger the inbox config rerender
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// Although we use global store to store the default agent config,
|
|
55
|
+
// due to the `currentAgentConfig` selector use `useGlobalStore.getState()`
|
|
56
|
+
// to get the default agent config which not rerender on global store update
|
|
57
|
+
// we need to update the session config here.
|
|
58
|
+
dispatchSession({ config, id: activeId, type: 'updateSessionConfig' });
|
|
47
59
|
},
|
|
48
60
|
|
|
49
61
|
updateAgentMeta: (meta) => {
|
|
@@ -2,7 +2,8 @@ import { t } from 'i18next';
|
|
|
2
2
|
|
|
3
3
|
import { DEFAULT_OPENAI_MODEL_LIST, VISION_MODEL_WHITE_LIST } from '@/const/llm';
|
|
4
4
|
import { DEFAULT_AVATAR, DEFAULT_BACKGROUND_COLOR } from '@/const/meta';
|
|
5
|
-
import { DEFAUTT_AGENT_TTS_CONFIG } from '@/const/settings';
|
|
5
|
+
import { DEFAULT_AGENT_CONFIG, DEFAUTT_AGENT_TTS_CONFIG } from '@/const/settings';
|
|
6
|
+
import { settingsSelectors, useGlobalStore } from '@/store/global';
|
|
6
7
|
import { SessionStore } from '@/store/session';
|
|
7
8
|
import { LanguageModel } from '@/types/llm';
|
|
8
9
|
import { MetaData } from '@/types/meta';
|
|
@@ -10,7 +11,6 @@ import { LobeAgentTTSConfig } from '@/types/session';
|
|
|
10
11
|
import { merge } from '@/utils/merge';
|
|
11
12
|
|
|
12
13
|
import { sessionSelectors } from '../session/selectors';
|
|
13
|
-
import { initialLobeAgentConfig } from './initialState';
|
|
14
14
|
|
|
15
15
|
const currentAgentMeta = (s: SessionStore): MetaData => {
|
|
16
16
|
const session = sessionSelectors.currentSession(s);
|
|
@@ -22,7 +22,13 @@ const currentAgentTitle = (s: SessionStore) => currentAgentMeta(s)?.title || t('
|
|
|
22
22
|
|
|
23
23
|
const currentAgentConfig = (s: SessionStore) => {
|
|
24
24
|
const session = sessionSelectors.currentSession(s);
|
|
25
|
-
|
|
25
|
+
|
|
26
|
+
// if is the inbox session, use the default agent config in global store
|
|
27
|
+
if (sessionSelectors.isInboxSession(s)) {
|
|
28
|
+
return settingsSelectors.defaultAgentConfig(useGlobalStore.getState());
|
|
29
|
+
}
|
|
30
|
+
|
|
31
|
+
return merge(DEFAULT_AGENT_CONFIG, session?.config);
|
|
26
32
|
};
|
|
27
33
|
|
|
28
34
|
const currentAgentSystemRole = (s: SessionStore) => {
|
|
@@ -14,7 +14,7 @@ import { isFunctionMessageAtStart, testFunctionMessageAtEnd } from '@/utils/mess
|
|
|
14
14
|
import { setNamespace } from '@/utils/storeDebug';
|
|
15
15
|
import { nanoid } from '@/utils/uuid';
|
|
16
16
|
|
|
17
|
-
import { agentSelectors } from '../../
|
|
17
|
+
import { agentSelectors } from '../../agent/selectors';
|
|
18
18
|
import { sessionSelectors } from '../../session/selectors';
|
|
19
19
|
import { FileDispatch, filesReducer } from '../reducers/files';
|
|
20
20
|
import { MessageDispatch, messagesReducer } from '../reducers/message';
|
|
@@ -388,7 +388,11 @@ export const chatMessage: StateCreator<
|
|
|
388
388
|
// check activeTopic and then auto create topic
|
|
389
389
|
const chats = chatSelectors.currentChats(get());
|
|
390
390
|
|
|
391
|
-
|
|
391
|
+
const agentConfig = agentSelectors.currentAgentConfig(get());
|
|
392
|
+
// if autoCreateTopic is false, then stop
|
|
393
|
+
if (!agentConfig.enableAutoCreateTopic) return;
|
|
394
|
+
|
|
395
|
+
if (!activeTopicId && chats.length >= agentConfig.autoCreateTopicThreshold) {
|
|
392
396
|
const { saveToTopic, toggleTopic } = get();
|
|
393
397
|
const id = await saveToTopic();
|
|
394
398
|
if (id) toggleTopic(id);
|
|
@@ -7,7 +7,7 @@ import { genShareGPTUrl } from '@/services/shareGPT';
|
|
|
7
7
|
import { SessionStore } from '@/store/session';
|
|
8
8
|
import { ShareGPTConversation } from '@/types/share';
|
|
9
9
|
|
|
10
|
-
import { agentSelectors } from '../../
|
|
10
|
+
import { agentSelectors } from '../../agent';
|
|
11
11
|
import { sessionSelectors } from '../../session/selectors';
|
|
12
12
|
import { chatSelectors } from '../selectors';
|
|
13
13
|
|
|
@@ -7,7 +7,7 @@ import { useGlobalStore } from '@/store/global';
|
|
|
7
7
|
import { ChatMessage } from '@/types/chatMessage';
|
|
8
8
|
|
|
9
9
|
import type { SessionStore } from '../../../store';
|
|
10
|
-
import { agentSelectors } from '../../
|
|
10
|
+
import { agentSelectors } from '../../agent';
|
|
11
11
|
import { sessionSelectors } from '../../session/selectors';
|
|
12
12
|
import { getSlicedMessagesWithConfig } from '../utils';
|
|
13
13
|
import { currentTopics } from './topic';
|
|
@@ -40,6 +40,8 @@ beforeEach(() => {
|
|
|
40
40
|
params: {
|
|
41
41
|
temperature: 0.6,
|
|
42
42
|
},
|
|
43
|
+
autoCreateTopicThreshold: 2,
|
|
44
|
+
enableAutoCreateTopic: true,
|
|
43
45
|
systemRole: '',
|
|
44
46
|
tts: {
|
|
45
47
|
ttsService: 'openai',
|
|
@@ -219,6 +221,8 @@ describe('organizeChats', () => {
|
|
|
219
221
|
},
|
|
220
222
|
},
|
|
221
223
|
config: {
|
|
224
|
+
autoCreateTopicThreshold: 2,
|
|
225
|
+
enableAutoCreateTopic: true,
|
|
222
226
|
model: 'gpt-4',
|
|
223
227
|
params: {
|
|
224
228
|
temperature: 0.6,
|
|
@@ -1,10 +1,9 @@
|
|
|
1
|
-
import { merge } from 'lodash-es';
|
|
2
1
|
import { AppRouterInstance } from 'next/dist/shared/lib/app-router-context.shared-runtime';
|
|
3
2
|
|
|
4
3
|
import { DEFAULT_AGENT_META, DEFAULT_INBOX_AVATAR } from '@/const/meta';
|
|
5
|
-
import {
|
|
6
|
-
|
|
7
|
-
import {
|
|
4
|
+
import { DEFAULT_AGENT_CONFIG } from '@/const/settings';
|
|
5
|
+
import { LobeAgentSession, LobeSessionType } from '@/types/session';
|
|
6
|
+
import { merge } from '@/utils/merge';
|
|
8
7
|
|
|
9
8
|
export interface SessionState {
|
|
10
9
|
/**
|
|
@@ -23,7 +22,7 @@ export interface SessionState {
|
|
|
23
22
|
|
|
24
23
|
export const initLobeSession: LobeAgentSession = {
|
|
25
24
|
chats: {},
|
|
26
|
-
config:
|
|
25
|
+
config: DEFAULT_AGENT_CONFIG,
|
|
27
26
|
createAt: Date.now(),
|
|
28
27
|
files: [],
|
|
29
28
|
id: '',
|
|
@@ -31,16 +30,12 @@ export const initLobeSession: LobeAgentSession = {
|
|
|
31
30
|
type: LobeSessionType.Agent,
|
|
32
31
|
updateAt: Date.now(),
|
|
33
32
|
};
|
|
34
|
-
|
|
35
|
-
export const initInbox = merge({}, initLobeSession, {
|
|
36
|
-
config: {
|
|
37
|
-
systemRole: '',
|
|
38
|
-
} as LobeAgentConfig,
|
|
33
|
+
export const initInbox: LobeAgentSession = merge(initLobeSession, {
|
|
39
34
|
id: 'inbox',
|
|
40
35
|
meta: {
|
|
41
36
|
avatar: DEFAULT_INBOX_AVATAR,
|
|
42
37
|
},
|
|
43
|
-
}
|
|
38
|
+
});
|
|
44
39
|
|
|
45
40
|
export const initialSessionState: SessionState = {
|
|
46
41
|
activeId: 'inbox',
|
|
@@ -7,7 +7,7 @@ import { isDev } from '@/utils/env';
|
|
|
7
7
|
|
|
8
8
|
import { createHyperStorage } from '../middleware/createHyperStorage';
|
|
9
9
|
import { SessionStoreState, initialState } from './initialState';
|
|
10
|
-
import { AgentAction, createAgentSlice } from './slices/
|
|
10
|
+
import { AgentAction, createAgentSlice } from './slices/agent/action';
|
|
11
11
|
import { ChatAction, createChatSlice } from './slices/chat/actions';
|
|
12
12
|
import { SessionAction, createSessionSlice } from './slices/session/action';
|
|
13
13
|
|
package/src/types/session.ts
CHANGED