@lobehub/chat 1.24.0 → 1.24.2
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 +2 -2
- package/src/app/(main)/chat/(workspace)/_layout/Desktop/Portal.tsx +8 -8
- package/src/config/modelProviders/google.ts +16 -1
- package/src/const/layoutTokens.ts +3 -2
- package/src/libs/agent-runtime/google/index.test.ts +4 -91
- package/src/libs/agent-runtime/google/index.ts +5 -49
package/CHANGELOG.md
CHANGED
@@ -2,6 +2,56 @@
|
|
2
2
|
|
3
3
|
# Changelog
|
4
4
|
|
5
|
+
### [Version 1.24.2](https://github.com/lobehub/lobe-chat/compare/v1.24.1...v1.24.2)
|
6
|
+
|
7
|
+
<sup>Released on **2024-10-26**</sup>
|
8
|
+
|
9
|
+
#### 💄 Styles
|
10
|
+
|
11
|
+
- **misc**: Update Google Model list, add `gemini-1.5-flash-8b`.
|
12
|
+
|
13
|
+
<br/>
|
14
|
+
|
15
|
+
<details>
|
16
|
+
<summary><kbd>Improvements and Fixes</kbd></summary>
|
17
|
+
|
18
|
+
#### Styles
|
19
|
+
|
20
|
+
- **misc**: Update Google Model list, add `gemini-1.5-flash-8b`, closes [#4495](https://github.com/lobehub/lobe-chat/issues/4495) ([499c479](https://github.com/lobehub/lobe-chat/commit/499c479))
|
21
|
+
|
22
|
+
</details>
|
23
|
+
|
24
|
+
<div align="right">
|
25
|
+
|
26
|
+
[](#readme-top)
|
27
|
+
|
28
|
+
</div>
|
29
|
+
|
30
|
+
### [Version 1.24.1](https://github.com/lobehub/lobe-chat/compare/v1.24.0...v1.24.1)
|
31
|
+
|
32
|
+
<sup>Released on **2024-10-25**</sup>
|
33
|
+
|
34
|
+
#### ♻ Code Refactoring
|
35
|
+
|
36
|
+
- **misc**: Refactor the Google Gen AI.
|
37
|
+
|
38
|
+
<br/>
|
39
|
+
|
40
|
+
<details>
|
41
|
+
<summary><kbd>Improvements and Fixes</kbd></summary>
|
42
|
+
|
43
|
+
#### Code refactoring
|
44
|
+
|
45
|
+
- **misc**: Refactor the Google Gen AI, closes [#4484](https://github.com/lobehub/lobe-chat/issues/4484) ([b890e8d](https://github.com/lobehub/lobe-chat/commit/b890e8d))
|
46
|
+
|
47
|
+
</details>
|
48
|
+
|
49
|
+
<div align="right">
|
50
|
+
|
51
|
+
[](#readme-top)
|
52
|
+
|
53
|
+
</div>
|
54
|
+
|
5
55
|
## [Version 1.24.0](https://github.com/lobehub/lobe-chat/compare/v1.23.1...v1.24.0)
|
6
56
|
|
7
57
|
<sup>Released on **2024-10-25**</sup>
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@lobehub/chat",
|
3
|
-
"version": "1.24.
|
3
|
+
"version": "1.24.2",
|
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",
|
@@ -116,7 +116,7 @@
|
|
116
116
|
"@clerk/themes": "^2.1.37",
|
117
117
|
"@codesandbox/sandpack-react": "^2.19.9",
|
118
118
|
"@cyntler/react-doc-viewer": "^1.17.0",
|
119
|
-
"@google/generative-ai": "^0.
|
119
|
+
"@google/generative-ai": "^0.21.0",
|
120
120
|
"@huggingface/inference": "^2.8.1",
|
121
121
|
"@icons-pack/react-simple-icons": "9.6.0",
|
122
122
|
"@khmyznikov/pwa-install": "^0.3.9",
|
@@ -6,7 +6,11 @@ import { rgba } from 'polished';
|
|
6
6
|
import { PropsWithChildren, memo } from 'react';
|
7
7
|
import { Flexbox } from 'react-layout-kit';
|
8
8
|
|
9
|
-
import {
|
9
|
+
import {
|
10
|
+
CHAT_PORTAL_MAX_WIDTH,
|
11
|
+
CHAT_PORTAL_TOOL_UI_WIDTH,
|
12
|
+
CHAT_PORTAL_WIDTH,
|
13
|
+
} from '@/const/layoutTokens';
|
10
14
|
import { useChatStore } from '@/store/chat';
|
11
15
|
import { chatPortalSelectors } from '@/store/chat/slices/portal/selectors';
|
12
16
|
|
@@ -25,12 +29,8 @@ const useStyles = createStyles(({ css, token, isDarkMode }) => ({
|
|
25
29
|
`,
|
26
30
|
panel: css`
|
27
31
|
overflow: hidden;
|
28
|
-
|
29
32
|
height: 100%;
|
30
|
-
margin: 4px;
|
31
|
-
|
32
33
|
background: ${isDarkMode ? rgba(token.colorBgElevated, 0.8) : token.colorBgElevated};
|
33
|
-
border-radius: 8px;
|
34
34
|
`,
|
35
35
|
}));
|
36
36
|
|
@@ -53,8 +53,8 @@ const PortalPanel = memo(({ children }: PropsWithChildren) => {
|
|
53
53
|
}}
|
54
54
|
expand
|
55
55
|
hanlderStyle={{ display: 'none' }}
|
56
|
-
maxWidth={
|
57
|
-
minWidth={showArtifactUI || showToolUI ?
|
56
|
+
maxWidth={CHAT_PORTAL_MAX_WIDTH}
|
57
|
+
minWidth={showArtifactUI || showToolUI ? CHAT_PORTAL_TOOL_UI_WIDTH : CHAT_PORTAL_WIDTH}
|
58
58
|
mode={md ? 'fixed' : 'float'}
|
59
59
|
placement={'right'}
|
60
60
|
showHandlerWhenUnexpand={false}
|
@@ -65,7 +65,7 @@ const PortalPanel = memo(({ children }: PropsWithChildren) => {
|
|
65
65
|
flex: 'none',
|
66
66
|
height: '100%',
|
67
67
|
maxHeight: '100vh',
|
68
|
-
minWidth:
|
68
|
+
minWidth: CHAT_PORTAL_WIDTH,
|
69
69
|
}}
|
70
70
|
>
|
71
71
|
<Flexbox className={styles.panel}>{children}</Flexbox>
|
@@ -64,7 +64,22 @@ const Google: ModelProviderCard = {
|
|
64
64
|
tokens: 1_000_000 + 8192,
|
65
65
|
vision: true,
|
66
66
|
},
|
67
|
-
|
67
|
+
{
|
68
|
+
description: 'Gemini 1.5 Flash 8B 是一款高效的多模态模型,支持广泛应用的扩展。',
|
69
|
+
displayName: 'Gemini 1.5 Flash 8B',
|
70
|
+
enabled: true,
|
71
|
+
functionCall: true,
|
72
|
+
id: 'gemini-1.5-flash-8b',
|
73
|
+
maxOutput: 8192,
|
74
|
+
pricing: {
|
75
|
+
cachedInput: 0.02,
|
76
|
+
input: 0.075,
|
77
|
+
output: 0.3,
|
78
|
+
},
|
79
|
+
releasedAt: '2024-10-03',
|
80
|
+
tokens: 1_000_000 + 8192,
|
81
|
+
vision: true,
|
82
|
+
},
|
68
83
|
{
|
69
84
|
description:
|
70
85
|
'Gemini 1.5 Flash 8B 0924 是最新的实验性模型,在文本和多模态用例中都有显著的性能提升。',
|
@@ -8,8 +8,9 @@ export const CHAT_TEXTAREA_HEIGHT = 160;
|
|
8
8
|
export const CHAT_TEXTAREA_HEIGHT_MOBILE = 108;
|
9
9
|
export const CHAT_SIDEBAR_WIDTH = 280;
|
10
10
|
|
11
|
-
export const
|
12
|
-
export const
|
11
|
+
export const CHAT_PORTAL_WIDTH = 400;
|
12
|
+
export const CHAT_PORTAL_MAX_WIDTH = 1280;
|
13
|
+
export const CHAT_PORTAL_TOOL_UI_WIDTH = 600;
|
13
14
|
|
14
15
|
export const MARKET_SIDEBAR_WIDTH = 400;
|
15
16
|
export const FOLDER_WIDTH = 270;
|
@@ -1,6 +1,5 @@
|
|
1
1
|
// @vitest-environment edge-runtime
|
2
|
-
import {
|
3
|
-
import { JSONSchema7 } from 'json-schema';
|
2
|
+
import { FunctionDeclarationsTool } from '@google/generative-ai';
|
4
3
|
import OpenAI from 'openai';
|
5
4
|
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
6
5
|
|
@@ -479,10 +478,10 @@ describe('LobeGoogleAI', () => {
|
|
479
478
|
name: 'testTool',
|
480
479
|
description: 'A test tool',
|
481
480
|
parameters: {
|
482
|
-
type:
|
481
|
+
type: 'object',
|
483
482
|
properties: {
|
484
|
-
param1: { type:
|
485
|
-
param2: { type:
|
483
|
+
param1: { type: 'string' },
|
484
|
+
param2: { type: 'number' },
|
486
485
|
},
|
487
486
|
required: ['param1'],
|
488
487
|
},
|
@@ -490,92 +489,6 @@ describe('LobeGoogleAI', () => {
|
|
490
489
|
});
|
491
490
|
});
|
492
491
|
|
493
|
-
describe('convertSchemaObject', () => {
|
494
|
-
it('should correctly convert object schema', () => {
|
495
|
-
const schema: JSONSchema7 = {
|
496
|
-
type: 'object',
|
497
|
-
properties: {
|
498
|
-
prop1: { type: 'string' },
|
499
|
-
prop2: { type: 'number' },
|
500
|
-
},
|
501
|
-
};
|
502
|
-
|
503
|
-
const converted = instance['convertSchemaObject'](schema);
|
504
|
-
|
505
|
-
expect(converted).toEqual({
|
506
|
-
type: FunctionDeclarationSchemaType.OBJECT,
|
507
|
-
properties: {
|
508
|
-
prop1: { type: FunctionDeclarationSchemaType.STRING },
|
509
|
-
prop2: { type: FunctionDeclarationSchemaType.NUMBER },
|
510
|
-
},
|
511
|
-
});
|
512
|
-
});
|
513
|
-
|
514
|
-
it('should correctly convert nested schema', () => {
|
515
|
-
const schema: JSONSchema7 = {
|
516
|
-
type: 'object',
|
517
|
-
properties: {
|
518
|
-
nested: {
|
519
|
-
type: 'array',
|
520
|
-
items: {
|
521
|
-
type: 'object',
|
522
|
-
properties: {
|
523
|
-
prop: { type: 'string' },
|
524
|
-
},
|
525
|
-
},
|
526
|
-
},
|
527
|
-
},
|
528
|
-
};
|
529
|
-
|
530
|
-
const converted = instance['convertSchemaObject'](schema);
|
531
|
-
|
532
|
-
expect(converted).toEqual({
|
533
|
-
type: FunctionDeclarationSchemaType.OBJECT,
|
534
|
-
properties: {
|
535
|
-
nested: {
|
536
|
-
type: FunctionDeclarationSchemaType.ARRAY,
|
537
|
-
items: {
|
538
|
-
type: FunctionDeclarationSchemaType.OBJECT,
|
539
|
-
properties: {
|
540
|
-
prop: { type: FunctionDeclarationSchemaType.STRING },
|
541
|
-
},
|
542
|
-
},
|
543
|
-
},
|
544
|
-
},
|
545
|
-
});
|
546
|
-
});
|
547
|
-
|
548
|
-
it('should correctly convert array schema', () => {
|
549
|
-
const schema: JSONSchema7 = {
|
550
|
-
type: 'array',
|
551
|
-
items: { type: 'string' },
|
552
|
-
};
|
553
|
-
const converted = instance['convertSchemaObject'](schema);
|
554
|
-
expect(converted).toEqual({
|
555
|
-
type: FunctionDeclarationSchemaType.ARRAY,
|
556
|
-
items: { type: FunctionDeclarationSchemaType.STRING },
|
557
|
-
});
|
558
|
-
});
|
559
|
-
|
560
|
-
it('should correctly convert string schema', () => {
|
561
|
-
const schema: JSONSchema7 = { type: 'string' };
|
562
|
-
const converted = instance['convertSchemaObject'](schema);
|
563
|
-
expect(converted).toEqual({ type: FunctionDeclarationSchemaType.STRING });
|
564
|
-
});
|
565
|
-
|
566
|
-
it('should correctly convert number schema', () => {
|
567
|
-
const schema: JSONSchema7 = { type: 'number' };
|
568
|
-
const converted = instance['convertSchemaObject'](schema);
|
569
|
-
expect(converted).toEqual({ type: FunctionDeclarationSchemaType.NUMBER });
|
570
|
-
});
|
571
|
-
|
572
|
-
it('should correctly convert boolean schema', () => {
|
573
|
-
const schema: JSONSchema7 = { type: 'boolean' };
|
574
|
-
const converted = instance['convertSchemaObject'](schema);
|
575
|
-
expect(converted).toEqual({ type: FunctionDeclarationSchemaType.BOOLEAN });
|
576
|
-
});
|
577
|
-
});
|
578
|
-
|
579
492
|
describe('convertOAIMessagesToGoogleMessage', () => {
|
580
493
|
it('should correctly convert assistant message', async () => {
|
581
494
|
const message: OpenAIChatMessage = {
|
@@ -2,14 +2,11 @@ import {
|
|
2
2
|
Content,
|
3
3
|
FunctionCallPart,
|
4
4
|
FunctionDeclaration,
|
5
|
-
FunctionDeclarationSchemaProperty,
|
6
|
-
FunctionDeclarationSchemaType,
|
7
5
|
Tool as GoogleFunctionCallTool,
|
8
6
|
GoogleGenerativeAI,
|
9
7
|
Part,
|
8
|
+
SchemaType,
|
10
9
|
} from '@google/generative-ai';
|
11
|
-
import { JSONSchema7 } from 'json-schema';
|
12
|
-
import { transform } from 'lodash-es';
|
13
10
|
|
14
11
|
import { imageUrlToBase64 } from '@/utils/imageToBase64';
|
15
12
|
import { safeParseJSON } from '@/utils/safeParseJSON';
|
@@ -190,13 +187,12 @@ export class LobeGoogleAI implements LobeRuntimeAI {
|
|
190
187
|
};
|
191
188
|
};
|
192
189
|
|
193
|
-
// convert messages from the
|
194
|
-
// that is expected by the Google GenAI SDK
|
190
|
+
// convert messages from the OpenAI format to Google GenAI SDK
|
195
191
|
private buildGoogleMessages = async (
|
196
192
|
messages: OpenAIChatMessage[],
|
197
193
|
model: string,
|
198
194
|
): Promise<Content[]> => {
|
199
|
-
// if the model is gemini-1.0 we
|
195
|
+
// if the model is gemini-1.0 we need to pair messages
|
200
196
|
if (model.startsWith('gemini-1.0')) {
|
201
197
|
const contents: Content[] = [];
|
202
198
|
let lastRole = 'model';
|
@@ -298,52 +294,12 @@ export class LobeGoogleAI implements LobeRuntimeAI {
|
|
298
294
|
name: functionDeclaration.name,
|
299
295
|
parameters: {
|
300
296
|
description: parameters?.description,
|
301
|
-
properties:
|
302
|
-
result[key] = this.convertSchemaObject(value as JSONSchema7);
|
303
|
-
}),
|
297
|
+
properties: parameters?.properties,
|
304
298
|
required: parameters?.required,
|
305
|
-
type:
|
299
|
+
type: SchemaType.OBJECT,
|
306
300
|
},
|
307
301
|
};
|
308
302
|
};
|
309
|
-
|
310
|
-
private convertSchemaObject(schema: JSONSchema7): FunctionDeclarationSchemaProperty {
|
311
|
-
switch (schema.type) {
|
312
|
-
default:
|
313
|
-
case 'object': {
|
314
|
-
return {
|
315
|
-
...schema,
|
316
|
-
properties: Object.fromEntries(
|
317
|
-
Object.entries(schema.properties || {}).map(([key, value]) => [
|
318
|
-
key,
|
319
|
-
this.convertSchemaObject(value as JSONSchema7),
|
320
|
-
]),
|
321
|
-
),
|
322
|
-
type: FunctionDeclarationSchemaType.OBJECT,
|
323
|
-
} as any;
|
324
|
-
}
|
325
|
-
|
326
|
-
case 'array': {
|
327
|
-
return {
|
328
|
-
...schema,
|
329
|
-
items: this.convertSchemaObject(schema.items as JSONSchema7),
|
330
|
-
type: FunctionDeclarationSchemaType.ARRAY,
|
331
|
-
} as any;
|
332
|
-
}
|
333
|
-
|
334
|
-
case 'string': {
|
335
|
-
return { ...schema, type: FunctionDeclarationSchemaType.STRING } as any;
|
336
|
-
}
|
337
|
-
|
338
|
-
case 'number': {
|
339
|
-
return { ...schema, type: FunctionDeclarationSchemaType.NUMBER } as any;
|
340
|
-
}
|
341
|
-
|
342
|
-
case 'boolean': {
|
343
|
-
return { ...schema, type: FunctionDeclarationSchemaType.BOOLEAN } as any;
|
344
|
-
}
|
345
|
-
}
|
346
|
-
}
|
347
303
|
}
|
348
304
|
|
349
305
|
export default LobeGoogleAI;
|