@lobehub/chat 1.36.17 → 1.36.19

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,56 @@
2
2
 
3
3
  # Changelog
4
4
 
5
+ ### [Version 1.36.19](https://github.com/lobehub/lobe-chat/compare/v1.36.18...v1.36.19)
6
+
7
+ <sup>Released on **2024-12-13**</sup>
8
+
9
+ #### 🐛 Bug Fixes
10
+
11
+ - **misc**: One of Gemini functionCall error.
12
+
13
+ <br/>
14
+
15
+ <details>
16
+ <summary><kbd>Improvements and Fixes</kbd></summary>
17
+
18
+ #### What's fixed
19
+
20
+ - **misc**: One of Gemini functionCall error, closes [#5002](https://github.com/lobehub/lobe-chat/issues/5002) ([3c7f5ff](https://github.com/lobehub/lobe-chat/commit/3c7f5ff))
21
+
22
+ </details>
23
+
24
+ <div align="right">
25
+
26
+ [![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)
27
+
28
+ </div>
29
+
30
+ ### [Version 1.36.18](https://github.com/lobehub/lobe-chat/compare/v1.36.17...v1.36.18)
31
+
32
+ <sup>Released on **2024-12-12**</sup>
33
+
34
+ #### 🐛 Bug Fixes
35
+
36
+ - **misc**: Fix claude first message can not be `assistant`.
37
+
38
+ <br/>
39
+
40
+ <details>
41
+ <summary><kbd>Improvements and Fixes</kbd></summary>
42
+
43
+ #### What's fixed
44
+
45
+ - **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))
46
+
47
+ </details>
48
+
49
+ <div align="right">
50
+
51
+ [![](https://img.shields.io/badge/-BACK_TO_TOP-151515?style=flat-square)](#readme-top)
52
+
53
+ </div>
54
+
5
55
  ### [Version 1.36.17](https://github.com/lobehub/lobe-chat/compare/v1.36.16...v1.36.17)
6
56
 
7
57
  <sup>Released on **2024-12-12**</sup>
package/changelog/v1.json CHANGED
@@ -1,4 +1,22 @@
1
1
  [
2
+ {
3
+ "children": {
4
+ "fixes": [
5
+ "One of Gemini functionCall error."
6
+ ]
7
+ },
8
+ "date": "2024-12-13",
9
+ "version": "1.36.19"
10
+ },
11
+ {
12
+ "children": {
13
+ "fixes": [
14
+ "Fix claude first message can not be assistant."
15
+ ]
16
+ },
17
+ "date": "2024-12-12",
18
+ "version": "1.36.18"
19
+ },
2
20
  {
3
21
  "children": {},
4
22
  "date": "2024-12-12",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@lobehub/chat",
3
- "version": "1.36.17",
3
+ "version": "1.36.19",
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",
@@ -91,12 +91,7 @@ export class LobeGoogleAI implements LobeRuntimeAI {
91
91
  .generateContentStream({
92
92
  contents,
93
93
  systemInstruction: payload.system as string,
94
- tools: (() => {
95
- if (!payload.tools && model.startsWith('gemini-2.0')) {
96
- return [{ googleSearch: {} } as GoogleFunctionCallTool];
97
- }
98
- return this.buildGoogleTools(payload.tools);
99
- })(),
94
+ tools: this.buildGoogleTools(payload.tools),
100
95
  });
101
96
 
102
97
  const googleStream = convertIterableToStream(geminiStreamResult.stream);
@@ -293,13 +288,17 @@ export class LobeGoogleAI implements LobeRuntimeAI {
293
288
  private convertToolToGoogleTool = (tool: ChatCompletionTool): FunctionDeclaration => {
294
289
  const functionDeclaration = tool.function;
295
290
  const parameters = functionDeclaration.parameters;
291
+ // refs: https://github.com/lobehub/lobe-chat/pull/5002
292
+ const properties = parameters?.properties && Object.keys(parameters.properties).length > 0
293
+ ? parameters.properties
294
+ : { dummy: { type: 'string' } }; // dummy property to avoid empty object
296
295
 
297
296
  return {
298
297
  description: functionDeclaration.description,
299
298
  name: functionDeclaration.name,
300
299
  parameters: {
301
300
  description: parameters?.description,
302
- properties: parameters?.properties,
301
+ properties: properties,
303
302
  required: parameters?.required,
304
303
  type: SchemaType.OBJECT,
305
304
  },
@@ -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(4);
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(9);
274
+ expect(contents).toHaveLength(5);
261
275
  expect(contents).toEqual([
262
- { content: '_', role: 'user' },
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
- if (lastRole === anthropicMessage.role) {
144
- messages.push({ content: '_', role: lastRole === 'user' ? 'assistant' : 'user' });
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