@lobehub/chat 1.71.2 → 1.71.3
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 +25 -0
- package/changelog/v1.json +9 -0
- package/package.json +1 -1
- package/src/libs/agent-runtime/anthropic/index.test.ts +3 -3
- package/src/libs/agent-runtime/anthropic/index.ts +3 -1
- package/src/libs/agent-runtime/google/index.test.ts +3 -1
- package/src/libs/agent-runtime/google/index.ts +50 -7
package/CHANGELOG.md
CHANGED
@@ -2,6 +2,31 @@
|
|
2
2
|
|
3
3
|
# Changelog
|
4
4
|
|
5
|
+
### [Version 1.71.3](https://github.com/lobehub/lobe-chat/compare/v1.71.2...v1.71.3)
|
6
|
+
|
7
|
+
<sup>Released on **2025-03-15**</sup>
|
8
|
+
|
9
|
+
#### 🐛 Bug Fixes
|
10
|
+
|
11
|
+
- **misc**: Fix claude 3.5+ models context max output.
|
12
|
+
|
13
|
+
<br/>
|
14
|
+
|
15
|
+
<details>
|
16
|
+
<summary><kbd>Improvements and Fixes</kbd></summary>
|
17
|
+
|
18
|
+
#### What's fixed
|
19
|
+
|
20
|
+
- **misc**: Fix claude 3.5+ models context max output, closes [#6984](https://github.com/lobehub/lobe-chat/issues/6984) ([da342dd](https://github.com/lobehub/lobe-chat/commit/da342dd))
|
21
|
+
|
22
|
+
</details>
|
23
|
+
|
24
|
+
<div align="right">
|
25
|
+
|
26
|
+
[](#readme-top)
|
27
|
+
|
28
|
+
</div>
|
29
|
+
|
5
30
|
### [Version 1.71.2](https://github.com/lobehub/lobe-chat/compare/v1.71.1...v1.71.2)
|
6
31
|
|
7
32
|
<sup>Released on **2025-03-15**</sup>
|
package/changelog/v1.json
CHANGED
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@lobehub/chat",
|
3
|
-
"version": "1.71.
|
3
|
+
"version": "1.71.3",
|
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",
|
@@ -123,21 +123,21 @@ describe('LobeAnthropicAI', () => {
|
|
123
123
|
{ content: 'You are an awesome greeter', role: 'system' },
|
124
124
|
{ content: 'Hello', role: 'user' },
|
125
125
|
],
|
126
|
-
model: 'claude-3-
|
126
|
+
model: 'claude-3-7-sonnet-20250219',
|
127
127
|
temperature: 0,
|
128
128
|
});
|
129
129
|
|
130
130
|
// Assert
|
131
131
|
expect(instance['client'].messages.create).toHaveBeenCalledWith(
|
132
132
|
{
|
133
|
-
max_tokens:
|
133
|
+
max_tokens: 8192,
|
134
134
|
messages: [
|
135
135
|
{
|
136
136
|
content: [{ cache_control: { type: 'ephemeral' }, text: 'Hello', type: 'text' }],
|
137
137
|
role: 'user',
|
138
138
|
},
|
139
139
|
],
|
140
|
-
model: 'claude-3-
|
140
|
+
model: 'claude-3-7-sonnet-20250219',
|
141
141
|
stream: true,
|
142
142
|
system: [
|
143
143
|
{
|
@@ -25,6 +25,8 @@ export interface AnthropicModelCard {
|
|
25
25
|
id: string;
|
26
26
|
}
|
27
27
|
|
28
|
+
const modelsWithSmallContextWindow = new Set(['claude-3-opus-20240229', 'claude-3-haiku-20240307']);
|
29
|
+
|
28
30
|
const DEFAULT_BASE_URL = 'https://api.anthropic.com';
|
29
31
|
|
30
32
|
interface AnthropicAIParams extends ClientOptions {
|
@@ -132,7 +134,7 @@ export class LobeAnthropicAI implements LobeRuntimeAI {
|
|
132
134
|
return {
|
133
135
|
// claude 3 series model hax max output token of 4096, 3.x series has 8192
|
134
136
|
// https://docs.anthropic.com/en/docs/about-claude/models/all-models#:~:text=200K-,Max%20output,-Normal%3A
|
135
|
-
max_tokens: max_tokens ?? (
|
137
|
+
max_tokens: max_tokens ?? (modelsWithSmallContextWindow.has(model) ? 4096 : 8192),
|
136
138
|
messages: postMessages,
|
137
139
|
model,
|
138
140
|
system: systemPrompts,
|
@@ -340,7 +340,9 @@ describe('LobeGoogleAI', () => {
|
|
340
340
|
expect(e).toEqual({
|
341
341
|
errorType: bizErrorType,
|
342
342
|
error: {
|
343
|
-
message: `
|
343
|
+
message: `API key not valid. Please pass a valid API key. [{"@type":"type.googleapis.com/google.rpc.ErrorInfo","reason":"Error","domain":"googleapis.com","metadata":{"service":"generativelanguage.googleapis.com}}]`,
|
344
|
+
statusCode: 400,
|
345
|
+
statusCodeText: '[400 Bad Request]',
|
344
346
|
},
|
345
347
|
provider,
|
346
348
|
});
|
@@ -325,12 +325,12 @@ export class LobeGoogleAI implements LobeRuntimeAI {
|
|
325
325
|
if (message.includes('location is not supported'))
|
326
326
|
return { error: { message }, errorType: AgentRuntimeErrorType.LocationNotSupportError };
|
327
327
|
|
328
|
-
|
329
|
-
|
330
|
-
|
331
|
-
|
332
|
-
}
|
328
|
+
const startIndex = message.lastIndexOf('[');
|
329
|
+
if (startIndex === -1) {
|
330
|
+
return defaultError;
|
331
|
+
}
|
333
332
|
|
333
|
+
try {
|
334
334
|
// 从开始位置截取字符串到最后
|
335
335
|
const jsonString = message.slice(startIndex);
|
336
336
|
|
@@ -349,9 +349,18 @@ export class LobeGoogleAI implements LobeRuntimeAI {
|
|
349
349
|
}
|
350
350
|
}
|
351
351
|
} catch {
|
352
|
-
//
|
353
|
-
return defaultError;
|
352
|
+
//
|
354
353
|
}
|
354
|
+
|
355
|
+
const errorObj = this.extractErrorObjectFromError(message);
|
356
|
+
|
357
|
+
const { errorDetails } = errorObj;
|
358
|
+
|
359
|
+
if (errorDetails) {
|
360
|
+
return { error: errorDetails, errorType: AgentRuntimeErrorType.ProviderBizError };
|
361
|
+
}
|
362
|
+
|
363
|
+
return defaultError;
|
355
364
|
}
|
356
365
|
|
357
366
|
private buildGoogleTools(
|
@@ -392,6 +401,40 @@ export class LobeGoogleAI implements LobeRuntimeAI {
|
|
392
401
|
},
|
393
402
|
};
|
394
403
|
};
|
404
|
+
|
405
|
+
private extractErrorObjectFromError(message: string) {
|
406
|
+
// 使用正则表达式匹配状态码部分 [数字 描述文本]
|
407
|
+
const regex = /^(.*?)(\[\d+ [^\]]+])(.*)$/;
|
408
|
+
const match = message.match(regex);
|
409
|
+
|
410
|
+
if (match) {
|
411
|
+
const prefix = match[1].trim();
|
412
|
+
const statusCodeWithBrackets = match[2].trim();
|
413
|
+
const message = match[3].trim();
|
414
|
+
|
415
|
+
// 提取状态码数字
|
416
|
+
const statusCodeMatch = statusCodeWithBrackets.match(/\[(\d+)/);
|
417
|
+
const statusCode = statusCodeMatch ? parseInt(statusCodeMatch[1]) : null;
|
418
|
+
|
419
|
+
// 创建包含状态码和消息的JSON
|
420
|
+
const resultJson = {
|
421
|
+
message: message,
|
422
|
+
statusCode: statusCode,
|
423
|
+
statusCodeText: statusCodeWithBrackets,
|
424
|
+
};
|
425
|
+
|
426
|
+
return {
|
427
|
+
errorDetails: resultJson,
|
428
|
+
prefix: prefix,
|
429
|
+
};
|
430
|
+
}
|
431
|
+
|
432
|
+
// 如果无法匹配,返回原始消息
|
433
|
+
return {
|
434
|
+
errorDetails: null,
|
435
|
+
prefix: message,
|
436
|
+
};
|
437
|
+
}
|
395
438
|
}
|
396
439
|
|
397
440
|
export default LobeGoogleAI;
|