@lobehub/chat 0.107.4 → 0.107.6
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/package.json +1 -1
- package/src/database/models/__DEBUG.ts +14 -9
- package/src/database/models/__tests__/message.test.ts +13 -0
- package/src/services/debug.ts +29 -2
- package/src/services/message.ts +5 -0
- package/src/store/chat/actions/message.ts +7 -6
- package/src/store/chat/actions/plugin.ts +2 -2
- package/src/store/chat/actions/topic.ts +1 -1
- package/src/utils/fetch.ts +3 -3
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,56 @@
|
|
|
2
2
|
|
|
3
3
|
# Changelog
|
|
4
4
|
|
|
5
|
+
### [Version 0.107.6](https://github.com/lobehub/lobe-chat/compare/v0.107.5...v0.107.6)
|
|
6
|
+
|
|
7
|
+
<sup>Released on **2023-11-30**</sup>
|
|
8
|
+
|
|
9
|
+
#### 🐛 Bug Fixes
|
|
10
|
+
|
|
11
|
+
- **misc**: 修正调用插件查询的显示问题.
|
|
12
|
+
|
|
13
|
+
<br/>
|
|
14
|
+
|
|
15
|
+
<details>
|
|
16
|
+
<summary><kbd>Improvements and Fixes</kbd></summary>
|
|
17
|
+
|
|
18
|
+
#### What's fixed
|
|
19
|
+
|
|
20
|
+
- **misc**: 修正调用插件查询的显示问题 ([671ccef](https://github.com/lobehub/lobe-chat/commit/671ccef))
|
|
21
|
+
|
|
22
|
+
</details>
|
|
23
|
+
|
|
24
|
+
<div align="right">
|
|
25
|
+
|
|
26
|
+
[](#readme-top)
|
|
27
|
+
|
|
28
|
+
</div>
|
|
29
|
+
|
|
30
|
+
### [Version 0.107.5](https://github.com/lobehub/lobe-chat/compare/v0.107.4...v0.107.5)
|
|
31
|
+
|
|
32
|
+
<sup>Released on **2023-11-30**</sup>
|
|
33
|
+
|
|
34
|
+
#### 🐛 Bug Fixes
|
|
35
|
+
|
|
36
|
+
- **misc**: 修正调用插件查询的显示问题.
|
|
37
|
+
|
|
38
|
+
<br/>
|
|
39
|
+
|
|
40
|
+
<details>
|
|
41
|
+
<summary><kbd>Improvements and Fixes</kbd></summary>
|
|
42
|
+
|
|
43
|
+
#### What's fixed
|
|
44
|
+
|
|
45
|
+
- **misc**: 修正调用插件查询的显示问题 ([1457fe8](https://github.com/lobehub/lobe-chat/commit/1457fe8))
|
|
46
|
+
|
|
47
|
+
</details>
|
|
48
|
+
|
|
49
|
+
<div align="right">
|
|
50
|
+
|
|
51
|
+
[](#readme-top)
|
|
52
|
+
|
|
53
|
+
</div>
|
|
54
|
+
|
|
5
55
|
### [Version 0.107.4](https://github.com/lobehub/lobe-chat/compare/v0.107.3...v0.107.4)
|
|
6
56
|
|
|
7
57
|
<sup>Released on **2023-11-30**</sup>
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lobehub/chat",
|
|
3
|
-
"version": "0.107.
|
|
3
|
+
"version": "0.107.6",
|
|
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",
|
|
@@ -34,7 +34,12 @@ class _DEBUG_MODEL extends BaseModel<'sessions'> {
|
|
|
34
34
|
return array[randomIndex];
|
|
35
35
|
}
|
|
36
36
|
|
|
37
|
-
createRandomData = async ({
|
|
37
|
+
createRandomData = async ({
|
|
38
|
+
sessionCount = 10,
|
|
39
|
+
topicCount = 2000,
|
|
40
|
+
messageCount = 10_000,
|
|
41
|
+
startIndex = 1,
|
|
42
|
+
}) => {
|
|
38
43
|
const numberOfSessions = sessionCount;
|
|
39
44
|
const numberOfTopics = topicCount;
|
|
40
45
|
const numberOfMessages = messageCount;
|
|
@@ -45,7 +50,7 @@ class _DEBUG_MODEL extends BaseModel<'sessions'> {
|
|
|
45
50
|
const messagesData: DBModel<DB_Message>[] = [];
|
|
46
51
|
|
|
47
52
|
// Prepare sessions
|
|
48
|
-
for (let i =
|
|
53
|
+
for (let i = startIndex; i < numberOfSessions + startIndex; i++) {
|
|
49
54
|
sessionsData.push({
|
|
50
55
|
config: DEFAULT_AGENT_CONFIG,
|
|
51
56
|
createdAt: this.randomDate(new Date(2020, 0, 1), new Date()),
|
|
@@ -61,30 +66,30 @@ class _DEBUG_MODEL extends BaseModel<'sessions'> {
|
|
|
61
66
|
}
|
|
62
67
|
|
|
63
68
|
// Prepare topics
|
|
64
|
-
for (let i =
|
|
69
|
+
for (let i = startIndex; i < numberOfTopics + startIndex; i++) {
|
|
65
70
|
topicsData.push({
|
|
66
71
|
createdAt: this.randomDate(new Date(2020, 0, 1), new Date()),
|
|
67
72
|
favorite: this.getRandomInt(0, 1),
|
|
68
73
|
id: `topic_${i}`,
|
|
69
|
-
sessionId: `sess_${this.getRandomInt(
|
|
74
|
+
sessionId: `sess_${this.getRandomInt(startIndex, numberOfSessions)}`,
|
|
70
75
|
title: `Topic Title ${i}`,
|
|
71
76
|
updatedAt: this.randomDate(new Date(2020, 0, 1), new Date()),
|
|
72
77
|
});
|
|
73
78
|
}
|
|
74
79
|
|
|
75
80
|
// Prepare messages
|
|
76
|
-
for (let i =
|
|
81
|
+
for (let i = startIndex; i < numberOfMessages + startIndex; i++) {
|
|
77
82
|
messagesData.push({
|
|
78
83
|
content: this.randomString(300),
|
|
79
84
|
createdAt: this.randomDate(new Date(2020, 0, 1), new Date()),
|
|
80
85
|
favorite: this.getRandomInt(0, 1),
|
|
81
86
|
fromModel: 'model',
|
|
82
87
|
id: `msg_${i}`,
|
|
83
|
-
parentId: `msg_${this.getRandomInt(
|
|
84
|
-
quotaId: `msg_${this.getRandomInt(
|
|
88
|
+
parentId: `msg_${this.getRandomInt(startIndex, numberOfMessages)}`,
|
|
89
|
+
quotaId: `msg_${this.getRandomInt(startIndex, numberOfMessages)}`,
|
|
85
90
|
role: this.randomPick(['user', 'assistant']),
|
|
86
|
-
sessionId: `sess_${this.getRandomInt(
|
|
87
|
-
topicId: `topic_${this.getRandomInt(
|
|
91
|
+
sessionId: `sess_${this.getRandomInt(startIndex, numberOfSessions)}`,
|
|
92
|
+
topicId: `topic_${this.getRandomInt(startIndex, numberOfTopics)}`,
|
|
88
93
|
updatedAt: this.randomDate(new Date(2020, 0, 1), new Date()),
|
|
89
94
|
});
|
|
90
95
|
}
|
|
@@ -260,6 +260,19 @@ describe('MessageModel', () => {
|
|
|
260
260
|
|
|
261
261
|
expect(updatedMessage).toHaveProperty('content', 'Updated content');
|
|
262
262
|
});
|
|
263
|
+
|
|
264
|
+
it('should update a role and plugins', async () => {
|
|
265
|
+
const createdMessage = await MessageModel.create(messageData);
|
|
266
|
+
const updateData = {
|
|
267
|
+
role: 'function' as const,
|
|
268
|
+
plugin: { apiName: 'a', identifier: 'b', arguments: 'abc' },
|
|
269
|
+
};
|
|
270
|
+
|
|
271
|
+
await MessageModel.update(createdMessage.id, updateData);
|
|
272
|
+
const updatedMessage = await MessageModel.findById(createdMessage.id);
|
|
273
|
+
|
|
274
|
+
expect(updatedMessage).toHaveProperty('role', 'function');
|
|
275
|
+
});
|
|
263
276
|
});
|
|
264
277
|
|
|
265
278
|
describe('batchUpdate', () => {
|
package/src/services/debug.ts
CHANGED
|
@@ -2,11 +2,38 @@ import { DEBUG_MODEL } from '@/database/models/__DEBUG';
|
|
|
2
2
|
|
|
3
3
|
class DebugService {
|
|
4
4
|
async insertLargeDataToDB() {
|
|
5
|
-
|
|
6
|
-
messageCount:
|
|
5
|
+
await DEBUG_MODEL.createRandomData({
|
|
6
|
+
messageCount: 100_000,
|
|
7
7
|
sessionCount: 40,
|
|
8
|
+
startIndex: 0,
|
|
8
9
|
topicCount: 200,
|
|
9
10
|
});
|
|
11
|
+
|
|
12
|
+
console.log('已插入10w');
|
|
13
|
+
|
|
14
|
+
await DEBUG_MODEL.createRandomData({
|
|
15
|
+
messageCount: 300_000,
|
|
16
|
+
sessionCount: 40,
|
|
17
|
+
startIndex: 100_001,
|
|
18
|
+
topicCount: 200,
|
|
19
|
+
});
|
|
20
|
+
console.log('已插入40w');
|
|
21
|
+
|
|
22
|
+
await DEBUG_MODEL.createRandomData({
|
|
23
|
+
messageCount: 300_000,
|
|
24
|
+
sessionCount: 40,
|
|
25
|
+
startIndex: 400_001,
|
|
26
|
+
topicCount: 200,
|
|
27
|
+
});
|
|
28
|
+
console.log('已插入70w');
|
|
29
|
+
|
|
30
|
+
await DEBUG_MODEL.createRandomData({
|
|
31
|
+
messageCount: 300_000,
|
|
32
|
+
sessionCount: 40,
|
|
33
|
+
startIndex: 700_001,
|
|
34
|
+
topicCount: 200,
|
|
35
|
+
});
|
|
36
|
+
console.log('已插入100w');
|
|
10
37
|
}
|
|
11
38
|
}
|
|
12
39
|
|
package/src/services/message.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { CreateMessageParams, MessageModel } from '@/database/models/message';
|
|
2
|
+
import { DB_Message } from '@/database/schemas/message';
|
|
2
3
|
import {
|
|
3
4
|
ChatMessage,
|
|
4
5
|
ChatMessageError,
|
|
@@ -64,6 +65,10 @@ export class MessageService {
|
|
|
64
65
|
return MessageModel.batchUpdate(messageIds, { topicId });
|
|
65
66
|
}
|
|
66
67
|
|
|
68
|
+
async updateMessage(id: string, message: Partial<DB_Message>) {
|
|
69
|
+
return MessageModel.update(id, message);
|
|
70
|
+
}
|
|
71
|
+
|
|
67
72
|
async updateMessageRole(id: string, role: LLMRoleType) {
|
|
68
73
|
return MessageModel.update(id, { role });
|
|
69
74
|
}
|
|
@@ -271,9 +271,9 @@ export const chatMessage: StateCreator<
|
|
|
271
271
|
topicId: activeTopicId,
|
|
272
272
|
};
|
|
273
273
|
functionId = await messageService.create(functionMessage);
|
|
274
|
-
await refreshMessages();
|
|
275
274
|
}
|
|
276
275
|
|
|
276
|
+
await refreshMessages();
|
|
277
277
|
triggerFunctionCall(functionId);
|
|
278
278
|
}
|
|
279
279
|
},
|
|
@@ -287,7 +287,7 @@ export const chatMessage: StateCreator<
|
|
|
287
287
|
set({ messages }, false, t(`dispatchMessage/${payload.type}`, payload));
|
|
288
288
|
},
|
|
289
289
|
fetchAIChatMessage: async (messages, assistantId) => {
|
|
290
|
-
const {
|
|
290
|
+
const { toggleChatLoading, refreshMessages } = get();
|
|
291
291
|
|
|
292
292
|
const abortController = toggleChatLoading(
|
|
293
293
|
true,
|
|
@@ -360,12 +360,13 @@ export const chatMessage: StateCreator<
|
|
|
360
360
|
onFinish: async (content) => {
|
|
361
361
|
// update the content after fetch result
|
|
362
362
|
await messageService.updateMessageContent(assistantId, content);
|
|
363
|
+
await refreshMessages();
|
|
363
364
|
},
|
|
364
|
-
onMessageHandle: (text) => {
|
|
365
|
+
onMessageHandle: async (text) => {
|
|
365
366
|
output += text;
|
|
366
|
-
|
|
367
|
-
|
|
368
|
-
|
|
367
|
+
|
|
368
|
+
await messageService.updateMessageContent(assistantId, output);
|
|
369
|
+
await refreshMessages();
|
|
369
370
|
|
|
370
371
|
// is this message is just a function call
|
|
371
372
|
if (isFunctionMessageAtStart(output)) isFunctionCall = true;
|
|
@@ -81,14 +81,14 @@ export const chatPlugin: StateCreator<
|
|
|
81
81
|
};
|
|
82
82
|
|
|
83
83
|
await messageService.updateMessageContent(id, '');
|
|
84
|
+
await refreshMessages();
|
|
84
85
|
} else {
|
|
85
86
|
if (message.plugin) payload = message.plugin;
|
|
86
87
|
}
|
|
87
88
|
|
|
88
89
|
if (!payload.apiName) return;
|
|
89
90
|
|
|
90
|
-
await messageService.
|
|
91
|
-
await messageService.updateMessagePlugin(id, payload);
|
|
91
|
+
await messageService.updateMessage(id, { plugin: payload, role: 'function' });
|
|
92
92
|
await refreshMessages();
|
|
93
93
|
|
|
94
94
|
if (payload.type === 'standalone') {
|
|
@@ -97,7 +97,7 @@ export const chatTopic: StateCreator<
|
|
|
97
97
|
onError: () => {
|
|
98
98
|
updateTopicTitleInSummary(topicId, topic.title);
|
|
99
99
|
},
|
|
100
|
-
onFinish: (text) => {
|
|
100
|
+
onFinish: async (text) => {
|
|
101
101
|
topicService.updateTitle(topicId, text);
|
|
102
102
|
},
|
|
103
103
|
onLoadingChange: (loading) => {
|
package/src/utils/fetch.ts
CHANGED
|
@@ -27,7 +27,7 @@ export const getMessageError = async (response: Response) => {
|
|
|
27
27
|
|
|
28
28
|
export interface FetchSSEOptions {
|
|
29
29
|
onErrorHandle?: (error: ChatMessageError) => void;
|
|
30
|
-
onFinish?: (text: string) => void
|
|
30
|
+
onFinish?: (text: string) => Promise<void>;
|
|
31
31
|
onMessageHandle?: (text: string) => void;
|
|
32
32
|
}
|
|
33
33
|
|
|
@@ -67,7 +67,7 @@ export const fetchSSE = async (fetchFn: () => Promise<Response>, options: FetchS
|
|
|
67
67
|
options.onMessageHandle?.(chunkValue);
|
|
68
68
|
}
|
|
69
69
|
|
|
70
|
-
options?.onFinish?.(output);
|
|
70
|
+
await options?.onFinish?.(output);
|
|
71
71
|
|
|
72
72
|
return returnRes;
|
|
73
73
|
};
|
|
@@ -78,7 +78,7 @@ interface FetchAITaskResultParams<T> {
|
|
|
78
78
|
* 错误处理函数
|
|
79
79
|
*/
|
|
80
80
|
onError?: (e: Error, rawError?: any) => void;
|
|
81
|
-
onFinish?: (text: string) => void
|
|
81
|
+
onFinish?: (text: string) => Promise<void>;
|
|
82
82
|
/**
|
|
83
83
|
* 加载状态变化处理函数
|
|
84
84
|
* @param loading - 是否处于加载状态
|