@lobehub/chat 0.115.13 → 0.116.1
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/README.md +10 -7
- package/README.zh-CN.md +10 -7
- package/package.json +2 -1
- package/src/const/message.ts +2 -2
- package/src/database/models/message.ts +1 -0
- package/src/features/PluginSettings/PluginSettingRender.tsx +22 -2
- package/src/features/PluginSettings/index.tsx +7 -1
- package/src/services/__tests__/chat.test.ts +73 -57
- package/src/services/chat.ts +2 -3
- package/src/store/chat/slices/tool/action.test.ts +31 -6
- package/src/store/chat/slices/tool/action.ts +8 -5
- package/src/store/tool/selectors/tool.test.ts +28 -3
- package/src/store/tool/selectors/tool.ts +3 -3
- package/src/types/message/index.ts +3 -7
- package/src/types/message/tools.ts +6 -0
- package/src/types/openai/chat.ts +14 -1
- package/src/types/openai/functionCall.ts +6 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,56 @@
|
|
|
2
2
|
|
|
3
3
|
# Changelog
|
|
4
4
|
|
|
5
|
+
### [Version 0.116.1](https://github.com/lobehub/lobe-chat/compare/v0.116.0...v0.116.1)
|
|
6
|
+
|
|
7
|
+
<sup>Released on **2023-12-26**</sup>
|
|
8
|
+
|
|
9
|
+
#### 💄 Styles
|
|
10
|
+
|
|
11
|
+
- **misc**: Support slider and select plugin setting render.
|
|
12
|
+
|
|
13
|
+
<br/>
|
|
14
|
+
|
|
15
|
+
<details>
|
|
16
|
+
<summary><kbd>Improvements and Fixes</kbd></summary>
|
|
17
|
+
|
|
18
|
+
#### Styles
|
|
19
|
+
|
|
20
|
+
- **misc**: Support slider and select plugin setting render, closes [#819](https://github.com/lobehub/lobe-chat/issues/819) ([3190b44](https://github.com/lobehub/lobe-chat/commit/3190b44))
|
|
21
|
+
|
|
22
|
+
</details>
|
|
23
|
+
|
|
24
|
+
<div align="right">
|
|
25
|
+
|
|
26
|
+
[](#readme-top)
|
|
27
|
+
|
|
28
|
+
</div>
|
|
29
|
+
|
|
30
|
+
## [Version 0.116.0](https://github.com/lobehub/lobe-chat/compare/v0.115.13...v0.116.0)
|
|
31
|
+
|
|
32
|
+
<sup>Released on **2023-12-26**</sup>
|
|
33
|
+
|
|
34
|
+
#### ✨ Features
|
|
35
|
+
|
|
36
|
+
- **misc**: Support OpenAI tool calls.
|
|
37
|
+
|
|
38
|
+
<br/>
|
|
39
|
+
|
|
40
|
+
<details>
|
|
41
|
+
<summary><kbd>Improvements and Fixes</kbd></summary>
|
|
42
|
+
|
|
43
|
+
#### What's improved
|
|
44
|
+
|
|
45
|
+
- **misc**: Support OpenAI tool calls ([9681fdc](https://github.com/lobehub/lobe-chat/commit/9681fdc))
|
|
46
|
+
|
|
47
|
+
</details>
|
|
48
|
+
|
|
49
|
+
<div align="right">
|
|
50
|
+
|
|
51
|
+
[](#readme-top)
|
|
52
|
+
|
|
53
|
+
</div>
|
|
54
|
+
|
|
5
55
|
### [Version 0.115.13](https://github.com/lobehub/lobe-chat/compare/v0.115.12...v0.115.13)
|
|
6
56
|
|
|
7
57
|
<sup>Released on **2023-12-26**</sup>
|
package/README.md
CHANGED
|
@@ -37,6 +37,7 @@ Supports one-click free deployment of your private ChatGPT/LLM web application.
|
|
|
37
37
|
[![][share-reddit-shield]][share-reddit-link]
|
|
38
38
|
[![][share-weibo-shield]][share-weibo-link]
|
|
39
39
|
[![][share-mastodon-shield]][share-mastodon-link]
|
|
40
|
+
[![][share-linkedin-shield]][share-linkedin-link]
|
|
40
41
|
|
|
41
42
|
<sup>Pioneering the new age of thinking and creating. Built for you, the Super Individual.</sup>
|
|
42
43
|
|
|
@@ -207,14 +208,14 @@ Our marketplace is not just a showcase platform but also a collaborative space.
|
|
|
207
208
|
|
|
208
209
|
<!-- AGENT LIST -->
|
|
209
210
|
|
|
210
|
-
| Recent Submits
|
|
211
|
-
|
|
|
212
|
-
| [
|
|
213
|
-
| [
|
|
214
|
-
| [
|
|
215
|
-
| [
|
|
211
|
+
| Recent Submits | Description |
|
|
212
|
+
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
213
|
+
| [Academic Proofreading Expert](https://chat-preview.lobehub.com/market?agent=academic-paragraph-refiner)<br/><sup>By **[Feliks151450](https://github.com/Feliks151450)** on **2023-12-26**</sup> | Highly skilled in advanced research proofreading and language editing, specializing in multiple research fields and proficient in academic English.<br/>`proofreading` `writing` `research` |
|
|
214
|
+
| [Flutter Maestro](https://chat-preview.lobehub.com/market?agent=flutter-dev)<br/><sup>By **[kamaravichow](https://github.com/kamaravichow)** on **2023-12-25**</sup> | A developer expert in Flutter framework and Dart programming language.<br/>`flutter` `development` `dart` `programming` `widgets` |
|
|
215
|
+
| [Facebook Ads Expert](https://chat-preview.lobehub.com/market?agent=facebook-ads-expert)<br/><sup>By **[alissonryan](https://github.com/alissonryan)** on **2023-12-20**</sup> | Create a Facebook Ads with a expert<br/>`copywriting` `facebook-ads` `lead-generation` |
|
|
216
|
+
| [Dream Painter](https://chat-preview.lobehub.com/market?agent=dream-painter)<br/><sup>By **[ccdanpian](https://github.com/ccdanpian)** on **2023-12-19**</sup> | A dream artist who can bring your dreams into reality.<br/>`txt-2-img` `painter` |
|
|
216
217
|
|
|
217
|
-
> 📊 Total agents: [<kbd>**
|
|
218
|
+
> 📊 Total agents: [<kbd>**79**</kbd> ](https://github.com/lobehub/lobe-chat-agents)
|
|
218
219
|
|
|
219
220
|
<!-- AGENT LIST -->
|
|
220
221
|
|
|
@@ -626,6 +627,8 @@ This project is [MIT](./LICENSE) licensed.
|
|
|
626
627
|
[pr-welcome-link]: https://github.com/lobehub/lobe-chat/pulls
|
|
627
628
|
[pr-welcome-shield]: https://img.shields.io/badge/🤯_pr_welcome-%E2%86%92-ffcb47?labelColor=black&style=for-the-badge
|
|
628
629
|
[profile-link]: https://github.com/lobehub
|
|
630
|
+
[share-linkedin-link]: https://linkedin.com/feed
|
|
631
|
+
[share-linkedin-shield]: https://img.shields.io/badge/-share%20on%20linkedin-black?labelColor=black&logo=linkedin&logoColor=white&style=flat-square
|
|
629
632
|
[share-mastodon-link]: https://mastodon.social/share?text=Check%20this%20GitHub%20repository%20out%20%F0%9F%A4%AF%20LobeChat%20-%20An%20open-source,%20extensible%20(Function%20Calling),%20high-performance%20chatbot%20framework.%20It%20supports%20one-click%20free%20deployment%20of%20your%20private%20ChatGPT/LLM%20web%20application.%20https://github.com/lobehub/lobe-chat%20#chatbot%20#chatGPT%20#openAI
|
|
630
633
|
[share-mastodon-shield]: https://img.shields.io/badge/-share%20on%20mastodon-black?labelColor=black&logo=mastodon&logoColor=white&style=flat-square
|
|
631
634
|
[share-reddit-link]: https://www.reddit.com/submit?title=Check%20this%20GitHub%20repository%20out%20%F0%9F%A4%AF%20LobeChat%20-%20An%20open-source%2C%20extensible%20%28Function%20Calling%29%2C%20high-performance%20chatbot%20framework.%20It%20supports%20one-click%20free%20deployment%20of%20your%20private%20ChatGPT%2FLLM%20web%20application.%20%23chatbot%20%23chatGPT%20%23openAI&url=https%3A%2F%2Fgithub.com%2Flobehub%2Flobe-chat
|
package/README.zh-CN.md
CHANGED
|
@@ -35,6 +35,7 @@ LobeChat 是开源的高性能聊天机器人框架,支持语音合成、多
|
|
|
35
35
|
[![][share-whatsapp-shield]][share-whatsapp-link]
|
|
36
36
|
[![][share-reddit-shield]][share-reddit-link]
|
|
37
37
|
[![][share-weibo-shield]][share-weibo-link]
|
|
38
|
+
[![][share-mastodon-shield]][share-mastodon-link]
|
|
38
39
|
|
|
39
40
|

|
|
40
41
|
|
|
@@ -183,14 +184,14 @@ LobeChat 的插件生态系统是其核心功能的重要扩展,它极大地
|
|
|
183
184
|
|
|
184
185
|
<!-- AGENT LIST -->
|
|
185
186
|
|
|
186
|
-
| 最近新增
|
|
187
|
-
|
|
|
188
|
-
| [
|
|
189
|
-
| [
|
|
190
|
-
| [
|
|
191
|
-
| [
|
|
187
|
+
| 最近新增 | 助手说明 |
|
|
188
|
+
| -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------- |
|
|
189
|
+
| [学术润色专家](https://chat-preview.lobehub.com/market?agent=academic-paragraph-refiner)<br/><sup>By **[Feliks151450](https://github.com/Feliks151450)** on **2023-12-26**</sup> | 高级研究校对及语言编辑,专业于多个研究领域,精通学术英语。<br/>`校对` `写作` `研究` |
|
|
190
|
+
| [Flutter 开发专家](https://chat-preview.lobehub.com/market?agent=flutter-dev)<br/><sup>By **[kamaravichow](https://github.com/kamaravichow)** on **2023-12-25**</sup> | 一位精通 Flutter 框架和 Dart 编程语言的开发者<br/>`flutter` `development` `dart` `programming` `widgets` |
|
|
191
|
+
| [Facebook 广告专家](https://chat-preview.lobehub.com/market?agent=facebook-ads-expert)<br/><sup>By **[alissonryan](https://github.com/alissonryan)** on **2023-12-20**</sup> | 与专家一起创建 Facebook 广告<br/>`文案撰写` `facebook广告` `潜在客户生成` |
|
|
192
|
+
| [梦境画家](https://chat-preview.lobehub.com/market?agent=dream-painter)<br/><sup>By **[ccdanpian](https://github.com/ccdanpian)** on **2023-12-19**</sup> | 一位能将你的梦想变成现实的梦境艺术家。<br/>`txt-2-img` `painter` |
|
|
192
193
|
|
|
193
|
-
> 📊 Total agents: [<kbd>**
|
|
194
|
+
> 📊 Total agents: [<kbd>**79**</kbd> ](https://github.com/lobehub/lobe-chat-agents)
|
|
194
195
|
|
|
195
196
|
<!-- AGENT LIST -->
|
|
196
197
|
|
|
@@ -597,6 +598,8 @@ This project is [MIT](./LICENSE) licensed.
|
|
|
597
598
|
[pr-welcome-link]: https://github.com/lobehub/lobe-chat/pulls
|
|
598
599
|
[pr-welcome-shield]: https://img.shields.io/badge/🤯_pr_welcome-%E2%86%92-ffcb47?labelColor=black&style=for-the-badge
|
|
599
600
|
[profile-link]: https://github.com/lobehub
|
|
601
|
+
[share-mastodon-link]: https://mastodon.social/share?text=Check%20this%20GitHub%20repository%20out%20%F0%9F%A4%AF%20LobeChat%20-%20An%20open-source,%20extensible%20(Function%20Calling),%20high-performance%20chatbot%20framework.%20It%20supports%20one-click%20free%20deployment%20of%20your%20private%20ChatGPT/LLM%20web%20application.%20https://github.com/lobehub/lobe-chat%20#chatbot%20#chatGPT%20#openAI
|
|
602
|
+
[share-mastodon-shield]: https://img.shields.io/badge/-share%20on%20mastodon-black?labelColor=black&logo=mastodon&logoColor=white&style=flat-square
|
|
600
603
|
[share-reddit-link]: https://www.reddit.com/submit?title=%E6%8E%A8%E8%8D%90%E4%B8%80%E4%B8%AA%20GitHub%20%E5%BC%80%E6%BA%90%E9%A1%B9%E7%9B%AE%20%F0%9F%A4%AF%20LobeChat%20-%20%E5%BC%80%E6%BA%90%E7%9A%84%E3%80%81%E5%8F%AF%E6%89%A9%E5%B1%95%E7%9A%84%EF%BC%88Function%20Calling%EF%BC%89%E9%AB%98%E6%80%A7%E8%83%BD%E8%81%8A%E5%A4%A9%E6%9C%BA%E5%99%A8%E4%BA%BA%E6%A1%86%E6%9E%B6%E3%80%82%0A%E5%AE%83%E6%94%AF%E6%8C%81%E4%B8%80%E9%94%AE%E5%85%8D%E8%B4%B9%E9%83%A8%E7%BD%B2%E7%A7%81%E4%BA%BA%20ChatGPT%2FLLM%20%E7%BD%91%E9%A1%B5%E5%BA%94%E7%94%A8%E7%A8%8B%E5%BA%8F%20%23chatbot%20%23chatGPT%20%23openAI&url=https%3A%2F%2Fgithub.com%2Flobehub%2Flobe-chat
|
|
601
604
|
[share-reddit-shield]: https://img.shields.io/badge/-share%20on%20reddit-black?labelColor=black&logo=reddit&logoColor=white&style=flat-square
|
|
602
605
|
[share-telegram-link]: https://t.me/share/url"?text=%E6%8E%A8%E8%8D%90%E4%B8%80%E4%B8%AA%20GitHub%20%E5%BC%80%E6%BA%90%E9%A1%B9%E7%9B%AE%20%F0%9F%A4%AF%20LobeChat%20-%20%E5%BC%80%E6%BA%90%E7%9A%84%E3%80%81%E5%8F%AF%E6%89%A9%E5%B1%95%E7%9A%84%EF%BC%88Function%20Calling%EF%BC%89%E9%AB%98%E6%80%A7%E8%83%BD%E8%81%8A%E5%A4%A9%E6%9C%BA%E5%99%A8%E4%BA%BA%E6%A1%86%E6%9E%B6%E3%80%82%0A%E5%AE%83%E6%94%AF%E6%8C%81%E4%B8%80%E9%94%AE%E5%85%8D%E8%B4%B9%E9%83%A8%E7%BD%B2%E7%A7%81%E4%BA%BA%20ChatGPT%2FLLM%20%E7%BD%91%E9%A1%B5%E5%BA%94%E7%94%A8%E7%A8%8B%E5%BA%8F%20%23chatbot%20%23chatGPT%20%23openAI&url=https%3A%2F%2Fgithub.com%2Flobehub%2Flobe-chat
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lobehub/chat",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.116.1",
|
|
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",
|
|
@@ -140,6 +140,7 @@
|
|
|
140
140
|
"@testing-library/jest-dom": "^6",
|
|
141
141
|
"@testing-library/react": "^14",
|
|
142
142
|
"@types/chroma-js": "^2",
|
|
143
|
+
"@types/json-schema": "^7.0.15",
|
|
143
144
|
"@types/lodash": "^4",
|
|
144
145
|
"@types/lodash-es": "^4",
|
|
145
146
|
"@types/node": "^20",
|
package/src/const/message.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
export const LOADING_FLAT = '...';
|
|
2
2
|
|
|
3
|
-
//
|
|
4
|
-
export const FUNCTION_MESSAGE_FLAG = '{"
|
|
3
|
+
// start with this,it should be a function message
|
|
4
|
+
export const FUNCTION_MESSAGE_FLAG = '{"tool_calls"';
|
|
5
5
|
|
|
6
6
|
export const FUNCTION_LOADING = 'FUNCTION_LOADING';
|
|
@@ -1,16 +1,20 @@
|
|
|
1
|
-
import { Input, InputNumber, Switch } from 'antd';
|
|
1
|
+
import { Input, InputNumber, Select, Slider, Switch } from 'antd';
|
|
2
|
+
import { JSONSchema7Type } from 'json-schema';
|
|
2
3
|
import { memo } from 'react';
|
|
3
4
|
|
|
4
5
|
interface PluginSettingsProps {
|
|
5
6
|
defaultValue?: any;
|
|
7
|
+
enum?: JSONSchema7Type[];
|
|
6
8
|
format?: string;
|
|
9
|
+
maximum?: number;
|
|
10
|
+
minimum?: number;
|
|
7
11
|
onChange: (value: any) => void;
|
|
8
12
|
props?: any;
|
|
9
13
|
type?: 'string' | 'number' | 'boolean';
|
|
10
14
|
}
|
|
11
15
|
|
|
12
16
|
const PluginSettingRender = memo<PluginSettingsProps>(
|
|
13
|
-
({ type, defaultValue, onChange, format, props }) => {
|
|
17
|
+
({ type, defaultValue, enum: enumItems, onChange, format, minimum, maximum, props }) => {
|
|
14
18
|
switch (type) {
|
|
15
19
|
case 'string': {
|
|
16
20
|
switch (format) {
|
|
@@ -26,6 +30,19 @@ const PluginSettingRender = memo<PluginSettingsProps>(
|
|
|
26
30
|
);
|
|
27
31
|
}
|
|
28
32
|
}
|
|
33
|
+
|
|
34
|
+
if (enumItems) {
|
|
35
|
+
return (
|
|
36
|
+
<Select
|
|
37
|
+
defaultValue={defaultValue}
|
|
38
|
+
onChange={onChange}
|
|
39
|
+
options={enumItems.map((i) =>
|
|
40
|
+
typeof i === 'string' ? { label: i, value: i } : (i as any),
|
|
41
|
+
)}
|
|
42
|
+
/>
|
|
43
|
+
);
|
|
44
|
+
}
|
|
45
|
+
|
|
29
46
|
return (
|
|
30
47
|
<Input
|
|
31
48
|
{...props}
|
|
@@ -36,7 +53,10 @@ const PluginSettingRender = memo<PluginSettingsProps>(
|
|
|
36
53
|
/>
|
|
37
54
|
);
|
|
38
55
|
}
|
|
56
|
+
|
|
39
57
|
case 'number': {
|
|
58
|
+
if (typeof minimum === 'number' || typeof maximum === 'number')
|
|
59
|
+
return <Slider defaultValue={defaultValue} max={maximum} min={minimum} {...props} />;
|
|
40
60
|
return (
|
|
41
61
|
<InputNumber
|
|
42
62
|
{...props}
|
|
@@ -15,8 +15,11 @@ export const transformPluginSettings = (pluginSettings: PluginSchema) => {
|
|
|
15
15
|
|
|
16
16
|
return Object.entries(pluginSettings.properties).map(([name, i]) => ({
|
|
17
17
|
desc: i.description,
|
|
18
|
+
enum: i.enum,
|
|
18
19
|
format: i.format,
|
|
19
|
-
label: i.title,
|
|
20
|
+
label: i.title || name,
|
|
21
|
+
maximum: i.maximum,
|
|
22
|
+
minimum: i.minimum,
|
|
20
23
|
name,
|
|
21
24
|
tag: name,
|
|
22
25
|
type: i.type,
|
|
@@ -63,7 +66,10 @@ const PluginSettingsConfig = memo<PluginSettingsConfigProps>(({ schema, id }) =>
|
|
|
63
66
|
>
|
|
64
67
|
<PluginSettingRender
|
|
65
68
|
defaultValue={pluginSetting[item.name]}
|
|
69
|
+
enum={item.enum}
|
|
66
70
|
format={item.format}
|
|
71
|
+
maximum={item.maximum}
|
|
72
|
+
minimum={item.minimum}
|
|
67
73
|
onChange={(value) => {
|
|
68
74
|
updatePluginSettings(id, { [item.name]: value });
|
|
69
75
|
}}
|
|
@@ -57,7 +57,14 @@ describe('ChatService', () => {
|
|
|
57
57
|
|
|
58
58
|
expect(getChatCompletionSpy).toHaveBeenCalledWith(
|
|
59
59
|
expect.objectContaining({
|
|
60
|
-
|
|
60
|
+
tools: expect.arrayContaining([
|
|
61
|
+
{
|
|
62
|
+
type: 'function',
|
|
63
|
+
function: {
|
|
64
|
+
name: 'plugin1____api1',
|
|
65
|
+
},
|
|
66
|
+
},
|
|
67
|
+
]),
|
|
61
68
|
messages: expect.anything(),
|
|
62
69
|
}),
|
|
63
70
|
undefined,
|
|
@@ -77,7 +84,7 @@ describe('ChatService', () => {
|
|
|
77
84
|
|
|
78
85
|
expect(getChatCompletionSpy).toHaveBeenCalledWith(
|
|
79
86
|
expect.objectContaining({
|
|
80
|
-
|
|
87
|
+
tools: undefined,
|
|
81
88
|
model: modelInWhitelist,
|
|
82
89
|
}),
|
|
83
90
|
undefined,
|
|
@@ -307,14 +314,17 @@ describe('ChatService', () => {
|
|
|
307
314
|
{
|
|
308
315
|
model: 'gpt-3.5-turbo-1106',
|
|
309
316
|
top_p: 1,
|
|
310
|
-
|
|
317
|
+
tools: [
|
|
311
318
|
{
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
319
|
+
type: 'function',
|
|
320
|
+
function: {
|
|
321
|
+
description: 'Get data from users',
|
|
322
|
+
name: 'seo____getData',
|
|
323
|
+
parameters: {
|
|
324
|
+
properties: { keyword: { type: 'string' }, url: { type: 'string' } },
|
|
325
|
+
required: ['keyword', 'url'],
|
|
326
|
+
type: 'object',
|
|
327
|
+
},
|
|
318
328
|
},
|
|
319
329
|
},
|
|
320
330
|
],
|
|
@@ -411,14 +421,17 @@ Get data from users`,
|
|
|
411
421
|
{
|
|
412
422
|
model: 'gpt-3.5-turbo-1106',
|
|
413
423
|
top_p: 1,
|
|
414
|
-
|
|
424
|
+
tools: [
|
|
415
425
|
{
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
426
|
+
type: 'function',
|
|
427
|
+
function: {
|
|
428
|
+
description: 'Get data from users',
|
|
429
|
+
name: 'seo____getData',
|
|
430
|
+
parameters: {
|
|
431
|
+
properties: { keyword: { type: 'string' }, url: { type: 'string' } },
|
|
432
|
+
required: ['keyword', 'url'],
|
|
433
|
+
type: 'object',
|
|
434
|
+
},
|
|
422
435
|
},
|
|
423
436
|
},
|
|
424
437
|
],
|
|
@@ -509,50 +522,53 @@ Get data from users`,
|
|
|
509
522
|
{
|
|
510
523
|
model: 'gpt-3.5-turbo-1106',
|
|
511
524
|
top_p: 1,
|
|
512
|
-
|
|
525
|
+
tools: [
|
|
513
526
|
{
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
|
|
519
|
-
|
|
520
|
-
|
|
521
|
-
|
|
522
|
-
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
|
|
528
|
-
|
|
529
|
-
|
|
530
|
-
|
|
531
|
-
|
|
532
|
-
|
|
533
|
-
|
|
534
|
-
|
|
535
|
-
|
|
536
|
-
|
|
537
|
-
|
|
538
|
-
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
|
|
546
|
-
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
'
|
|
550
|
-
|
|
551
|
-
|
|
527
|
+
type: 'function',
|
|
528
|
+
function: {
|
|
529
|
+
description: 'Create images from a text-only prompt.',
|
|
530
|
+
name: 'dalle3____text2image____builtin',
|
|
531
|
+
parameters: {
|
|
532
|
+
properties: {
|
|
533
|
+
prompts: {
|
|
534
|
+
description:
|
|
535
|
+
"The user's original image description, potentially modified to abide by the dalle policies. If the user does not suggest a number of captions to create, create four of them. If creating multiple captions, make them as diverse as possible. If the user requested modifications to previous images, the captions should not simply be longer, but rather it should be refactored to integrate the suggestions into each of the captions. Generate no more than 4 images, even if the user requests more.",
|
|
536
|
+
items: { type: 'string' },
|
|
537
|
+
maxItems: 4,
|
|
538
|
+
minItems: 1,
|
|
539
|
+
type: 'array',
|
|
540
|
+
},
|
|
541
|
+
quality: {
|
|
542
|
+
default: 'standard',
|
|
543
|
+
description:
|
|
544
|
+
'The quality of the image that will be generated. hd creates images with finer details and greater consistency across the image.',
|
|
545
|
+
enum: ['standard', 'hd'],
|
|
546
|
+
type: 'string',
|
|
547
|
+
},
|
|
548
|
+
seeds: {
|
|
549
|
+
description:
|
|
550
|
+
'A list of seeds to use for each prompt. If the user asks to modify a previous image, populate this field with the seed used to generate that image from the image dalle metadata.',
|
|
551
|
+
items: { type: 'integer' },
|
|
552
|
+
type: 'array',
|
|
553
|
+
},
|
|
554
|
+
size: {
|
|
555
|
+
default: '1024x1024',
|
|
556
|
+
description:
|
|
557
|
+
'The resolution of the requested image, which can be wide, square, or tall. Use 1024x1024 (square) as the default unless the prompt suggests a wide image, 1792x1024, or a full-body portrait, in which case 1024x1792 (tall) should be used instead. Always include this parameter in the request.',
|
|
558
|
+
enum: ['1792x1024', '1024x1024', '1024x1792'],
|
|
559
|
+
type: 'string',
|
|
560
|
+
},
|
|
561
|
+
style: {
|
|
562
|
+
default: 'vivid',
|
|
563
|
+
description:
|
|
564
|
+
'The style of the generated images. Must be one of vivid or natural. Vivid causes the model to lean towards generating hyper-real and dramatic images. Natural causes the model to produce more natural, less hyper-real looking images.',
|
|
565
|
+
enum: ['vivid', 'natural'],
|
|
566
|
+
type: 'string',
|
|
567
|
+
},
|
|
552
568
|
},
|
|
569
|
+
required: ['prompts'],
|
|
570
|
+
type: 'object',
|
|
553
571
|
},
|
|
554
|
-
required: ['prompts'],
|
|
555
|
-
type: 'object',
|
|
556
572
|
},
|
|
557
573
|
},
|
|
558
574
|
],
|
package/src/services/chat.ts
CHANGED
|
@@ -55,10 +55,9 @@ class ChatService {
|
|
|
55
55
|
// 2. model is not in vision white list, because vision model can't use tools
|
|
56
56
|
// TODO: we need to find some method to let vision model use tools
|
|
57
57
|
const shouldUseTools = filterTools.length > 0 && !isVisionModel(payload.model);
|
|
58
|
+
const tools = shouldUseTools ? filterTools : undefined;
|
|
58
59
|
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
return this.getChatCompletion({ ...params, functions, messages: oaiMessages }, options);
|
|
60
|
+
return this.getChatCompletion({ ...params, messages: oaiMessages, tools }, options);
|
|
62
61
|
};
|
|
63
62
|
|
|
64
63
|
getChatCompletion = (params: Partial<OpenAIChatStreamPayload>, options?: FetchOptions) => {
|
|
@@ -139,7 +139,18 @@ describe('ChatPluginAction', () => {
|
|
|
139
139
|
describe('triggerFunctionCall', () => {
|
|
140
140
|
it('should trigger a function call and update the plugin message accordingly', async () => {
|
|
141
141
|
const messageId = 'message-id';
|
|
142
|
-
const messageContent =
|
|
142
|
+
const messageContent = JSON.stringify({
|
|
143
|
+
tool_calls: [
|
|
144
|
+
{
|
|
145
|
+
id: 'call_sbca',
|
|
146
|
+
type: 'function',
|
|
147
|
+
function: {
|
|
148
|
+
name: `pluginName${PLUGIN_SCHEMA_SEPARATOR}apiName`,
|
|
149
|
+
arguments: { key: 'value' },
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
],
|
|
153
|
+
});
|
|
143
154
|
const messagePluginPayload = {
|
|
144
155
|
apiName: 'apiName',
|
|
145
156
|
identifier: 'pluginName',
|
|
@@ -183,7 +194,16 @@ describe('ChatPluginAction', () => {
|
|
|
183
194
|
const id = 'pluginIdentifier';
|
|
184
195
|
const md5ApiName = PLUGIN_SCHEMA_API_MD5_PREFIX + Md5.hashStr(apiName).toString();
|
|
185
196
|
const messageContent = JSON.stringify({
|
|
186
|
-
|
|
197
|
+
tool_calls: [
|
|
198
|
+
{
|
|
199
|
+
id: 'call_sbca',
|
|
200
|
+
type: 'function',
|
|
201
|
+
function: {
|
|
202
|
+
name: id + PLUGIN_SCHEMA_SEPARATOR + md5ApiName,
|
|
203
|
+
arguments: {},
|
|
204
|
+
},
|
|
205
|
+
},
|
|
206
|
+
],
|
|
187
207
|
});
|
|
188
208
|
|
|
189
209
|
const plugin = { identifier: id, manifest: { api: [{ name: apiName }] } } as LobeTool;
|
|
@@ -222,10 +242,15 @@ describe('ChatPluginAction', () => {
|
|
|
222
242
|
it('should handle standalone plugin type', async () => {
|
|
223
243
|
const messageId = 'message-id';
|
|
224
244
|
const messageContent = JSON.stringify({
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
245
|
+
tool_calls: [
|
|
246
|
+
{
|
|
247
|
+
id: 'call_scv',
|
|
248
|
+
function: {
|
|
249
|
+
name: `pluginName${PLUGIN_SCHEMA_SEPARATOR}apiName${PLUGIN_SCHEMA_SEPARATOR}standalone`,
|
|
250
|
+
arguments: {},
|
|
251
|
+
},
|
|
252
|
+
},
|
|
253
|
+
],
|
|
229
254
|
});
|
|
230
255
|
|
|
231
256
|
useChatStore.setState({
|
|
@@ -8,7 +8,7 @@ import { ChatStore } from '@/store/chat/store';
|
|
|
8
8
|
import { useToolStore } from '@/store/tool';
|
|
9
9
|
import { pluginSelectors } from '@/store/tool/selectors';
|
|
10
10
|
import { ChatPluginPayload } from '@/types/message';
|
|
11
|
-
import {
|
|
11
|
+
import { OpenAIToolCall } from '@/types/openai/functionCall';
|
|
12
12
|
import { setNamespace } from '@/utils/storeDebug';
|
|
13
13
|
|
|
14
14
|
import { chatSelectors } from '../../selectors';
|
|
@@ -83,20 +83,22 @@ export const chatPlugin: StateCreator<
|
|
|
83
83
|
await coreProcessMessage(chats, id);
|
|
84
84
|
},
|
|
85
85
|
triggerFunctionCall: async (id) => {
|
|
86
|
-
const { invokeDefaultTypePlugin, invokeBuiltinTool, refreshMessages } = get();
|
|
87
|
-
|
|
88
86
|
const message = chatSelectors.getMessageById(id)(get());
|
|
89
87
|
if (!message) return;
|
|
90
88
|
|
|
89
|
+
const { invokeDefaultTypePlugin, invokeBuiltinTool, refreshMessages } = get();
|
|
90
|
+
|
|
91
91
|
let payload = { apiName: '', identifier: '' } as ChatPluginPayload;
|
|
92
92
|
|
|
93
93
|
// 识别到内容是 function_call 的情况下
|
|
94
94
|
// 将 function_call 转换为 plugin request payload
|
|
95
95
|
if (message.content) {
|
|
96
|
-
const {
|
|
97
|
-
|
|
96
|
+
const { tool_calls } = JSON.parse(message.content) as {
|
|
97
|
+
tool_calls: OpenAIToolCall[];
|
|
98
98
|
};
|
|
99
99
|
|
|
100
|
+
const function_call = tool_calls[0].function;
|
|
101
|
+
|
|
100
102
|
const [identifier, apiName, type] = function_call.name.split(PLUGIN_SCHEMA_SEPARATOR);
|
|
101
103
|
|
|
102
104
|
payload = {
|
|
@@ -142,6 +144,7 @@ export const chatPlugin: StateCreator<
|
|
|
142
144
|
}
|
|
143
145
|
}
|
|
144
146
|
},
|
|
147
|
+
|
|
145
148
|
updatePluginState: async (id, key, value) => {
|
|
146
149
|
const { refreshMessages } = get();
|
|
147
150
|
|
|
@@ -61,7 +61,20 @@ describe('toolSelectors', () => {
|
|
|
61
61
|
describe('enabledSchema', () => {
|
|
62
62
|
it('enabledSchema should return correct ChatCompletionFunctions array', () => {
|
|
63
63
|
const result = toolSelectors.enabledSchema(['plugin-1', 'plugin-2'])(mockState);
|
|
64
|
-
expect(result).toEqual([
|
|
64
|
+
expect(result).toEqual([
|
|
65
|
+
{
|
|
66
|
+
type: 'function',
|
|
67
|
+
function: {
|
|
68
|
+
name: 'plugin-1____api-1',
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
{
|
|
72
|
+
type: 'function',
|
|
73
|
+
function: {
|
|
74
|
+
name: 'plugin-2____api-2',
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
]);
|
|
65
78
|
});
|
|
66
79
|
|
|
67
80
|
it('enabledSchema should return with standalone plugin', () => {
|
|
@@ -80,7 +93,14 @@ describe('toolSelectors', () => {
|
|
|
80
93
|
},
|
|
81
94
|
],
|
|
82
95
|
} as ToolStoreState);
|
|
83
|
-
expect(result).toEqual([
|
|
96
|
+
expect(result).toEqual([
|
|
97
|
+
{
|
|
98
|
+
type: 'function',
|
|
99
|
+
function: {
|
|
100
|
+
name: 'plugin-4____api-4____standalone',
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
]);
|
|
84
104
|
});
|
|
85
105
|
|
|
86
106
|
it('enabledSchema should return md5 hash apiName', () => {
|
|
@@ -99,7 +119,12 @@ describe('toolSelectors', () => {
|
|
|
99
119
|
],
|
|
100
120
|
} as ToolStoreState);
|
|
101
121
|
expect(result).toEqual([
|
|
102
|
-
{
|
|
122
|
+
{
|
|
123
|
+
type: 'function',
|
|
124
|
+
function: {
|
|
125
|
+
name: 'long-long-plugin-with-id____MD5HASH_396eae4c671da3fb642c49ad2b9e8790',
|
|
126
|
+
},
|
|
127
|
+
},
|
|
103
128
|
]);
|
|
104
129
|
});
|
|
105
130
|
|
|
@@ -4,7 +4,7 @@ import { Md5 } from 'ts-md5';
|
|
|
4
4
|
|
|
5
5
|
import { PLUGIN_SCHEMA_API_MD5_PREFIX, PLUGIN_SCHEMA_SEPARATOR } from '@/const/plugin';
|
|
6
6
|
import { MetaData } from '@/types/meta';
|
|
7
|
-
import {
|
|
7
|
+
import { ChatCompletionTool } from '@/types/openai/chat';
|
|
8
8
|
import { LobeToolMeta } from '@/types/tool/tool';
|
|
9
9
|
|
|
10
10
|
import { pluginHelpers } from '../helpers';
|
|
@@ -32,7 +32,7 @@ const getAPIName = (identifier: string, name: string, type?: string) => {
|
|
|
32
32
|
|
|
33
33
|
const enabledSchema =
|
|
34
34
|
(tools: string[] = []) =>
|
|
35
|
-
(s: ToolStoreState):
|
|
35
|
+
(s: ToolStoreState): ChatCompletionTool[] => {
|
|
36
36
|
const list = pluginSelectors
|
|
37
37
|
.installedPluginManifestList(s)
|
|
38
38
|
.concat(s.builtinTools.map((b) => b.manifest as LobeChatPluginManifest))
|
|
@@ -45,7 +45,7 @@ const enabledSchema =
|
|
|
45
45
|
})),
|
|
46
46
|
);
|
|
47
47
|
|
|
48
|
-
return uniqBy(list, 'name');
|
|
48
|
+
return uniqBy(list, 'name').map((i) => ({ function: i, type: 'function' }));
|
|
49
49
|
};
|
|
50
50
|
|
|
51
51
|
const enabledSystemRoles =
|
|
@@ -3,6 +3,7 @@ import { Translate } from '@/types/translate';
|
|
|
3
3
|
|
|
4
4
|
import { LLMRoleType } from '../llm';
|
|
5
5
|
import { BaseDataModel } from '../meta';
|
|
6
|
+
import { ChatPluginPayload } from './tools';
|
|
6
7
|
|
|
7
8
|
/**
|
|
8
9
|
* 聊天消息错误对象
|
|
@@ -23,12 +24,7 @@ export interface ChatTTS {
|
|
|
23
24
|
voice?: string;
|
|
24
25
|
}
|
|
25
26
|
|
|
26
|
-
export
|
|
27
|
-
apiName: string;
|
|
28
|
-
arguments: string;
|
|
29
|
-
identifier: string;
|
|
30
|
-
type: 'standalone' | 'default' | 'builtin';
|
|
31
|
-
}
|
|
27
|
+
export * from './tools';
|
|
32
28
|
|
|
33
29
|
export interface ChatMessage extends BaseDataModel {
|
|
34
30
|
content: string;
|
|
@@ -45,8 +41,8 @@ export interface ChatMessage extends BaseDataModel {
|
|
|
45
41
|
files?: string[];
|
|
46
42
|
parentId?: string;
|
|
47
43
|
plugin?: ChatPluginPayload;
|
|
48
|
-
|
|
49
44
|
pluginState?: any;
|
|
45
|
+
|
|
50
46
|
// 引用
|
|
51
47
|
quotaId?: string;
|
|
52
48
|
/**
|
package/src/types/openai/chat.ts
CHANGED
|
@@ -46,6 +46,9 @@ export interface OpenAIChatStreamPayload {
|
|
|
46
46
|
* @default 0
|
|
47
47
|
*/
|
|
48
48
|
frequency_penalty?: number;
|
|
49
|
+
/**
|
|
50
|
+
* @deprecated
|
|
51
|
+
*/
|
|
49
52
|
functions?: ChatCompletionFunctions[];
|
|
50
53
|
/**
|
|
51
54
|
* @title 生成文本的最大长度
|
|
@@ -82,7 +85,8 @@ export interface OpenAIChatStreamPayload {
|
|
|
82
85
|
* @default 0.5
|
|
83
86
|
*/
|
|
84
87
|
temperature: number;
|
|
85
|
-
|
|
88
|
+
tool_choice?: string;
|
|
89
|
+
tools?: ChatCompletionTool[];
|
|
86
90
|
/**
|
|
87
91
|
* @title 控制生成文本中最高概率的单个令牌
|
|
88
92
|
* @default 1
|
|
@@ -112,3 +116,12 @@ export interface ChatCompletionFunctions {
|
|
|
112
116
|
[key: string]: any;
|
|
113
117
|
};
|
|
114
118
|
}
|
|
119
|
+
|
|
120
|
+
export interface ChatCompletionTool {
|
|
121
|
+
function: ChatCompletionFunctions;
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* The type of the tool. Currently, only `function` is supported.
|
|
125
|
+
*/
|
|
126
|
+
type: 'function';
|
|
127
|
+
}
|