@lobehub/chat 0.115.13 → 0.116.0

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,31 @@
2
2
 
3
3
  # Changelog
4
4
 
5
+ ## [Version 0.116.0](https://github.com/lobehub/lobe-chat/compare/v0.115.13...v0.116.0)
6
+
7
+ <sup>Released on **2023-12-26**</sup>
8
+
9
+ #### ✨ Features
10
+
11
+ - **misc**: Support OpenAI tool calls.
12
+
13
+ <br/>
14
+
15
+ <details>
16
+ <summary><kbd>Improvements and Fixes</kbd></summary>
17
+
18
+ #### What's improved
19
+
20
+ - **misc**: Support OpenAI tool calls ([9681fdc](https://github.com/lobehub/lobe-chat/commit/9681fdc))
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
+
5
30
  ### [Version 0.115.13](https://github.com/lobehub/lobe-chat/compare/v0.115.12...v0.115.13)
6
31
 
7
32
  <sup>Released on **2023-12-26**</sup>
package/README.md CHANGED
@@ -207,14 +207,14 @@ Our marketplace is not just a showcase platform but also a collaborative space.
207
207
 
208
208
  <!-- AGENT LIST -->
209
209
 
210
- | Recent Submits | Description |
211
- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
212
- | [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` |
213
- | [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` |
214
- | [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` |
215
- | [News Hub](https://chat-preview.lobehub.com/market?agent=news-hub)<br/><sup>By **[ccdanpian](https://github.com/ccdanpian)** on **2023-12-19**</sup> | News Search Assistant, proficient in locating and presenting relevant news based on user requests. Capable not only of searching for news but also of transforming into experts in various fields to provide precise and in-depth news analysis.<br/>`news` `search` `helper` |
216
-
217
- > 📊 Total agents: [<kbd>**78**</kbd> ](https://github.com/lobehub/lobe-chat-agents)
210
+ | Recent Submits | Description |
211
+ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
212
+ | [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` |
213
+ | [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` |
214
+ | [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` |
215
+ | [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
+ > 📊 Total agents: [<kbd>**79**</kbd> ](https://github.com/lobehub/lobe-chat-agents)
218
218
 
219
219
  <!-- AGENT LIST -->
220
220
 
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
  ![](https://gw.alipayobjects.com/zos/kitchen/RKnWrrfuMl/welcome.webp)
40
41
 
@@ -183,14 +184,14 @@ LobeChat 的插件生态系统是其核心功能的重要扩展,它极大地
183
184
 
184
185
  <!-- AGENT LIST -->
185
186
 
186
- | 最近新增 | 助手说明 |
187
- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------- |
188
- | [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` |
189
- | [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广告` `潜在客户生成` |
190
- | [梦境画家](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` |
191
- | [新闻搜索助手](https://chat-preview.lobehub.com/market?agent=news-hub)<br/><sup>By **[ccdanpian](https://github.com/ccdanpian)** on **2023-12-19**</sup> | 新闻搜索助手,精通根据用户需求查找和呈现相关新闻。不仅能够搜索新闻,还可以根据用户的要求转变为不同领域的专家,提供精确深入的新闻解读<br/>`新闻` `搜索` `助手` |
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>**78**</kbd> ](https://github.com/lobehub/lobe-chat-agents)
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.115.13",
3
+ "version": "0.116.0",
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",
@@ -1,6 +1,6 @@
1
1
  export const LOADING_FLAT = '...';
2
2
 
3
- // 只要 start with 这个,就可以判断为 function message
4
- export const FUNCTION_MESSAGE_FLAG = '{"function';
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';
@@ -9,6 +9,7 @@ import { nanoid } from '@/utils/uuid';
9
9
  export interface CreateMessageParams
10
10
  extends Partial<Omit<ChatMessage, 'content' | 'role'>>,
11
11
  Pick<ChatMessage, 'content' | 'role'> {
12
+ fromModel?: string;
12
13
  sessionId: string;
13
14
  }
14
15
 
@@ -57,7 +57,14 @@ describe('ChatService', () => {
57
57
 
58
58
  expect(getChatCompletionSpy).toHaveBeenCalledWith(
59
59
  expect.objectContaining({
60
- functions: expect.arrayContaining([{ name: 'plugin1____api1' }]),
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
- functions: undefined,
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
- functions: [
317
+ tools: [
311
318
  {
312
- description: 'Get data from users',
313
- name: 'seo____getData',
314
- parameters: {
315
- properties: { keyword: { type: 'string' }, url: { type: 'string' } },
316
- required: ['keyword', 'url'],
317
- type: 'object',
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
- functions: [
424
+ tools: [
415
425
  {
416
- description: 'Get data from users',
417
- name: 'seo____getData',
418
- parameters: {
419
- properties: { keyword: { type: 'string' }, url: { type: 'string' } },
420
- required: ['keyword', 'url'],
421
- type: 'object',
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
- functions: [
525
+ tools: [
513
526
  {
514
- description: 'Create images from a text-only prompt.',
515
- name: 'dalle3____text2image____builtin',
516
- parameters: {
517
- properties: {
518
- prompts: {
519
- description:
520
- "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.",
521
- items: { type: 'string' },
522
- maxItems: 4,
523
- minItems: 1,
524
- type: 'array',
525
- },
526
- quality: {
527
- default: 'standard',
528
- description:
529
- 'The quality of the image that will be generated. hd creates images with finer details and greater consistency across the image.',
530
- enum: ['standard', 'hd'],
531
- type: 'string',
532
- },
533
- seeds: {
534
- description:
535
- '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.',
536
- items: { type: 'integer' },
537
- type: 'array',
538
- },
539
- size: {
540
- default: '1024x1024',
541
- description:
542
- '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.',
543
- enum: ['1792x1024', '1024x1024', '1024x1792'],
544
- type: 'string',
545
- },
546
- style: {
547
- default: 'vivid',
548
- description:
549
- '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.',
550
- enum: ['vivid', 'natural'],
551
- type: 'string',
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
  ],
@@ -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
- const functions = shouldUseTools ? filterTools : undefined;
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 = `{"function_call": {"name": "pluginName${PLUGIN_SCHEMA_SEPARATOR}apiName", "arguments": {"key": "value"}}}`;
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
- function_call: { name: id + PLUGIN_SCHEMA_SEPARATOR + md5ApiName, arguments: {} },
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
- function_call: {
226
- name: `pluginName${PLUGIN_SCHEMA_SEPARATOR}apiName${PLUGIN_SCHEMA_SEPARATOR}standalone`,
227
- arguments: {},
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 { OpenAIFunctionCall } from '@/types/openai/functionCall';
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 { function_call } = JSON.parse(message.content) as {
97
- function_call: OpenAIFunctionCall;
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([{ name: 'plugin-1____api-1' }, { name: 'plugin-2____api-2' }]);
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([{ name: 'plugin-4____api-4____standalone' }]);
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
- { name: 'long-long-plugin-with-id____MD5HASH_396eae4c671da3fb642c49ad2b9e8790' },
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 { ChatCompletionFunctions } from '@/types/openai/chat';
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): ChatCompletionFunctions[] => {
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 interface ChatPluginPayload {
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
  /**
@@ -0,0 +1,6 @@
1
+ export interface ChatPluginPayload {
2
+ apiName: string;
3
+ arguments: string;
4
+ identifier: string;
5
+ type: 'standalone' | 'default' | 'builtin';
6
+ }
@@ -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
+ }
@@ -2,3 +2,9 @@ export interface OpenAIFunctionCall {
2
2
  arguments: string;
3
3
  name: string;
4
4
  }
5
+
6
+ export interface OpenAIToolCall {
7
+ function: OpenAIFunctionCall;
8
+ id: string;
9
+ type: 'function';
10
+ }