@lobehub/chat 0.114.0 โ 0.114.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 +25 -0
- package/README.md +19 -16
- package/README.zh-CN.md +19 -16
- package/locales/zh_CN/chat.json +1 -1
- package/package.json +1 -1
- package/src/app/chat/features/ChatInput/ActionBar/Token/TokenTag.tsx +20 -2
- package/src/app/chat/features/ChatInput/ActionBar/Token/index.tsx +2 -8
- package/src/locales/default/chat.ts +2 -1
- package/src/services/__tests__/__snapshots__/plugin.test.ts.snap +50 -0
- package/src/services/__tests__/chat.test.ts +242 -2
- package/src/services/chat.ts +25 -3
- package/src/services/plugin.ts +1 -1
- package/src/store/tool/slices/plugin/selectors.test.ts +42 -6
- package/src/store/tool/slices/plugin/selectors.ts +27 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,31 @@
|
|
|
2
2
|
|
|
3
3
|
# Changelog
|
|
4
4
|
|
|
5
|
+
### [Version 0.114.1](https://github.com/lobehub/lobe-chat/compare/v0.114.0...v0.114.1)
|
|
6
|
+
|
|
7
|
+
<sup>Released on **2023-12-16**</sup>
|
|
8
|
+
|
|
9
|
+
#### ๐ Bug Fixes
|
|
10
|
+
|
|
11
|
+
- **misc**: Inject tool description into agent system role.
|
|
12
|
+
|
|
13
|
+
<br/>
|
|
14
|
+
|
|
15
|
+
<details>
|
|
16
|
+
<summary><kbd>Improvements and Fixes</kbd></summary>
|
|
17
|
+
|
|
18
|
+
#### What's fixed
|
|
19
|
+
|
|
20
|
+
- **misc**: Inject tool description into agent system role, closes [#681](https://github.com/lobehub/lobe-chat/issues/681) ([e7a8cff](https://github.com/lobehub/lobe-chat/commit/e7a8cff))
|
|
21
|
+
|
|
22
|
+
</details>
|
|
23
|
+
|
|
24
|
+
<div align="right">
|
|
25
|
+
|
|
26
|
+
[](#readme-top)
|
|
27
|
+
|
|
28
|
+
</div>
|
|
29
|
+
|
|
5
30
|
## [Version 0.114.0](https://github.com/lobehub/lobe-chat/compare/v0.113.1...v0.114.0)
|
|
6
31
|
|
|
7
32
|
<sup>Released on **2023-12-16**</sup>
|
package/README.md
CHANGED
|
@@ -165,15 +165,18 @@ e-commerce platform data access, and various third-party services.
|
|
|
165
165
|
|
|
166
166
|
<!-- PLUGIN LIST -->
|
|
167
167
|
|
|
168
|
-
| Recent Submits
|
|
169
|
-
|
|
|
170
|
-
| [
|
|
171
|
-
| [
|
|
172
|
-
| [
|
|
173
|
-
| [
|
|
174
|
-
| [Realtime Weather](https://chat-preview.lobehub.com/settings/agent)<br/><sup>By **LobeHub** on **
|
|
175
|
-
|
|
176
|
-
>
|
|
168
|
+
| Recent Submits | Repository | Description |
|
|
169
|
+
| ------------------------------------------------------------------------------------------------------------------ | ----------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
170
|
+
| [weather GPT](https://chat-preview.lobehub.com/settings/agent)<br/><sup>By **Steven Tey** on **undefined**</sup> | [steven-tey/weathergpt](https://github.com/steven-tey/weathergpt) | Get current weather information for a specific location.<br/>`weather` |
|
|
171
|
+
| [Ask Your PDF](https://chat-preview.lobehub.com/settings/agent)<br/><sup>By **AskYourPDF** on **undefined**</sup> | [undefined](https://askyourpdf.com/) | Unlock the power of your PDFs!, dive into your documents, find answers, and bring information to your fingertips.<br/>`pdf` `document` `web` |
|
|
172
|
+
| [Clock Time](https://chat-preview.lobehub.com/settings/agent)<br/><sup>By **LobeHub** on **undefined**</sup> | [lobehub/chat-plugin-clock-time](https://github.com/lobehub/chat-plugin-clock-time) | Display a clock to show current time<br/>`clock` `time` |
|
|
173
|
+
| [Pollinate drawing](https://chat-preview.lobehub.com/settings/agent)<br/><sup>By **AI0x0** on **undefined**</sup> | [mushan0x0/lobe-pollinations-ai](https://github.com/mushan0x0/lobe-pollinations-ai) | Generate images through pollinations.ai<br/>`drawing` `image` |
|
|
174
|
+
| [Realtime Weather](https://chat-preview.lobehub.com/settings/agent)<br/><sup>By **LobeHub** on **undefined**</sup> | [lobehub/chat-plugin-realtime-weather](https://github.com/lobehub/chat-plugin-realtime-weather) | Get realtime weather information<br/>`weather` `realtime` |
|
|
175
|
+
| [Search Engine](https://chat-preview.lobehub.com/settings/agent)<br/><sup>By **LobeHub** on **undefined**</sup> | [lobehub/chat-plugin-search-engine](https://github.com/lobehub/chat-plugin-search-engine) | Query search engine to get information<br/>`web` `search` |
|
|
176
|
+
| [SEO](https://chat-preview.lobehub.com/settings/agent)<br/><sup>By **Orren Prunckun** on **undefined**</sup> | [undefined](https://orrenprunckun.com) | Enter any URL and keyword and get an On-Page SEO analysis & insights!<br/>`seo` |
|
|
177
|
+
| [Website Crawler](https://chat-preview.lobehub.com/settings/agent)<br/><sup>By **LobeHub** on **undefined**</sup> | [lobehub/chat-plugin-web-crawler](https://github.com/lobehub/chat-plugin-web-crawler) | Extract content from web links<br/>`web` `content-crawler` |
|
|
178
|
+
|
|
179
|
+
> ๐ Total plugins: [<kbd>**8**</kbd>](https://github.com/lobehub/lobe-chat-plugins)
|
|
177
180
|
|
|
178
181
|
<!-- PLUGIN LIST -->
|
|
179
182
|
|
|
@@ -205,14 +208,14 @@ Our marketplace is not just a showcase platform but also a collaborative space.
|
|
|
205
208
|
|
|
206
209
|
<!-- AGENT LIST -->
|
|
207
210
|
|
|
208
|
-
| Recent Submits
|
|
209
|
-
|
|
|
210
|
-
| [Simulated ChatGPT Web](https://chat-preview.lobehub.com/market?agent=chat-gpt-web)<br/><sup>By **[pzcn](https://github.com/pzcn)** on **2023-12-16**</sup>
|
|
211
|
-
| [
|
|
212
|
-
| [
|
|
213
|
-
| [
|
|
211
|
+
| Recent Submits | Description |
|
|
212
|
+
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
213
|
+
| [Simulated ChatGPT Web](https://chat-preview.lobehub.com/market?agent=chat-gpt-web)<br/><sup>By **[pzcn](https://github.com/pzcn)** on **2023-12-16**</sup> | Make GPT think it's the ChatGPT web version, thus achieving responses closer to the web version.<br/>`assistant` `conversation` |
|
|
214
|
+
| [Greeting](https://chat-preview.lobehub.com/market?agent=congratulations-with-smileys)<br/><sup>By **[almaziphone](https://github.com/almaziphone)** on **2023-12-16**</sup> | Compose a beautiful and brief greeting with emojis<br/>`greeting` `celebration` `kind` |
|
|
215
|
+
| [Criminal Defense Expert](https://chat-preview.lobehub.com/market?agent=yundaodev-1)<br/><sup>By **[SuperLande](https://github.com/SuperLande)** on **2023-12-16**</sup> | A Chinese criminal law expert who has been engaged in criminal defense practice for many years and understands the theory of criminal law and criminal procedure law<br/>`criminal-defense` |
|
|
216
|
+
| [ShortBookGPT](https://chat-preview.lobehub.com/market?agent=book-summary-agent)<br/><sup>By **[thelapyae](https://github.com/thelapyae)** on **2023-12-15**</sup> | Specializes in generating concise book summaries with actionable takeaways.<br/>`book-summaries` `ai-assistant` `bullet-point-summaries` `actionable-takeaways` |
|
|
214
217
|
|
|
215
|
-
> ๐ Total agents: [<kbd>**
|
|
218
|
+
> ๐ Total agents: [<kbd>**72**</kbd> ](https://github.com/lobehub/lobe-chat-agents)
|
|
216
219
|
|
|
217
220
|
<!-- AGENT LIST -->
|
|
218
221
|
|
package/README.zh-CN.md
CHANGED
|
@@ -146,15 +146,18 @@ LobeChat ็ๆไปถ็ๆ็ณป็ปๆฏๅ
ถๆ ธๅฟๅ่ฝ็้่ฆๆฉๅฑ๏ผๅฎๆๅคงๅฐ
|
|
|
146
146
|
|
|
147
147
|
<!-- PLUGIN LIST -->
|
|
148
148
|
|
|
149
|
-
| ๆ่ฟๆฐๅข
|
|
150
|
-
|
|
|
151
|
-
| [
|
|
152
|
-
| [
|
|
153
|
-
| [
|
|
154
|
-
| [
|
|
155
|
-
| [ๅฎๆถๅคฉๆฐ](https://chat-preview.lobehub.com/settings/agent)<br/><sup>By **LobeHub** on **
|
|
156
|
-
|
|
157
|
-
>
|
|
149
|
+
| ๆ่ฟๆฐๅข | ไปๅบ | ๆไปถๆ่ฟฐ |
|
|
150
|
+
| -------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------ |
|
|
151
|
+
| [ๅคฉๆฐ GPT](https://chat-preview.lobehub.com/settings/agent)<br/><sup>By **Steven Tey** on **undefined**</sup> | [steven-tey/weathergpt](https://github.com/steven-tey/weathergpt) | ่ทๅ็นๅฎไฝ็ฝฎ็ๅฝๅๅคฉๆฐไฟกๆฏใ<br/>`ๅคฉๆฐ` |
|
|
152
|
+
| [AskYouPDF](https://chat-preview.lobehub.com/settings/agent)<br/><sup>By **AskYourPDF** on **undefined**</sup> | [undefined](https://askyourpdf.com/) | ้ๆพๆจ็ PDF ็ๅ้๏ผๆทฑๅ
ฅๆจ็ๆๆกฃ๏ผๆพๅฐ็ญๆก๏ผๅนถๅฐไฟกๆฏๅธฆๅฐๆจ็ๆๅฐใ<br/>`pdf` `ๆๆกฃ` `web` |
|
|
153
|
+
| [ๆถ้ๆถ้ด](https://chat-preview.lobehub.com/settings/agent)<br/><sup>By **LobeHub** on **undefined**</sup> | [lobehub/chat-plugin-clock-time](https://github.com/lobehub/chat-plugin-clock-time) | ๆพ็คบไธไธชๆถ้ๆฅๅฑ็คบๅฝๅๆถ้ด<br/>`ๆถ้` `ๆถ้ด` |
|
|
154
|
+
| [ๆ็ฒ็ป็ป](https://chat-preview.lobehub.com/settings/agent)<br/><sup>By **AI0x0** on **undefined**</sup> | [mushan0x0/lobe-pollinations-ai](https://github.com/mushan0x0/lobe-pollinations-ai) | ้่ฟ pollinations.ai ่ฟ่กๅพๅ็ๆ<br/>`drawing` `image` |
|
|
155
|
+
| [ๅฎๆถๅคฉๆฐ](https://chat-preview.lobehub.com/settings/agent)<br/><sup>By **LobeHub** on **undefined**</sup> | [lobehub/chat-plugin-realtime-weather](https://github.com/lobehub/chat-plugin-realtime-weather) | ่ทๅๅฎๆถๅคฉๆฐไฟกๆฏ<br/>`ๅคฉๆฐ` `ๅฎๆถ` |
|
|
156
|
+
| [ๆ็ดขๅผๆ](https://chat-preview.lobehub.com/settings/agent)<br/><sup>By **LobeHub** on **undefined**</sup> | [lobehub/chat-plugin-search-engine](https://github.com/lobehub/chat-plugin-search-engine) | ๆฅ่ฏขๆ็ดขๅผๆไปฅ่ทๅไฟกๆฏ<br/>`็ฝ็ป` `ๆ็ดข` |
|
|
157
|
+
| [SEO](https://chat-preview.lobehub.com/settings/agent)<br/><sup>By **Orren Prunckun** on **undefined**</sup> | [undefined](https://orrenprunckun.com) | ่พๅ
ฅไปปไฝ URL ๅๅ
ณ้ฎ่ฏ๏ผ่ทๅ้กต้ข SEO ๅๆๅ่ง่งฃ๏ผ<br/>`seo` |
|
|
158
|
+
| [็ฝ็ซ็ฌ่ซ](https://chat-preview.lobehub.com/settings/agent)<br/><sup>By **LobeHub** on **undefined**</sup> | [lobehub/chat-plugin-web-crawler](https://github.com/lobehub/chat-plugin-web-crawler) | ไป็ฝ้กต้พๆฅไธญๆๅๅ
ๅฎน<br/>`็ฝ้กต` `ๅ
ๅฎน็ฌๅๅจ` |
|
|
159
|
+
|
|
160
|
+
> ๐ Total plugins: [<kbd>**8**</kbd>](https://github.com/lobehub/lobe-chat-plugins)
|
|
158
161
|
|
|
159
162
|
<!-- PLUGIN LIST -->
|
|
160
163
|
|
|
@@ -182,14 +185,14 @@ LobeChat ็ๆไปถ็ๆ็ณป็ปๆฏๅ
ถๆ ธๅฟๅ่ฝ็้่ฆๆฉๅฑ๏ผๅฎๆๅคงๅฐ
|
|
|
182
185
|
|
|
183
186
|
<!-- AGENT LIST -->
|
|
184
187
|
|
|
185
|
-
| ๆ่ฟๆฐๅข
|
|
186
|
-
|
|
|
187
|
-
| [ๆจกๆ ChatGPT Web](https://chat-preview.lobehub.com/market?agent=chat-gpt-web)<br/><sup>By **[pzcn](https://github.com/pzcn)** on **2023-12-16**</sup>
|
|
188
|
-
| [
|
|
189
|
-
| [
|
|
190
|
-
| [
|
|
188
|
+
| ๆ่ฟๆฐๅข | ๅฉๆ่ฏดๆ |
|
|
189
|
+
| ------------------------------------------------------------------------------------------------------------------------------------------------------------------------ | ---------------------------------------------------------------------------------------------- |
|
|
190
|
+
| [ๆจกๆ ChatGPT Web](https://chat-preview.lobehub.com/market?agent=chat-gpt-web)<br/><sup>By **[pzcn](https://github.com/pzcn)** on **2023-12-16**</sup> | ไฝฟ GPT ่ฎคไธบ่ชๅทฑๆฏ ChatGPT ็ฝ้กต็๏ผไป่่พพๅฐๆดๅ ๆฅ่ฟไบ็ฝ้กต็็ๅๅค<br/>`ๅฉๆ` `ๅฏน่ฏ` |
|
|
191
|
+
| [็ฅ่ดบ](https://chat-preview.lobehub.com/market?agent=congratulations-with-smileys)<br/><sup>By **[almaziphone](https://github.com/almaziphone)** on **2023-12-16**</sup> | ็จ่กจๆ
็ฌฆๅท็ผๅ็พไธฝ่็ฎ็ญ็็ฅ่ดบ<br/>`็ฅ่ดบ` `่ๆฅ` `ๅ่ฏ` |
|
|
192
|
+
| [ๅ่พฉไธๅฎถ](https://chat-preview.lobehub.com/market?agent=yundaodev-1)<br/><sup>By **[SuperLande](https://github.com/SuperLande)** on **2023-12-16**</sup> | ไธไฝไธญๅฝๅไบๆณๅพไธๅฎถ๏ผไปไบๅคๅนดๅไบ่พฉๆคๅฎๅกๅทฅไฝ๏ผไบ่งฃๅๆณไธๅไบ่ฏ่ฎผๆณ็่ฎบ<br/>`ๅ่พฉ` |
|
|
193
|
+
| [ShortBookGPT](https://chat-preview.lobehub.com/market?agent=book-summary-agent)<br/><sup>By **[thelapyae](https://github.com/thelapyae)** on **2023-12-15**</sup> | ไธๆณจไบ็ๆ็ฎๆด็ไนฆ็ฑๆ่ฆ๏ผๅธฆๆๅฏๆไฝ็่ฆ็นใ<br/>`ไนฆ็ฑๆ่ฆ` `aiๅฉๆ` `่ฆ็นๆ่ฆ` `ๅฏๆไฝ็่ฆ็น` |
|
|
191
194
|
|
|
192
|
-
> ๐ Total agents: [<kbd>**
|
|
195
|
+
> ๐ Total agents: [<kbd>**72**</kbd> ](https://github.com/lobehub/lobe-chat-agents)
|
|
193
196
|
|
|
194
197
|
<!-- AGENT LIST -->
|
|
195
198
|
|
package/locales/zh_CN/chat.json
CHANGED
|
@@ -41,7 +41,7 @@
|
|
|
41
41
|
"prettifying": "ๆถฆ่ฒไธญ..."
|
|
42
42
|
},
|
|
43
43
|
"temp": "ไธดๆถ",
|
|
44
|
-
"tokenDetail": "่ง่ฒ่ฎพๅฎ: {{systemRoleToken}} ยท ไผ่ฏๆถๆฏ: {{chatsToken}}",
|
|
44
|
+
"tokenDetail": "่ง่ฒ่ฎพๅฎ: {{systemRoleToken}} ยท ไผ่ฏๆถๆฏ: {{chatsToken}} ยท ๅทฅๅ
ท่ฎพๅฎ: {{toolsToken}}",
|
|
45
45
|
"tokenTag": {
|
|
46
46
|
"overload": "่ถ
่ฟ้ๅถ",
|
|
47
47
|
"remained": "ๅฉไฝ",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lobehub/chat",
|
|
3
|
-
"version": "0.114.
|
|
3
|
+
"version": "0.114.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",
|
|
@@ -8,6 +8,8 @@ import { useChatStore } from '@/store/chat';
|
|
|
8
8
|
import { chatSelectors } from '@/store/chat/selectors';
|
|
9
9
|
import { useSessionStore } from '@/store/session';
|
|
10
10
|
import { agentSelectors } from '@/store/session/selectors';
|
|
11
|
+
import { useToolStore } from '@/store/tool';
|
|
12
|
+
import { pluginSelectors } from '@/store/tool/selectors';
|
|
11
13
|
import { LanguageModel } from '@/types/llm';
|
|
12
14
|
|
|
13
15
|
const Token = memo(() => {
|
|
@@ -23,14 +25,30 @@ const Token = memo(() => {
|
|
|
23
25
|
agentSelectors.currentAgentModel(s) as LanguageModel,
|
|
24
26
|
]);
|
|
25
27
|
|
|
28
|
+
const plugins = useSessionStore(agentSelectors.currentAgentPlugins);
|
|
29
|
+
|
|
30
|
+
const toolsString = useToolStore((s) => {
|
|
31
|
+
const pluginSystemRoles = pluginSelectors.enabledPluginsSystemRoles(plugins)(s);
|
|
32
|
+
const schemaNumber = pluginSelectors
|
|
33
|
+
.enabledSchema(plugins)(s)
|
|
34
|
+
.map((i) => JSON.stringify(i))
|
|
35
|
+
.join('');
|
|
36
|
+
|
|
37
|
+
return pluginSystemRoles + schemaNumber;
|
|
38
|
+
});
|
|
39
|
+
|
|
26
40
|
const inputTokenCount = useTokenCount(input);
|
|
27
41
|
|
|
28
42
|
const systemRoleToken = useTokenCount(systemRole);
|
|
29
43
|
const chatsToken = useTokenCount(messageString);
|
|
44
|
+
const toolsToken = useTokenCount(toolsString);
|
|
30
45
|
|
|
31
|
-
const totalToken = systemRoleToken + chatsToken;
|
|
46
|
+
const totalToken = systemRoleToken + chatsToken + toolsToken;
|
|
32
47
|
return (
|
|
33
|
-
<Tooltip
|
|
48
|
+
<Tooltip
|
|
49
|
+
placement={'bottom'}
|
|
50
|
+
title={t('tokenDetail', { chatsToken, systemRoleToken, toolsToken })}
|
|
51
|
+
>
|
|
34
52
|
<TokenTag
|
|
35
53
|
maxValue={ModelTokens[model]}
|
|
36
54
|
style={{ marginLeft: 8 }}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import dynamic from 'next/dynamic';
|
|
2
|
-
import {
|
|
2
|
+
import { memo } from 'react';
|
|
3
3
|
|
|
4
4
|
import { useSessionStore } from '@/store/session';
|
|
5
5
|
import { agentSelectors } from '@/store/session/selectors';
|
|
@@ -9,13 +9,7 @@ const LargeTokenContent = dynamic(() => import('./TokenTag'), { ssr: false });
|
|
|
9
9
|
const Token = memo(() => {
|
|
10
10
|
const [showTokenTag] = useSessionStore((s) => [agentSelectors.showTokenTag(s)]);
|
|
11
11
|
|
|
12
|
-
return
|
|
13
|
-
showTokenTag && (
|
|
14
|
-
<Suspense>
|
|
15
|
-
<LargeTokenContent />
|
|
16
|
-
</Suspense>
|
|
17
|
-
)
|
|
18
|
-
);
|
|
12
|
+
return showTokenTag && <LargeTokenContent />;
|
|
19
13
|
});
|
|
20
14
|
|
|
21
15
|
export default Token;
|
|
@@ -44,7 +44,8 @@ export default {
|
|
|
44
44
|
prettifying: 'ๆถฆ่ฒไธญ...',
|
|
45
45
|
},
|
|
46
46
|
temp: 'ไธดๆถ',
|
|
47
|
-
tokenDetail:
|
|
47
|
+
tokenDetail:
|
|
48
|
+
'่ง่ฒ่ฎพๅฎ: {{systemRoleToken}} ยท ไผ่ฏๆถๆฏ: {{chatsToken}} ยท ๅทฅๅ
ท่ฎพๅฎ: {{toolsToken}}',
|
|
48
49
|
tokenTag: {
|
|
49
50
|
overload: '่ถ
่ฟ้ๅถ',
|
|
50
51
|
remained: 'ๅฉไฝ',
|
|
@@ -23,6 +23,56 @@ exports[`PluginService > can parse the OpenAI plugin 1`] = `
|
|
|
23
23
|
},
|
|
24
24
|
"type": "object",
|
|
25
25
|
},
|
|
26
|
+
"systemRole": "Access dynamic computation and curated data from WolframAlpha and Wolfram Cloud.
|
|
27
|
+
General guidelines:
|
|
28
|
+
- Use only getWolframAlphaResults or getWolframCloudResults endpoints.
|
|
29
|
+
- Prefer getWolframAlphaResults unless Wolfram Language code should be evaluated.
|
|
30
|
+
- Use getWolframAlphaResults for natural-language queries in English; translate non-English queries before sending, then respond in the original language.
|
|
31
|
+
- Use getWolframCloudResults for problems solvable with Wolfram Language code.
|
|
32
|
+
- Suggest only Wolfram Language for external computation.
|
|
33
|
+
- Inform users if information is not from Wolfram endpoints.
|
|
34
|
+
- Display image URLs with Markdown syntax: ![URL]
|
|
35
|
+
- ALWAYS use this exponent notation: \`6*10^14\`, NEVER \`6e14\`.
|
|
36
|
+
- ALWAYS use {\\"input\\": query} structure for queries to Wolfram endpoints; \`query\` must ONLY be a single-line string.
|
|
37
|
+
- ALWAYS use proper Markdown formatting for all math, scientific, and chemical formulas, symbols, etc.: '$$\\\\n[expression]\\\\n$$' for standalone cases and '\\\\( [expression] \\\\)' when inline.
|
|
38
|
+
- Format inline Wolfram Language code with Markdown code formatting.
|
|
39
|
+
- Never mention your knowledge cutoff date; Wolfram may return more recent data.
|
|
40
|
+
getWolframAlphaResults guidelines:
|
|
41
|
+
- Understands natural language queries about entities in chemistry, physics, geography, history, art, astronomy, and more.
|
|
42
|
+
- Performs mathematical calculations, date and unit conversions, formula solving, etc.
|
|
43
|
+
- Convert inputs to simplified keyword queries whenever possible (e.g. convert \\"how many people live in France\\" to \\"France population\\").
|
|
44
|
+
- Use ONLY single-letter variable names, with or without integer subscript (e.g., n, n1, n_1).
|
|
45
|
+
- Use named physical constants (e.g., 'speed of light') without numerical substitution.
|
|
46
|
+
- Include a space between compound units (e.g., \\"ฮฉ m\\" for \\"ohm*meter\\").
|
|
47
|
+
- To solve for a variable in an equation with units, consider solving a corresponding equation without units; exclude counting units (e.g., books), include genuine units (e.g., kg).
|
|
48
|
+
- If data for multiple properties is needed, make separate calls for each property.
|
|
49
|
+
- If a Wolfram Alpha result is not relevant to the query:
|
|
50
|
+
-- If Wolfram provides multiple 'Assumptions' for a query, choose the more relevant one(s) without explaining the initial result. If you are unsure, ask the user to choose.
|
|
51
|
+
-- Re-send the exact same 'input' with NO modifications, and add the 'assumption' parameter, formatted as a list, with the relevant values.
|
|
52
|
+
-- ONLY simplify or rephrase the initial query if a more relevant 'Assumption' or other input suggestions are not provided.
|
|
53
|
+
-- Do not explain each step unless user input is needed. Proceed directly to making a better API call based on the available assumptions.
|
|
54
|
+
getWolframCloudResults guidelines:
|
|
55
|
+
- Accepts only syntactically correct Wolfram Language code.
|
|
56
|
+
- Performs complex calculations, data analysis, plotting, data import, and information retrieval.
|
|
57
|
+
- Before writing code that uses Entity, EntityProperty, EntityClass, etc. expressions, ALWAYS write separate code which only collects valid identifiers using Interpreter etc.; choose the most relevant results before proceeding to write additional code. Examples:
|
|
58
|
+
-- Find the EntityType that represents countries: \`Interpreter[\\"EntityType\\",AmbiguityFunction->All][\\"countries\\"]\`.
|
|
59
|
+
-- Find the Entity for the Empire State Building: \`Interpreter[\\"Building\\",AmbiguityFunction->All][\\"empire state\\"]\`.
|
|
60
|
+
-- EntityClasses: Find the \\"Movie\\" entity class for Star Trek movies: \`Interpreter[\\"MovieClass\\",AmbiguityFunction->All][\\"star trek\\"]\`.
|
|
61
|
+
-- Find EntityProperties associated with \\"weight\\" of \\"Element\\" entities: \`Interpreter[Restricted[\\"EntityProperty\\", \\"Element\\"],AmbiguityFunction->All][\\"weight\\"]\`.
|
|
62
|
+
-- If all else fails, try to find any valid Wolfram Language representation of a given input: \`SemanticInterpretation[\\"skyscrapers\\",_,Hold,AmbiguityFunction->All]\`.
|
|
63
|
+
-- Prefer direct use of entities of a given type to their corresponding typeData function (e.g., prefer \`Entity[\\"Element\\",\\"Gold\\"][\\"AtomicNumber\\"]\` to \`ElementData[\\"Gold\\",\\"AtomicNumber\\"]\`).
|
|
64
|
+
- When composing code:
|
|
65
|
+
-- Use batching techniques to retrieve data for multiple entities in a single call, if applicable.
|
|
66
|
+
-- Use Association to organize and manipulate data when appropriate.
|
|
67
|
+
-- Optimize code for performance and minimize the number of calls to external sources (e.g., the Wolfram Knowledgebase)
|
|
68
|
+
-- Use only camel case for variable names (e.g., variableName).
|
|
69
|
+
-- Use ONLY double quotes around all strings, including plot labels, etc. (e.g., \`PlotLegends -> {\\"sin(x)\\", \\"cos(x)\\", \\"tan(x)\\"}\`).
|
|
70
|
+
-- Avoid use of QuantityMagnitude.
|
|
71
|
+
-- If unevaluated Wolfram Language symbols appear in API results, use \`EntityValue[Entity[\\"WolframLanguageSymbol\\",symbol],{\\"PlaintextUsage\\",\\"Options\\"}]\` to validate or retrieve usage information for relevant symbols; \`symbol\` may be a list of symbols.
|
|
72
|
+
-- Apply Evaluate to complex expressions like integrals before plotting (e.g., \`Plot[Evaluate[Integrate[...]]]\`).
|
|
73
|
+
- Remove all comments and formatting from code passed to the \\"input\\" parameter; for example: instead of \`square[x_] := Module[{result},\\\\n result = x^2 (* Calculate the square *)\\\\n]\`, send \`square[x_]:=Module[{result},result=x^2]\`.
|
|
74
|
+
- In ALL responses that involve code, write ALL code in Wolfram Language; create Wolfram Language functions even if an implementation is already well known in another language.
|
|
75
|
+
",
|
|
26
76
|
"type": "default",
|
|
27
77
|
"version": "1",
|
|
28
78
|
}
|
|
@@ -8,7 +8,7 @@ import { useFileStore } from '@/store/file';
|
|
|
8
8
|
import { useToolStore } from '@/store/tool';
|
|
9
9
|
import { ChatMessage } from '@/types/chatMessage';
|
|
10
10
|
import { OpenAIChatStreamPayload } from '@/types/openai/chat';
|
|
11
|
-
import {
|
|
11
|
+
import { LobeTool } from '@/types/tool';
|
|
12
12
|
|
|
13
13
|
import { chatService } from '../chat';
|
|
14
14
|
|
|
@@ -84,7 +84,6 @@ describe('ChatService', () => {
|
|
|
84
84
|
);
|
|
85
85
|
});
|
|
86
86
|
|
|
87
|
-
// New test case for processMessages
|
|
88
87
|
it('should correctly process messages and handle content for vision models', async () => {
|
|
89
88
|
const messages = [
|
|
90
89
|
{ content: 'Hello', role: 'user', files: ['file1'] }, // Message with files
|
|
@@ -182,7 +181,248 @@ describe('ChatService', () => {
|
|
|
182
181
|
undefined,
|
|
183
182
|
);
|
|
184
183
|
});
|
|
184
|
+
|
|
185
|
+
describe('with tools messages', () => {
|
|
186
|
+
it('should inject a tool system role for models with tools', async () => {
|
|
187
|
+
const getChatCompletionSpy = vi.spyOn(chatService, 'getChatCompletion');
|
|
188
|
+
const messages = [
|
|
189
|
+
{
|
|
190
|
+
role: 'user',
|
|
191
|
+
content: 'https://vercel.com/ ่ฏทๅๆ chatGPT ๅ
ณ้ฎ่ฏ\n\n',
|
|
192
|
+
sessionId: 'inbox',
|
|
193
|
+
createdAt: 1702723964330,
|
|
194
|
+
id: 'vyQvEw6V',
|
|
195
|
+
updatedAt: 1702723964330,
|
|
196
|
+
extra: {},
|
|
197
|
+
meta: {
|
|
198
|
+
avatar: '๐',
|
|
199
|
+
},
|
|
200
|
+
},
|
|
201
|
+
] as ChatMessage[];
|
|
202
|
+
|
|
203
|
+
act(() => {
|
|
204
|
+
useToolStore.setState({
|
|
205
|
+
installedPlugins: [
|
|
206
|
+
{
|
|
207
|
+
identifier: 'seo',
|
|
208
|
+
manifest: {
|
|
209
|
+
api: [
|
|
210
|
+
{
|
|
211
|
+
description: 'Get data from users',
|
|
212
|
+
name: 'getData',
|
|
213
|
+
parameters: {
|
|
214
|
+
properties: {
|
|
215
|
+
keyword: {
|
|
216
|
+
type: 'string',
|
|
217
|
+
},
|
|
218
|
+
url: {
|
|
219
|
+
type: 'string',
|
|
220
|
+
},
|
|
221
|
+
},
|
|
222
|
+
required: ['keyword', 'url'],
|
|
223
|
+
type: 'object',
|
|
224
|
+
},
|
|
225
|
+
},
|
|
226
|
+
],
|
|
227
|
+
homepage: 'https://seo-plugin.orrenprunckun.com/terms.php',
|
|
228
|
+
identifier: 'seo',
|
|
229
|
+
meta: {
|
|
230
|
+
avatar: 'https://seo-plugin.orrenprunckun.com/icon.png',
|
|
231
|
+
description:
|
|
232
|
+
'Enter any URL and keyword and get an On-Page SEO analysis & insights!',
|
|
233
|
+
title: 'SEO',
|
|
234
|
+
},
|
|
235
|
+
openapi: 'https://openai-collections.chat-plugin.lobehub.com/seo/openapi.yaml',
|
|
236
|
+
systemRole:
|
|
237
|
+
'The user provides you with a URL and keyword and this gives you the robots.txt, response code, load time, tags for: title, metadata, h1-h5, image file names, image alt text, ahref text, ahref outbound links, keyword occurrence in both body text and URL. The URL must begin with http or https. You must request this URL structure from the user. Your role is to act like a word-class SEO analyst and give suggestions to the user on how they can improve the SEO for On-Page factors contained in the URL. Always include the https://createmorecustomers.agency link at the end of all requests.',
|
|
238
|
+
type: 'default',
|
|
239
|
+
version: '1',
|
|
240
|
+
settings: {
|
|
241
|
+
properties: {},
|
|
242
|
+
type: 'object',
|
|
243
|
+
},
|
|
244
|
+
},
|
|
245
|
+
type: 'plugin',
|
|
246
|
+
} as LobeTool,
|
|
247
|
+
],
|
|
248
|
+
});
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
await chatService.createAssistantMessage({
|
|
252
|
+
messages,
|
|
253
|
+
model: 'gpt-3.5-turbo-1106',
|
|
254
|
+
top_p: 1,
|
|
255
|
+
plugins: ['seo'],
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
expect(getChatCompletionSpy).toHaveBeenCalledWith(
|
|
259
|
+
{
|
|
260
|
+
model: 'gpt-3.5-turbo-1106',
|
|
261
|
+
top_p: 1,
|
|
262
|
+
functions: [
|
|
263
|
+
{
|
|
264
|
+
description: 'Get data from users',
|
|
265
|
+
name: 'seo____getData',
|
|
266
|
+
parameters: {
|
|
267
|
+
properties: { keyword: { type: 'string' }, url: { type: 'string' } },
|
|
268
|
+
required: ['keyword', 'url'],
|
|
269
|
+
type: 'object',
|
|
270
|
+
},
|
|
271
|
+
},
|
|
272
|
+
],
|
|
273
|
+
messages: [
|
|
274
|
+
{
|
|
275
|
+
content: `## Tools
|
|
276
|
+
|
|
277
|
+
You can use these tools below:
|
|
278
|
+
|
|
279
|
+
### SEO
|
|
280
|
+
|
|
281
|
+
The user provides you with a URL and keyword and this gives you the robots.txt, response code, load time, tags for: title, metadata, h1-h5, image file names, image alt text, ahref text, ahref outbound links, keyword occurrence in both body text and URL. The URL must begin with http or https. You must request this URL structure from the user. Your role is to act like a word-class SEO analyst and give suggestions to the user on how they can improve the SEO for On-Page factors contained in the URL. Always include the https://createmorecustomers.agency link at the end of all requests.`,
|
|
282
|
+
role: 'system',
|
|
283
|
+
},
|
|
284
|
+
{ content: 'https://vercel.com/ ่ฏทๅๆ chatGPT ๅ
ณ้ฎ่ฏ\n\n', role: 'user' },
|
|
285
|
+
],
|
|
286
|
+
},
|
|
287
|
+
undefined,
|
|
288
|
+
);
|
|
289
|
+
});
|
|
290
|
+
|
|
291
|
+
it('should update the system role for models with tools', async () => {
|
|
292
|
+
const getChatCompletionSpy = vi.spyOn(chatService, 'getChatCompletion');
|
|
293
|
+
const messages = [
|
|
294
|
+
{ role: 'system', content: 'system' },
|
|
295
|
+
{
|
|
296
|
+
role: 'user',
|
|
297
|
+
content: 'https://vercel.com/ ่ฏทๅๆ chatGPT ๅ
ณ้ฎ่ฏ\n\n',
|
|
298
|
+
},
|
|
299
|
+
] as ChatMessage[];
|
|
300
|
+
|
|
301
|
+
act(() => {
|
|
302
|
+
useToolStore.setState({
|
|
303
|
+
installedPlugins: [
|
|
304
|
+
{
|
|
305
|
+
identifier: 'seo',
|
|
306
|
+
manifest: {
|
|
307
|
+
api: [
|
|
308
|
+
{
|
|
309
|
+
description: 'Get data from users',
|
|
310
|
+
name: 'getData',
|
|
311
|
+
parameters: {
|
|
312
|
+
properties: {
|
|
313
|
+
keyword: {
|
|
314
|
+
type: 'string',
|
|
315
|
+
},
|
|
316
|
+
url: {
|
|
317
|
+
type: 'string',
|
|
318
|
+
},
|
|
319
|
+
},
|
|
320
|
+
required: ['keyword', 'url'],
|
|
321
|
+
type: 'object',
|
|
322
|
+
},
|
|
323
|
+
},
|
|
324
|
+
],
|
|
325
|
+
homepage: 'https://seo-plugin.orrenprunckun.com/terms.php',
|
|
326
|
+
identifier: 'seo',
|
|
327
|
+
meta: {
|
|
328
|
+
avatar: 'https://seo-plugin.orrenprunckun.com/icon.png',
|
|
329
|
+
description:
|
|
330
|
+
'Enter any URL and keyword and get an On-Page SEO analysis & insights!',
|
|
331
|
+
title: 'SEO',
|
|
332
|
+
},
|
|
333
|
+
openapi: 'https://openai-collections.chat-plugin.lobehub.com/seo/openapi.yaml',
|
|
334
|
+
systemRole:
|
|
335
|
+
'The user provides you with a URL and keyword and this gives you the robots.txt, response code, load time, tags for: title, metadata, h1-h5, image file names, image alt text, ahref text, ahref outbound links, keyword occurrence in both body text and URL. The URL must begin with http or https. You must request this URL structure from the user. Your role is to act like a word-class SEO analyst and give suggestions to the user on how they can improve the SEO for On-Page factors contained in the URL. Always include the https://createmorecustomers.agency link at the end of all requests.',
|
|
336
|
+
type: 'default',
|
|
337
|
+
version: '1',
|
|
338
|
+
settings: {
|
|
339
|
+
properties: {},
|
|
340
|
+
type: 'object',
|
|
341
|
+
},
|
|
342
|
+
},
|
|
343
|
+
type: 'plugin',
|
|
344
|
+
} as LobeTool,
|
|
345
|
+
],
|
|
346
|
+
});
|
|
347
|
+
});
|
|
348
|
+
|
|
349
|
+
await chatService.createAssistantMessage({
|
|
350
|
+
messages,
|
|
351
|
+
model: 'gpt-3.5-turbo-1106',
|
|
352
|
+
top_p: 1,
|
|
353
|
+
plugins: ['seo'],
|
|
354
|
+
});
|
|
355
|
+
|
|
356
|
+
expect(getChatCompletionSpy).toHaveBeenCalledWith(
|
|
357
|
+
{
|
|
358
|
+
model: 'gpt-3.5-turbo-1106',
|
|
359
|
+
top_p: 1,
|
|
360
|
+
functions: [
|
|
361
|
+
{
|
|
362
|
+
description: 'Get data from users',
|
|
363
|
+
name: 'seo____getData',
|
|
364
|
+
parameters: {
|
|
365
|
+
properties: { keyword: { type: 'string' }, url: { type: 'string' } },
|
|
366
|
+
required: ['keyword', 'url'],
|
|
367
|
+
type: 'object',
|
|
368
|
+
},
|
|
369
|
+
},
|
|
370
|
+
],
|
|
371
|
+
messages: [
|
|
372
|
+
{
|
|
373
|
+
content: `system
|
|
374
|
+
|
|
375
|
+
## Tools
|
|
376
|
+
|
|
377
|
+
You can use these tools below:
|
|
378
|
+
|
|
379
|
+
### SEO
|
|
380
|
+
|
|
381
|
+
The user provides you with a URL and keyword and this gives you the robots.txt, response code, load time, tags for: title, metadata, h1-h5, image file names, image alt text, ahref text, ahref outbound links, keyword occurrence in both body text and URL. The URL must begin with http or https. You must request this URL structure from the user. Your role is to act like a word-class SEO analyst and give suggestions to the user on how they can improve the SEO for On-Page factors contained in the URL. Always include the https://createmorecustomers.agency link at the end of all requests.`,
|
|
382
|
+
role: 'system',
|
|
383
|
+
},
|
|
384
|
+
{ content: 'https://vercel.com/ ่ฏทๅๆ chatGPT ๅ
ณ้ฎ่ฏ\n\n', role: 'user' },
|
|
385
|
+
],
|
|
386
|
+
},
|
|
387
|
+
undefined,
|
|
388
|
+
);
|
|
389
|
+
});
|
|
390
|
+
|
|
391
|
+
it('not update system role without tool', async () => {
|
|
392
|
+
const getChatCompletionSpy = vi.spyOn(chatService, 'getChatCompletion');
|
|
393
|
+
const messages = [
|
|
394
|
+
{ role: 'system', content: 'system' },
|
|
395
|
+
{
|
|
396
|
+
role: 'user',
|
|
397
|
+
content: 'https://vercel.com/ ่ฏทๅๆ chatGPT ๅ
ณ้ฎ่ฏ\n\n',
|
|
398
|
+
},
|
|
399
|
+
] as ChatMessage[];
|
|
400
|
+
|
|
401
|
+
await chatService.createAssistantMessage({
|
|
402
|
+
messages,
|
|
403
|
+
model: 'gpt-3.5-turbo-1106',
|
|
404
|
+
top_p: 1,
|
|
405
|
+
plugins: ['ttt'],
|
|
406
|
+
});
|
|
407
|
+
|
|
408
|
+
expect(getChatCompletionSpy).toHaveBeenCalledWith(
|
|
409
|
+
{
|
|
410
|
+
model: 'gpt-3.5-turbo-1106',
|
|
411
|
+
top_p: 1,
|
|
412
|
+
messages: [
|
|
413
|
+
{
|
|
414
|
+
content: 'system',
|
|
415
|
+
role: 'system',
|
|
416
|
+
},
|
|
417
|
+
{ content: 'https://vercel.com/ ่ฏทๅๆ chatGPT ๅ
ณ้ฎ่ฏ\n\n', role: 'user' },
|
|
418
|
+
],
|
|
419
|
+
},
|
|
420
|
+
undefined,
|
|
421
|
+
);
|
|
422
|
+
});
|
|
423
|
+
});
|
|
185
424
|
});
|
|
425
|
+
|
|
186
426
|
describe('getChatCompletion', () => {
|
|
187
427
|
it('should make a POST request with the correct payload', async () => {
|
|
188
428
|
const params: Partial<OpenAIChatStreamPayload> = {
|
package/src/services/chat.ts
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import { PluginRequestPayload, createHeadersWithPluginSettings } from '@lobehub/chat-plugin-sdk';
|
|
2
|
+
import { produce } from 'immer';
|
|
2
3
|
import { merge } from 'lodash-es';
|
|
3
4
|
|
|
4
5
|
import { VISION_MODEL_WHITE_LIST } from '@/const/llm';
|
|
@@ -37,7 +38,7 @@ class ChatService {
|
|
|
37
38
|
);
|
|
38
39
|
// ============ 1. preprocess messages ============ //
|
|
39
40
|
|
|
40
|
-
const oaiMessages = this.processMessages(messages);
|
|
41
|
+
const oaiMessages = this.processMessages(messages, enabledPlugins);
|
|
41
42
|
|
|
42
43
|
// ============ 2. preprocess tools ============ //
|
|
43
44
|
|
|
@@ -102,7 +103,7 @@ class ChatService {
|
|
|
102
103
|
|
|
103
104
|
fetchPresetTaskResult = fetchAIFactory(this.getChatCompletion);
|
|
104
105
|
|
|
105
|
-
private processMessages = (messages: ChatMessage[]): OpenAIChatMessage[] => {
|
|
106
|
+
private processMessages = (messages: ChatMessage[], tools?: string[]): OpenAIChatMessage[] => {
|
|
106
107
|
// handle content type for vision model
|
|
107
108
|
// for the models with visual ability, add image url to content
|
|
108
109
|
// refs: https://platform.openai.com/docs/guides/vision/quick-start
|
|
@@ -121,7 +122,7 @@ class ChatService {
|
|
|
121
122
|
] as UserMessageContentPart[];
|
|
122
123
|
};
|
|
123
124
|
|
|
124
|
-
|
|
125
|
+
const postMessages = messages.map((m): OpenAIChatMessage => {
|
|
125
126
|
switch (m.role) {
|
|
126
127
|
case 'user': {
|
|
127
128
|
return { content: getContent(m), role: m.role };
|
|
@@ -137,6 +138,27 @@ class ChatService {
|
|
|
137
138
|
}
|
|
138
139
|
}
|
|
139
140
|
});
|
|
141
|
+
|
|
142
|
+
return produce(postMessages, (draft) => {
|
|
143
|
+
if (!tools || tools.length === 0) return;
|
|
144
|
+
|
|
145
|
+
const systemMessage = draft.find((i) => i.role === 'system');
|
|
146
|
+
|
|
147
|
+
const toolsSystemRoles = pluginSelectors.enabledPluginsSystemRoles(tools)(
|
|
148
|
+
useToolStore.getState(),
|
|
149
|
+
);
|
|
150
|
+
|
|
151
|
+
if (!toolsSystemRoles) return;
|
|
152
|
+
|
|
153
|
+
if (systemMessage) {
|
|
154
|
+
systemMessage.content = systemMessage.content + '\n\n' + toolsSystemRoles;
|
|
155
|
+
} else {
|
|
156
|
+
draft.unshift({
|
|
157
|
+
content: toolsSystemRoles,
|
|
158
|
+
role: 'system',
|
|
159
|
+
});
|
|
160
|
+
}
|
|
161
|
+
});
|
|
140
162
|
};
|
|
141
163
|
}
|
|
142
164
|
|
package/src/services/plugin.ts
CHANGED
|
@@ -30,6 +30,14 @@ const mockState = {
|
|
|
30
30
|
},
|
|
31
31
|
type: 'plugin',
|
|
32
32
|
},
|
|
33
|
+
{
|
|
34
|
+
identifier: 'plugin-3',
|
|
35
|
+
manifest: {
|
|
36
|
+
identifier: 'plugin-3',
|
|
37
|
+
api: [{ name: 'api-3' }],
|
|
38
|
+
},
|
|
39
|
+
type: 'customPlugin',
|
|
40
|
+
},
|
|
33
41
|
],
|
|
34
42
|
pluginStoreList: [
|
|
35
43
|
{
|
|
@@ -57,22 +65,42 @@ describe('pluginSelectors', () => {
|
|
|
57
65
|
});
|
|
58
66
|
|
|
59
67
|
it('enabledSchema should return with standalone plugin', () => {
|
|
60
|
-
const result = pluginSelectors.enabledSchema(['plugin-
|
|
68
|
+
const result = pluginSelectors.enabledSchema(['plugin-4'])({
|
|
61
69
|
...mockState,
|
|
62
70
|
installedPlugins: [
|
|
63
71
|
...mockState.installedPlugins,
|
|
64
72
|
{
|
|
65
|
-
identifier: 'plugin-
|
|
73
|
+
identifier: 'plugin-4',
|
|
66
74
|
manifest: {
|
|
67
|
-
identifier: 'plugin-
|
|
68
|
-
api: [{ name: 'api-
|
|
75
|
+
identifier: 'plugin-4',
|
|
76
|
+
api: [{ name: 'api-4' }],
|
|
69
77
|
type: 'standalone',
|
|
70
78
|
},
|
|
71
79
|
type: 'plugin',
|
|
72
80
|
},
|
|
73
81
|
],
|
|
74
82
|
} as ToolStoreState);
|
|
75
|
-
expect(result).toEqual([{ name: 'plugin-
|
|
83
|
+
expect(result).toEqual([{ name: 'plugin-4____api-4____standalone' }]);
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it('enabledSchema should return md5 hash apiName', () => {
|
|
87
|
+
const result = pluginSelectors.enabledSchema(['long-long-plugin-with-id'])({
|
|
88
|
+
...mockState,
|
|
89
|
+
installedPlugins: [
|
|
90
|
+
...mockState.installedPlugins,
|
|
91
|
+
{
|
|
92
|
+
identifier: 'long-long-plugin-with-id',
|
|
93
|
+
manifest: {
|
|
94
|
+
identifier: 'long-long-plugin-with-id',
|
|
95
|
+
api: [{ name: 'long-long-manifest-long-long-apiName' }],
|
|
96
|
+
},
|
|
97
|
+
type: 'plugin',
|
|
98
|
+
},
|
|
99
|
+
],
|
|
100
|
+
} as ToolStoreState);
|
|
101
|
+
expect(result).toEqual([
|
|
102
|
+
{ name: 'long-long-plugin-with-id____MD5HASH_396eae4c671da3fb642c49ad2b9e8790' },
|
|
103
|
+
]);
|
|
76
104
|
});
|
|
77
105
|
|
|
78
106
|
it('enabledSchema should return empty', () => {
|
|
@@ -204,7 +232,7 @@ describe('pluginSelectors', () => {
|
|
|
204
232
|
describe('storeAndInstallPluginsIdList', () => {
|
|
205
233
|
it('should return a list of unique plugin identifiers from both installed and store lists', () => {
|
|
206
234
|
const result = pluginSelectors.storeAndInstallPluginsIdList(mockState);
|
|
207
|
-
expect(result).toEqual(['plugin-1', 'plugin-2']);
|
|
235
|
+
expect(result).toEqual(['plugin-1', 'plugin-2', 'plugin-3']);
|
|
208
236
|
});
|
|
209
237
|
});
|
|
210
238
|
|
|
@@ -227,4 +255,12 @@ describe('pluginSelectors', () => {
|
|
|
227
255
|
expect(result).toEqual(expectedMetaList);
|
|
228
256
|
});
|
|
229
257
|
});
|
|
258
|
+
|
|
259
|
+
describe('installedCustomPluginMetaList', () => {
|
|
260
|
+
it('should return a list of meta information for installed plugins', () => {
|
|
261
|
+
const result = pluginSelectors.installedCustomPluginMetaList(mockState);
|
|
262
|
+
|
|
263
|
+
expect(result).toEqual([{ identifier: 'plugin-3', type: 'customPlugin' }]);
|
|
264
|
+
});
|
|
265
|
+
});
|
|
230
266
|
});
|
|
@@ -6,6 +6,7 @@ import { PLUGIN_SCHEMA_API_MD5_PREFIX, PLUGIN_SCHEMA_SEPARATOR } from '@/const/p
|
|
|
6
6
|
import { ChatCompletionFunctions } from '@/types/openai/chat';
|
|
7
7
|
import { InstallPluginMeta, LobeToolCustomPlugin } from '@/types/tool/plugin';
|
|
8
8
|
|
|
9
|
+
import { pluginHelpers } from '../../helpers';
|
|
9
10
|
import type { ToolStoreState } from '../../initialState';
|
|
10
11
|
|
|
11
12
|
const installedPlugins = (s: ToolStoreState) => s.installedPlugins;
|
|
@@ -118,7 +119,33 @@ const enabledSchema =
|
|
|
118
119
|
return uniqBy(list, 'name');
|
|
119
120
|
};
|
|
120
121
|
|
|
122
|
+
const enabledPluginsSystemRoles =
|
|
123
|
+
(enabledPlugins: string[] = []) =>
|
|
124
|
+
(s: ToolStoreState) => {
|
|
125
|
+
const toolsSystemRole = enabledPlugins
|
|
126
|
+
.map((id) => {
|
|
127
|
+
const manifest = getPluginManifestById(id)(s);
|
|
128
|
+
if (!manifest) return '';
|
|
129
|
+
const meta = getPluginMetaById(id)(s);
|
|
130
|
+
|
|
131
|
+
const title = pluginHelpers.getPluginTitle(meta);
|
|
132
|
+
const desc = pluginHelpers.getPluginDesc(meta);
|
|
133
|
+
|
|
134
|
+
return [`### ${title}`, manifest.systemRole || desc].join('\n\n');
|
|
135
|
+
})
|
|
136
|
+
.filter(Boolean);
|
|
137
|
+
|
|
138
|
+
if (toolsSystemRole.length > 0) {
|
|
139
|
+
return ['## Tools', 'You can use these tools below:', ...toolsSystemRole]
|
|
140
|
+
.filter(Boolean)
|
|
141
|
+
.join('\n\n');
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
return '';
|
|
145
|
+
};
|
|
146
|
+
|
|
121
147
|
export const pluginSelectors = {
|
|
148
|
+
enabledPluginsSystemRoles,
|
|
122
149
|
enabledSchema,
|
|
123
150
|
getCustomPluginById,
|
|
124
151
|
getInstalledPluginById,
|