@lobehub/chat 1.36.16 → 1.36.18
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
CHANGED
@@ -2,6 +2,48 @@
|
|
2
2
|
|
3
3
|
# Changelog
|
4
4
|
|
5
|
+
### [Version 1.36.18](https://github.com/lobehub/lobe-chat/compare/v1.36.17...v1.36.18)
|
6
|
+
|
7
|
+
<sup>Released on **2024-12-12**</sup>
|
8
|
+
|
9
|
+
#### 🐛 Bug Fixes
|
10
|
+
|
11
|
+
- **misc**: Fix claude first message can not be `assistant`.
|
12
|
+
|
13
|
+
<br/>
|
14
|
+
|
15
|
+
<details>
|
16
|
+
<summary><kbd>Improvements and Fixes</kbd></summary>
|
17
|
+
|
18
|
+
#### What's fixed
|
19
|
+
|
20
|
+
- **misc**: Fix claude first message can not be `assistant`, closes [#5001](https://github.com/lobehub/lobe-chat/issues/5001) ([063cd61](https://github.com/lobehub/lobe-chat/commit/063cd61))
|
21
|
+
|
22
|
+
</details>
|
23
|
+
|
24
|
+
<div align="right">
|
25
|
+
|
26
|
+
[](#readme-top)
|
27
|
+
|
28
|
+
</div>
|
29
|
+
|
30
|
+
### [Version 1.36.17](https://github.com/lobehub/lobe-chat/compare/v1.36.16...v1.36.17)
|
31
|
+
|
32
|
+
<sup>Released on **2024-12-12**</sup>
|
33
|
+
|
34
|
+
<br/>
|
35
|
+
|
36
|
+
<details>
|
37
|
+
<summary><kbd>Improvements and Fixes</kbd></summary>
|
38
|
+
|
39
|
+
</details>
|
40
|
+
|
41
|
+
<div align="right">
|
42
|
+
|
43
|
+
[](#readme-top)
|
44
|
+
|
45
|
+
</div>
|
46
|
+
|
5
47
|
### [Version 1.36.16](https://github.com/lobehub/lobe-chat/compare/v1.36.15...v1.36.16)
|
6
48
|
|
7
49
|
<sup>Released on **2024-12-12**</sup>
|
package/changelog/v1.json
CHANGED
@@ -1,4 +1,18 @@
|
|
1
1
|
[
|
2
|
+
{
|
3
|
+
"children": {
|
4
|
+
"fixes": [
|
5
|
+
"Fix claude first message can not be assistant."
|
6
|
+
]
|
7
|
+
},
|
8
|
+
"date": "2024-12-12",
|
9
|
+
"version": "1.36.18"
|
10
|
+
},
|
11
|
+
{
|
12
|
+
"children": {},
|
13
|
+
"date": "2024-12-12",
|
14
|
+
"version": "1.36.17"
|
15
|
+
},
|
2
16
|
{
|
3
17
|
"children": {
|
4
18
|
"improvements": [
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@lobehub/chat",
|
3
|
-
"version": "1.36.
|
3
|
+
"version": "1.36.18",
|
4
4
|
"description": "Lobe Chat - an open-source, high-performance chatbot framework that supports speech synthesis, multimodal, and extensible Function Call plugin system. Supports one-click free deployment of your private ChatGPT/LLM web application.",
|
5
5
|
"keywords": [
|
6
6
|
"framework",
|
@@ -228,6 +228,21 @@ describe('anthropicHelpers', () => {
|
|
228
228
|
]);
|
229
229
|
});
|
230
230
|
|
231
|
+
it('messages should start with user', async () => {
|
232
|
+
const messages: OpenAIChatMessage[] = [
|
233
|
+
{ content: 'Hi', role: 'assistant' },
|
234
|
+
{ content: 'Hello', role: 'user' },
|
235
|
+
];
|
236
|
+
|
237
|
+
const contents = await buildAnthropicMessages(messages);
|
238
|
+
|
239
|
+
expect(contents).toHaveLength(2);
|
240
|
+
expect(contents).toEqual([
|
241
|
+
{ content: 'Hi', role: 'user' },
|
242
|
+
{ content: 'Hello', role: 'user' },
|
243
|
+
]);
|
244
|
+
});
|
245
|
+
|
231
246
|
it('messages should end with user', async () => {
|
232
247
|
const messages: OpenAIChatMessage[] = [
|
233
248
|
{ content: 'Hello', role: 'user' },
|
@@ -237,10 +252,9 @@ describe('anthropicHelpers', () => {
|
|
237
252
|
|
238
253
|
const contents = await buildAnthropicMessages(messages);
|
239
254
|
|
240
|
-
expect(contents).toHaveLength(
|
255
|
+
expect(contents).toHaveLength(3);
|
241
256
|
expect(contents).toEqual([
|
242
257
|
{ content: 'Hello', role: 'user' },
|
243
|
-
{ content: '_', role: 'assistant' },
|
244
258
|
{ content: 'Hello', role: 'user' },
|
245
259
|
{ content: 'Hi', role: 'assistant' },
|
246
260
|
]);
|
@@ -257,15 +271,11 @@ describe('anthropicHelpers', () => {
|
|
257
271
|
|
258
272
|
const contents = await buildAnthropicMessages(messages);
|
259
273
|
|
260
|
-
expect(contents).toHaveLength(
|
274
|
+
expect(contents).toHaveLength(5);
|
261
275
|
expect(contents).toEqual([
|
262
|
-
{ content: '
|
263
|
-
{ content: 'a', role: 'assistant' },
|
264
|
-
{ content: '_', role: 'user' },
|
276
|
+
{ content: 'a', role: 'user' },
|
265
277
|
{ content: 'b', role: 'assistant' },
|
266
|
-
{ content: '_', role: 'user' },
|
267
278
|
{ content: 'c', role: 'assistant' },
|
268
|
-
{ content: '_', role: 'user' },
|
269
279
|
{ content: 'd', role: 'assistant' },
|
270
280
|
{ content: '你好', role: 'user' },
|
271
281
|
]);
|
@@ -370,7 +380,6 @@ describe('anthropicHelpers', () => {
|
|
370
380
|
],
|
371
381
|
role: 'user',
|
372
382
|
},
|
373
|
-
{ content: '_', role: 'assistant' },
|
374
383
|
{ content: '继续', role: 'user' },
|
375
384
|
]);
|
376
385
|
});
|
@@ -114,11 +114,11 @@ export const buildAnthropicMessages = async (
|
|
114
114
|
oaiMessages: OpenAIChatMessage[],
|
115
115
|
): Promise<Anthropic.Messages.MessageParam[]> => {
|
116
116
|
const messages: Anthropic.Messages.MessageParam[] = [];
|
117
|
-
let lastRole = 'assistant';
|
118
117
|
let pendingToolResults: Anthropic.ToolResultBlockParam[] = [];
|
119
118
|
|
120
119
|
for (const message of oaiMessages) {
|
121
120
|
const index = oaiMessages.indexOf(message);
|
121
|
+
|
122
122
|
// refs: https://docs.anthropic.com/claude/docs/tool-use#tool-use-and-tool-result-content-blocks
|
123
123
|
if (message.role === 'tool') {
|
124
124
|
pendingToolResults.push({
|
@@ -135,17 +135,14 @@ export const buildAnthropicMessages = async (
|
|
135
135
|
role: 'user',
|
136
136
|
});
|
137
137
|
pendingToolResults = [];
|
138
|
-
lastRole = 'user';
|
139
138
|
}
|
140
139
|
} else {
|
141
140
|
const anthropicMessage = await buildAnthropicMessage(message);
|
142
141
|
|
143
|
-
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
lastRole = anthropicMessage.role;
|
148
|
-
messages.push(anthropicMessage);
|
142
|
+
messages.push({
|
143
|
+
...anthropicMessage,
|
144
|
+
role: index === 0 && anthropicMessage.role === 'assistant' ? 'user' : anthropicMessage.role,
|
145
|
+
});
|
149
146
|
}
|
150
147
|
}
|
151
148
|
|
@@ -1,9 +1,9 @@
|
|
1
1
|
export const encodeAsync = async (str: string): Promise<number> => {
|
2
2
|
if (str.length === 0) return 0;
|
3
3
|
|
4
|
-
//
|
5
|
-
// if the string is longer than
|
6
|
-
if (str.length <=
|
4
|
+
// 30_000 is the limit of the client
|
5
|
+
// if the string is longer than 30_000, we will use the server
|
6
|
+
if (str.length <= 30_000) {
|
7
7
|
const { clientEncodeAsync } = await import('./client');
|
8
8
|
|
9
9
|
return await clientEncodeAsync(str);
|