@lobehub/chat 0.101.3 → 0.101.5
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 +37 -21
- package/README.zh-CN.md +36 -20
- package/docs/Deploy-with-Azure-OpenAI.md +2 -1
- package/docs/Deploy-with-Azure-OpenAI.zh-CN.md +2 -1
- package/docs/Docker-Deployment.md +3 -2
- package/docs/Docker-Deployment.zh-CN.md +3 -2
- package/docs/Upstream-Sync.md +2 -1
- package/docs/Upstream-Sync.zh-CN.md +2 -1
- package/docs/Usage-Agents.md +12 -6
- package/docs/Usage-Agents.zh-CN.md +12 -6
- package/docs/Usage-Topics.md +1 -1
- package/docs/Usage-Topics.zh-CN.md +1 -1
- package/next.config.mjs +10 -2
- package/package.json +2 -2
- package/src/app/api/openai/chat/createChatCompletion.test.ts +129 -0
- package/src/app/api/openai/chat/createChatCompletion.ts +21 -2
- package/src/store/session/slices/session/action.ts +8 -4
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,56 @@
|
|
|
2
2
|
|
|
3
3
|
# Changelog
|
|
4
4
|
|
|
5
|
+
### [Version 0.101.5](https://github.com/lobehub/lobe-chat/compare/v0.101.4...v0.101.5)
|
|
6
|
+
|
|
7
|
+
<sup>Released on **2023-11-17**</sup>
|
|
8
|
+
|
|
9
|
+
#### 🐛 Bug Fixes
|
|
10
|
+
|
|
11
|
+
- **misc**: Improve openai error info.
|
|
12
|
+
|
|
13
|
+
<br/>
|
|
14
|
+
|
|
15
|
+
<details>
|
|
16
|
+
<summary><kbd>Improvements and Fixes</kbd></summary>
|
|
17
|
+
|
|
18
|
+
#### What's fixed
|
|
19
|
+
|
|
20
|
+
- **misc**: Improve openai error info, closes [#469](https://github.com/lobehub/lobe-chat/issues/469) ([5523b64](https://github.com/lobehub/lobe-chat/commit/5523b64))
|
|
21
|
+
|
|
22
|
+
</details>
|
|
23
|
+
|
|
24
|
+
<div align="right">
|
|
25
|
+
|
|
26
|
+
[](#readme-top)
|
|
27
|
+
|
|
28
|
+
</div>
|
|
29
|
+
|
|
30
|
+
### [Version 0.101.4](https://github.com/lobehub/lobe-chat/compare/v0.101.3...v0.101.4)
|
|
31
|
+
|
|
32
|
+
<sup>Released on **2023-11-14**</sup>
|
|
33
|
+
|
|
34
|
+
#### 🐛 Bug Fixes
|
|
35
|
+
|
|
36
|
+
- **misc**: Fix the plugin array merge error when fork agent from market.
|
|
37
|
+
|
|
38
|
+
<br/>
|
|
39
|
+
|
|
40
|
+
<details>
|
|
41
|
+
<summary><kbd>Improvements and Fixes</kbd></summary>
|
|
42
|
+
|
|
43
|
+
#### What's fixed
|
|
44
|
+
|
|
45
|
+
- **misc**: Fix the plugin array merge error when fork agent from market, closes [#459](https://github.com/lobehub/lobe-chat/issues/459) ([fc29b33](https://github.com/lobehub/lobe-chat/commit/fc29b33))
|
|
46
|
+
|
|
47
|
+
</details>
|
|
48
|
+
|
|
49
|
+
<div align="right">
|
|
50
|
+
|
|
51
|
+
[](#readme-top)
|
|
52
|
+
|
|
53
|
+
</div>
|
|
54
|
+
|
|
5
55
|
### [Version 0.101.3](https://github.com/lobehub/lobe-chat/compare/v0.101.2...v0.101.3)
|
|
6
56
|
|
|
7
57
|
<sup>Released on **2023-11-14**</sup>
|
package/README.md
CHANGED
|
@@ -74,7 +74,8 @@ Please be aware that LobeChat is currently under active development, and feedbac
|
|
|
74
74
|
| :---------------------------------------- | :----------------------------------------------------------------------------------------------------------------- |
|
|
75
75
|
| [![][discord-shield-badge]][discord-link] | Join our Discord community! This is where you can connect with developers and other enthusiastic users of LobeHub. |
|
|
76
76
|
|
|
77
|
-
>
|
|
77
|
+
> \[!IMPORTANT]
|
|
78
|
+
>
|
|
78
79
|
> **Star Us**, You will receive all release notifications from GitHub without any delay \~ ⭐️
|
|
79
80
|
|
|
80
81
|

|
|
@@ -88,18 +89,26 @@ Please be aware that LobeChat is currently under active development, and feedbac
|
|
|
88
89
|
|
|
89
90
|
## ✨ Features
|
|
90
91
|
|
|
91
|
-
- [x] 💨 **Quick Deployment**: Using the Vercel platform, you can deploy with just one click and complete the process within 1 minute without any complex configuration.
|
|
92
92
|
- [x] 💎 **Exquisite UI Design**: With a carefully designed interface, it offers an elegant appearance and smooth interaction. It supports light and dark themes and is mobile-friendly. PWA support provides a more native-like experience.
|
|
93
93
|
- [x] 🗣️ **Smooth Conversation Experience**: Fluid responses ensure a smooth conversation experience. It fully supports Markdown rendering, including code highlighting, LaTex formulas, Mermaid flowcharts, and more.
|
|
94
|
-
- [x] 🧩 **Plugin Support & Custom Plugin Development**: Conversations are extendable with plugins. Users can install and use various plugins, such as search engines, web extraction, etc. It also supports the development of custom plugins to meet custom needs.
|
|
95
|
-
- [x] 🔒 **Privacy Protection**: All data is stored locally in the user's browser, ensuring user privacy.
|
|
96
94
|
- [x] 🤖 **Customizable Agent Roles**: Users can create, share, and debug personalized dialogue agent roles according to their needs, providing more flexible and customized dialogue functions.
|
|
97
|
-
- [x]
|
|
98
|
-
- [x] 🏬 **
|
|
95
|
+
- [x] 🧩 **Plugin Support & Custom Plugin Development**: Conversations are extendable with plugins. Users can install and use various plugins, such as search engines, web extraction, etc. It also supports the development of custom plugins to meet custom needs.
|
|
96
|
+
- [x] 🏬 **Agent Market**: A Agent Market is provided where users can select their preferred dialogue agent roles, enriching the content and style of the dialogue.
|
|
97
|
+
- [x] 👁️ **Visual Recognition**: With the integration of visual recognition capabilities, your agent can now analyze and understand images provided during the conversation. This allows for more interactive and context-aware conversations, enabling the dialogue agent to provide relevant and accurate responses based on visual content.
|
|
98
|
+
- [ ] (WIP)📢 **Text-to-Speech (TTS) Conversation**: LobeChat are supporting Text-to-Speech technology, allowing users to have voice-based conversations with the dialogue agent. This feature enhances the user experience by providing a more natural and immersive conversation environment. Users can choose from a variety of voices and adjust the speech rate to suit their preferences.
|
|
99
99
|
|
|
100
|
-
>
|
|
100
|
+
> \[!NOTE]
|
|
101
|
+
>
|
|
101
102
|
> You can find our upcoming [Roadmap][github-project-link] plans in the Projects section.
|
|
102
103
|
|
|
104
|
+
---
|
|
105
|
+
|
|
106
|
+
Beside these features, LobeChat also have much better basic technique underground:
|
|
107
|
+
|
|
108
|
+
- [x] 💨 **Quick Deployment**: Using the Vercel platform or docker image, you can deploy with just one click and complete the process within 1 minute without any complex configuration.
|
|
109
|
+
- [x] 🌐 **Custom Domain**: If users have their own domain, they can bind it to the platform for quick access to the dialogue agent from anywhere.
|
|
110
|
+
- [x] 🔒 **Privacy Protection**: All data is stored locally in the user's browser, ensuring user privacy.
|
|
111
|
+
|
|
103
112
|
<div align="right">
|
|
104
113
|
|
|
105
114
|
[![][back-to-top]](#readme-top)
|
|
@@ -124,14 +133,14 @@ In our agent market. We have accumulated a large number of practical, prompt age
|
|
|
124
133
|
|
|
125
134
|
<!-- AGENT LIST -->
|
|
126
135
|
|
|
127
|
-
| Recent Submits
|
|
128
|
-
|
|
|
129
|
-
| [
|
|
130
|
-
| [
|
|
131
|
-
| [
|
|
132
|
-
| [
|
|
136
|
+
| Recent Submits | Description |
|
|
137
|
+
| --------------------------------------------------------------------------------------------------------------------------------------------------------------------------- | ----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
138
|
+
| [Expert Agent Mentor](https://chat-preview.lobehub.com/market?agent=co-agent)<br/><sup>By **[tcmonster](https://github.com/tcmonster)** on **2023-11-16**</sup> | Call on expert agents perfectly suited for the task to support your goals<br/>`task-guidance` `execution-plan` `communication` `support` |
|
|
139
|
+
| [Full-stack Developer](https://chat-preview.lobehub.com/market?agent=fs-dev)<br/><sup>By **[cloverfield11](https://github.com/cloverfield11)** on **2023-11-15**</sup> | Full-stack web developer with experience in HTML, CSS, JavaScript, Python, Java, Ruby, and frameworks such as React, Angular, Vue.js, Express, Django, Next.js, Flask, or Ruby on Rails. Experience in databases, application architecture, security, and testing.<br/>`web-development` `front-end` `back-end` `programming` `databases` |
|
|
140
|
+
| [Graphic Creative Master](https://chat-preview.lobehub.com/market?agent=graphic-creativity)<br/><sup>By **[yingxirz](https://github.com/yingxirz)** on **2023-11-15**</sup> | Specializes in graphic creative design and graphic creativity<br/>`graphic` `creative` `design` `graphic-design` |
|
|
141
|
+
| [Expert Agent Mentor](https://chat-preview.lobehub.com/market?agent=synapse-co-r)<br/><sup>By **[tcmonster](https://github.com/tcmonster)** on **2023-11-15**</sup> | Call on expert agents perfectly suited for the task to support your goals<br/>`task-guidance` `execution-plan` `communication` `support` |
|
|
133
142
|
|
|
134
|
-
> 📊 Total agents: [<kbd>**
|
|
143
|
+
> 📊 Total agents: [<kbd>**48**</kbd> ](https://github.com/lobehub/lobe-chat-agents)
|
|
135
144
|
|
|
136
145
|
<!-- AGENT LIST -->
|
|
137
146
|
|
|
@@ -143,7 +152,8 @@ In our agent market. We have accumulated a large number of practical, prompt age
|
|
|
143
152
|
|
|
144
153
|
Utilize the Progressive Web Application ([PWA](https://support.google.com/chrome/answer/9658361)) technology to achieve a seamless LobeChat experience on your computer or mobile device.
|
|
145
154
|
|
|
146
|
-
>
|
|
155
|
+
> \[!NOTE]
|
|
156
|
+
>
|
|
147
157
|
> If you are unfamiliar with the installation process of PWA, you can add LobeChat as your desktop application (also applicable to mobile devices) by following these steps:
|
|
148
158
|
>
|
|
149
159
|
> - Launch the Chrome or Edge browser on your computer.
|
|
@@ -175,7 +185,8 @@ We have carried out a series of optimization designs for mobile devices to enhan
|
|
|
175
185
|
|
|
176
186
|
## ⚡️ Performance
|
|
177
187
|
|
|
178
|
-
>
|
|
188
|
+
> \[!NOTE]
|
|
189
|
+
>
|
|
179
190
|
> The complete list of reports can be found in the [📘 Lighthouse Reports](https://github.com/lobehub/lobe-chat/wiki/Lighthouse)
|
|
180
191
|
|
|
181
192
|
| Desktop | Mobile |
|
|
@@ -212,7 +223,8 @@ If you want to deploy this service yourself on Vercel, you can follow these step
|
|
|
212
223
|
|
|
213
224
|
If you have deployed your own project following the one-click deployment steps in the README, you might encounter constant prompts indicating "updates available." This is because Vercel defaults to creating a new project instead of forking this one, resulting in an inability to detect updates accurately.
|
|
214
225
|
|
|
215
|
-
>
|
|
226
|
+
> \[!TIP]
|
|
227
|
+
>
|
|
216
228
|
> We suggest you redeploy using the following steps, [📘 Maintaining Updates with LobeChat Self-Deployment](https://github.com/lobehub/lobe-chat/wiki/Upstream-Sync).
|
|
217
229
|
|
|
218
230
|
<br/>
|
|
@@ -232,7 +244,8 @@ $ docker run -d -p 3210:3210 \
|
|
|
232
244
|
lobehub/lobe-chat
|
|
233
245
|
```
|
|
234
246
|
|
|
235
|
-
>
|
|
247
|
+
> \[!TIP]
|
|
248
|
+
>
|
|
236
249
|
> If you need to use the OpenAI service through a proxy, you can configure the proxy address using the `OPENAI_PROXY_URL` environment variable:
|
|
237
250
|
|
|
238
251
|
```fish
|
|
@@ -243,7 +256,8 @@ $ docker run -d -p 3210:3210 \
|
|
|
243
256
|
lobehub/lobe-chat
|
|
244
257
|
```
|
|
245
258
|
|
|
246
|
-
>
|
|
259
|
+
> \[!NOTE]
|
|
260
|
+
>
|
|
247
261
|
> For detailed instructions on deploying with Docker, please refer to the [📘 Docker Deployment Guide](https://github.com/lobehub/lobe-chat/wiki/Docker-Deployment)
|
|
248
262
|
|
|
249
263
|
<br/>
|
|
@@ -258,7 +272,8 @@ This project provides some additional configuration items set with environment v
|
|
|
258
272
|
| `OPENAI_PROXY_URL` | No | If you manually configure the OpenAI interface proxy, you can use this configuration item to override the default OpenAI API request base URL | `https://api.chatanywhere.cn/v1`<br/>The default value is<br/>`https://api.openai.com/v1` |
|
|
259
273
|
| `ACCESS_CODE` | No | Add a password to access this service; the password should be a 6-digit number or letter | `awCT74` or `e3@09!` |
|
|
260
274
|
|
|
261
|
-
>
|
|
275
|
+
> \[!NOTE]
|
|
276
|
+
>
|
|
262
277
|
> The complete list of environment variables can be found in the [📘 Environment Variables](https://github.com/lobehub/lobe-chat/wiki/Environment-Variable)
|
|
263
278
|
|
|
264
279
|
<div align="right">
|
|
@@ -290,7 +305,8 @@ Plugins provide a means to extend the [Function Calling][fc-link] capabilities o
|
|
|
290
305
|
- [@lobehub/chat-plugin-sdk][chat-plugin-sdk]: The LobeChat Plugin SDK assists you in creating exceptional chat plugins for Lobe Chat.
|
|
291
306
|
- [@lobehub/chat-plugins-gateway][chat-plugins-gateway]: The LobeChat Plugins Gateway is a backend service that provides a gateway for LobeChat plugins. We deploy this service using Vercel. The primary API POST /api/v1/runner is deployed as an Edge Function.
|
|
292
307
|
|
|
293
|
-
>
|
|
308
|
+
> \[!NOTE]
|
|
309
|
+
>
|
|
294
310
|
> The plugin system is currently undergoing major development. You can learn more in the following issues:
|
|
295
311
|
>
|
|
296
312
|
> - [x] [**Plugin Phase 1**](https://github.com/lobehub/lobe-chat/issues/73): Implement separation of the plugin from the main body, split the plugin into an independent repository for maintenance, and realize dynamic loading of the plugin.
|
package/README.zh-CN.md
CHANGED
|
@@ -27,7 +27,7 @@ LobeChat 是一个开源的、可扩展的([Function Calling][fc-link])高
|
|
|
27
27
|
[![][github-issues-shield]][github-issues-link]
|
|
28
28
|
[![][github-license-shield]][github-license-link]
|
|
29
29
|
|
|
30
|
-
|
|
30
|
+
**分享 LobeChat 给你的好友**
|
|
31
31
|
|
|
32
32
|
[![][share-x-shield]][share-x-link]
|
|
33
33
|
[![][share-telegram-shield]][share-telegram-link]
|
|
@@ -72,7 +72,8 @@ LobeChat 是一个开源的、可扩展的([Function Calling][fc-link])高
|
|
|
72
72
|
| :---------------------------------------- | :--------------------------------------------------------------------------- |
|
|
73
73
|
| [![][discord-shield-badge]][discord-link] | 加入我们的 Discord 社区!这是你可以与开发者和其他 LobeHub 热衷用户交流的地方 |
|
|
74
74
|
|
|
75
|
-
>
|
|
75
|
+
> \[!IMPORTANT]
|
|
76
|
+
>
|
|
76
77
|
> **收藏项目**,你将从 GitHub 上无延迟地接收所有发布通知~⭐️
|
|
77
78
|
|
|
78
79
|

|
|
@@ -86,18 +87,26 @@ LobeChat 是一个开源的、可扩展的([Function Calling][fc-link])高
|
|
|
86
87
|
|
|
87
88
|
## ✨ 功能特性
|
|
88
89
|
|
|
89
|
-
- [x] 💨 **快速部署**:使用 Vercel 平台,只需点击一键部署按钮,即可在 1 分钟内完成部署,无需复杂的配置过程 .
|
|
90
90
|
- [x] 💎 **精致 UI 设计**:经过精心设计的界面,具有优雅的外观和流畅的交互效果,支持亮暗色主题,适配移动端。支持 PWA,提供更加接近原生应用的体验 .
|
|
91
91
|
- [x] 🗣️ **流畅的对话体验**:流式响应带来流畅的对话体验,并且支持完整的 Markdown 渲染,包括代码高亮、LaTex 公式、Mermaid 流程图等 .
|
|
92
92
|
- [x] 🧩 **支持插件与自定义插件开发**:会话支持插件扩展,用户可以安装和使用各种插件,例如搜索引擎、网页提取等,同时也支持自定义插件的开发,满足自定义需求 .
|
|
93
|
-
- [x] 🔒 **隐私安全**:所有数据保存在用户浏览器本地,保证用户的隐私安全 .
|
|
94
93
|
- [x] 🤖 **自定义助手角色**:用户可以根据自己的需求创建、分享和调试个性化的对话助手角色,提供更加灵活和个性化的对话功能 .
|
|
95
|
-
- [x] 🌐 **自定义域名**:如果用户拥有自己的域名,可以将其绑定到平台上,方便在任何地方快速访问对话助手 .
|
|
96
94
|
- [x] 🏬 **角色市场**:提供角色市场,用户可以在市场上选择自己喜欢的对话助手角色,丰富对话的内容和风格 .
|
|
95
|
+
- [x] 👁️ **视觉识别**: 通过集成视觉识别能力,AI 助手现在可以分析和理解对话过程中提供的图像。这使得对话代理能够进行更具交互性和上下文感知的对话,根据视觉内容提供相关和准确的回答。
|
|
96
|
+
- [ ] (WIP)📢 **文本转语音(TTS)对话**: 我们正在支持文本转语音技术,允许用户与对话代理进行语音对话。这个功能通过提供更自然和沉浸式的对话环境来增强用户体验。用户可以选择多种声音并调整语速以适应自己的偏好。
|
|
97
97
|
|
|
98
|
-
>
|
|
98
|
+
> \[!NOTE]
|
|
99
|
+
>
|
|
99
100
|
> 你可以在 Projects 中找到我们后续的 [Roadmap][github-project-link] 计划
|
|
100
101
|
|
|
102
|
+
---
|
|
103
|
+
|
|
104
|
+
除了上述功能特性以外,我们的底层技术方案为你带来了更多使用保障:
|
|
105
|
+
|
|
106
|
+
- [x] 💨 **快速部署**:使用 Vercel 平台或者我们的 Docker 镜像,只需点击一键部署按钮,即可在 1 分钟内完成部署,无需复杂的配置过程 .
|
|
107
|
+
- [x] 🔒 **隐私安全**:所有数据保存在用户浏览器本地,保证用户的隐私安全 .
|
|
108
|
+
- [x] 🌐 **自定义域名**:如果用户拥有自己的域名,可以将其绑定到平台上,方便在任何地方快速访问对话助手 .
|
|
109
|
+
|
|
101
110
|
<div align="right">
|
|
102
111
|
|
|
103
112
|
[![][back-to-top]](#readme-top)
|
|
@@ -122,14 +131,14 @@ LobeChat 是一个开源的、可扩展的([Function Calling][fc-link])高
|
|
|
122
131
|
|
|
123
132
|
<!-- AGENT LIST -->
|
|
124
133
|
|
|
125
|
-
| 最近新增
|
|
126
|
-
|
|
|
127
|
-
| [
|
|
128
|
-
| [
|
|
129
|
-
| [
|
|
130
|
-
| [
|
|
134
|
+
| 最近新增 | 助手说明 |
|
|
135
|
+
| ---------------------------------------------------------------------------------------------------------------------------------------------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
136
|
+
| [专家代理人导师](https://chat-preview.lobehub.com/market?agent=co-agent)<br/><sup>By **[tcmonster](https://github.com/tcmonster)** on **2023-11-16**</sup> | 调用完全适合任务的专家代理人来支持您的目标<br/>`任务指导` `执行计划` `沟通` `支持` |
|
|
137
|
+
| [全栈开发人员](https://chat-preview.lobehub.com/market?agent=fs-dev)<br/><sup>By **[cloverfield11](https://github.com/cloverfield11)** on **2023-11-15**</sup> | 具有 HTML、CSS、JavaScript、Python、Java、Ruby 和 React、Angular、Vue.js、Express、Django、Next.js、Flask 或 Ruby on Rails 框架经验的全栈 Web 开发人员。具备数据库、应用架构、安全性和测试经验。<br/>`web开发` `前端` `后端` `编程` `数据库` |
|
|
138
|
+
| [图形创意大师](https://chat-preview.lobehub.com/market?agent=graphic-creativity)<br/><sup>By **[yingxirz](https://github.com/yingxirz)** on **2023-11-15**</sup> | 擅长平面创意设计与图形创意<br/>`图形` `创意` `设计` `平面` |
|
|
139
|
+
| [专家代理人导师](https://chat-preview.lobehub.com/market?agent=synapse-co-r)<br/><sup>By **[tcmonster](https://github.com/tcmonster)** on **2023-11-15**</sup> | 调用完全适合任务的专家代理人来支持您的目标<br/>`任务指导` `执行计划` `沟通` `支持` |
|
|
131
140
|
|
|
132
|
-
> 📊 Total agents: [<kbd>**
|
|
141
|
+
> 📊 Total agents: [<kbd>**48**</kbd> ](https://github.com/lobehub/lobe-chat-agents)
|
|
133
142
|
|
|
134
143
|
<!-- AGENT LIST -->
|
|
135
144
|
|
|
@@ -141,7 +150,8 @@ LobeChat 是一个开源的、可扩展的([Function Calling][fc-link])高
|
|
|
141
150
|
|
|
142
151
|
利用渐进式 Web 应用 [PWA](https://support.google.com/chrome/answer/9658361) 技术,您可在电脑或移动设备上实现流畅的 LobeChat 体验。
|
|
143
152
|
|
|
144
|
-
>
|
|
153
|
+
> \[!NOTE]
|
|
154
|
+
>
|
|
145
155
|
> 若您未熟悉 PWA 的安装过程,您可以按照以下步骤将 LobeChat 添加为您的桌面应用(也适用于移动设备):
|
|
146
156
|
>
|
|
147
157
|
> - 在电脑上运行 Chrome 或 Edge 浏览器 .
|
|
@@ -175,7 +185,8 @@ LobeChat 提供了两种独特的主题模式 - 明亮模式和暗黑模式,
|
|
|
175
185
|
|
|
176
186
|
## ⚡️ 性能测试
|
|
177
187
|
|
|
178
|
-
>
|
|
188
|
+
> \[!NOTE]
|
|
189
|
+
>
|
|
179
190
|
> 完整测试报告可见 [📘 Lighthouse 性能测试](https://github.com/lobehub/lobe-chat/wiki/Lighthouse.zh-CN)
|
|
180
191
|
|
|
181
192
|
| Desktop | Mobile |
|
|
@@ -214,7 +225,8 @@ LobeChat 提供了 Vercel 的 自托管版本 和 [Docker 镜像][docker-release
|
|
|
214
225
|
|
|
215
226
|
如果你根据 README 中的一键部署步骤部署了自己的项目,你可能会发现总是被提示 “有可用更新”。这是因为 Vercel 默认为你创建新项目而非 fork 本项目,这将导致无法准确检测更新。
|
|
216
227
|
|
|
217
|
-
>
|
|
228
|
+
> \[!TIP]
|
|
229
|
+
>
|
|
218
230
|
> 我们建议按照 [📘 LobeChat 自部署保持更新](https://github.com/lobehub/lobe-chat/wiki/Upstream-Sync.zh-CN) 步骤重新部署。
|
|
219
231
|
|
|
220
232
|
<br/>
|
|
@@ -234,7 +246,8 @@ $ docker run -d -p 3210:3210 \
|
|
|
234
246
|
lobehub/lobe-chat
|
|
235
247
|
```
|
|
236
248
|
|
|
237
|
-
>
|
|
249
|
+
> \[!TIP]
|
|
250
|
+
>
|
|
238
251
|
> 如果你需要通过代理使用 OpenAI 服务,你可以使用 `OPENAI_PROXY_URL` 环境变量来配置代理地址:
|
|
239
252
|
|
|
240
253
|
```fish
|
|
@@ -245,7 +258,8 @@ $ docker run -d -p 3210:3210 \
|
|
|
245
258
|
lobehub/lobe-chat
|
|
246
259
|
```
|
|
247
260
|
|
|
248
|
-
>
|
|
261
|
+
> \[!NOTE]
|
|
262
|
+
>
|
|
249
263
|
> 有关 Docker 部署的详细说明,详见 [📘 使用 Docker 部署](https://github.com/lobehub/lobe-chat/wiki/Docker-Deployment.zh-CN)
|
|
250
264
|
|
|
251
265
|
<br/>
|
|
@@ -260,7 +274,8 @@ $ docker run -d -p 3210:3210 \
|
|
|
260
274
|
| `OPENAI_PROXY_URL` | 可选 | 如果你手动配置了 OpenAI 接口代理,可以使用此配置项来覆盖默认的 OpenAI API 请求基础 URL | `https://api.chatanywhere.cn/v1`<br/>默认值:<br/>`https://api.openai.com/v1` |
|
|
261
275
|
| `ACCESS_CODE` | 可选 | 添加访问此服务的密码,密码应为 6 位数字或字母 | `awCT74` 或 `e3@09!` |
|
|
262
276
|
|
|
263
|
-
>
|
|
277
|
+
> \[!NOTE]
|
|
278
|
+
>
|
|
264
279
|
> 完整环境变量可见 [📘环境变量](https://github.com/lobehub/lobe-chat/wiki/Environment-Variable.zh-CN)
|
|
265
280
|
|
|
266
281
|
<div align="right">
|
|
@@ -292,7 +307,8 @@ $ docker run -d -p 3210:3210 \
|
|
|
292
307
|
- [@lobehub/chat-plugin-sdk][chat-plugin-sdk]:LobeChat 插件 SDK 可帮助您创建出色的 Lobe Chat 插件。
|
|
293
308
|
- [@lobehub/chat-plugins-gateway][chat-plugins-gateway]:LobeChat 插件网关是一个后端服务,作为 LobeChat 插件的网关。我们使用 Vercel 部署此服务。主要的 API POST /api/v1/runner 被部署为 Edge Function。
|
|
294
309
|
|
|
295
|
-
>
|
|
310
|
+
> \[!NOTE]
|
|
311
|
+
>
|
|
296
312
|
> 插件系统目前正在进行重大开发。您可以在以下 Issues 中了解更多信息:
|
|
297
313
|
>
|
|
298
314
|
> - [x] [**插件一期**](https://github.com/lobehub/lobe-chat/issues/73): 实现插件与主体分离,将插件拆分为独立仓库维护,并实现插件的动态加载
|
|
@@ -45,7 +45,8 @@ If you want the deployed version to be directly configured with Azure OpenAI for
|
|
|
45
45
|
| `AZURE_API_VERSION` | No | Azure's API version, follows the YYYY-MM-DD format | 2023-08-01-preview | `2023-05-15`, refer to [latest version][azure-api-version-url] |
|
|
46
46
|
| `ACCESS_CODE` | No | Add a password to access this service, the password should be 6 digits or letters | - | `awCT74` or `e3@09!` |
|
|
47
47
|
|
|
48
|
-
>
|
|
48
|
+
> \[!NOTE]
|
|
49
|
+
>
|
|
49
50
|
> When you enable `USE_AZURE_OPENAI` on the server side, users will not be able to modify and use the OpenAI key in the front-end configuration.
|
|
50
51
|
|
|
51
52
|
[azure-api-version-url]: https://learn.microsoft.com/zh-cn/azure/ai-services/openai/reference#chat-completions
|
|
@@ -45,7 +45,8 @@ LobeChat 支持使用 [Azure OpenAI][azure-openai-url] 作为 OpenAI 的模型
|
|
|
45
45
|
| `AZURE_API_VERSION` | 可选 | Azure 的 API 版本,遵循 YYYY-MM-DD 格式 | 2023-08-01-preview | `2023-05-15`,查阅[最新版本][azure-api-verion-url] |
|
|
46
46
|
| `ACCESS_CODE` | 可选 | 添加访问此服务的密码,密码应为 6 位数字或字母 | - | `awCT74` 或 `e3@09!` |
|
|
47
47
|
|
|
48
|
-
>
|
|
48
|
+
> \[!NOTE]
|
|
49
|
+
>
|
|
49
50
|
> 当你在服务端开启 `USE_AZURE_OPENAI` 后,用户将无法在前端配置中修改并使用 OpenAI key。
|
|
50
51
|
|
|
51
52
|
[azure-api-verion-url]: https://learn.microsoft.com/zh-cn/azure/ai-services/openai/reference#chat-completions
|
|
@@ -35,7 +35,7 @@ $ docker run -d -p 3210:3210 \
|
|
|
35
35
|
lobehub/lobe-chat
|
|
36
36
|
```
|
|
37
37
|
|
|
38
|
-
>
|
|
38
|
+
> \[!NOTE]
|
|
39
39
|
>
|
|
40
40
|
> - The default mapped port is `3210`. Make sure it is not occupied or manually change the port mapping.
|
|
41
41
|
> - Replace `sk-xxxx` in the above command with your own OpenAI API Key.
|
|
@@ -54,7 +54,8 @@ $ docker run -d -p 3210:3210 \
|
|
|
54
54
|
lobehub/lobe-chat
|
|
55
55
|
```
|
|
56
56
|
|
|
57
|
-
>
|
|
57
|
+
> \[!NOTE]
|
|
58
|
+
>
|
|
58
59
|
> As the official Docker image build takes about half an hour, if there is a "update available" prompt after updating deployment, wait for the image to finish building before deploying again.
|
|
59
60
|
|
|
60
61
|
### `B` Docker Compose
|
|
@@ -35,7 +35,7 @@ $ docker run -d -p 3210:3210 \
|
|
|
35
35
|
lobehub/lobe-chat
|
|
36
36
|
```
|
|
37
37
|
|
|
38
|
-
>
|
|
38
|
+
> \[!NOTE]
|
|
39
39
|
>
|
|
40
40
|
> - 默认映射端口为 `3210`, 请确保未被占用或手动更改端口映射
|
|
41
41
|
> - 使用你的 OpenAI API Key 替换上述命令中的 `sk-xxxx`
|
|
@@ -54,7 +54,8 @@ $ docker run -d -p 3210:3210 \
|
|
|
54
54
|
lobehub/lobe-chat
|
|
55
55
|
```
|
|
56
56
|
|
|
57
|
-
>
|
|
57
|
+
> \[!NOTE]
|
|
58
|
+
>
|
|
58
59
|
> 由于官方的 Docker 镜像构建大约需要半小时左右,如果在更新部署后会出现「存在更新」的提示,可以等待镜像构建完成后再次部署。
|
|
59
60
|
|
|
60
61
|
### `B` Docker Compose
|
package/docs/Upstream-Sync.md
CHANGED
|
@@ -8,7 +8,8 @@ If you have deployed your own project following the one-click deployment steps i
|
|
|
8
8
|
|
|
9
9
|
## Enabling Automatic Updates
|
|
10
10
|
|
|
11
|
-
>
|
|
11
|
+
> \[!NOTE]
|
|
12
|
+
>
|
|
12
13
|
> If you encounter an error executing Upstream Sync, manually Sync Fork once
|
|
13
14
|
|
|
14
15
|
Once you have forked the project, due to Github restrictions, you will need to manually enable Workflows on the Actions page of your forked project and activate the Upstream Sync Action. Once enabled, you can set up hourly automatic updates.
|
package/docs/Usage-Agents.md
CHANGED
|
@@ -34,7 +34,8 @@ When you need to handle specific tasks, you'll want to consider creating a custo
|
|
|
34
34
|

|
|
35
35
|

|
|
36
36
|
|
|
37
|
-
>
|
|
37
|
+
> \[!NOTE]
|
|
38
|
+
>
|
|
38
39
|
> Quick setting tip: You can conveniently modify the prompt by using the quick edit button in the sidebar.
|
|
39
40
|
|
|
40
41
|

|
|
@@ -50,7 +51,8 @@ Generative AI is very useful, but it requires human guidance. In most cases, gen
|
|
|
50
51
|
|
|
51
52
|
### How to write a structured prompt
|
|
52
53
|
|
|
53
|
-
>
|
|
54
|
+
> \[!TIP]
|
|
55
|
+
>
|
|
54
56
|
> A structured prompt refers to the construction of the prompt having clear logic and structure. For example, if you want the model to generate an article, your prompt may need to include the topic of the article, its outline, and its style.
|
|
55
57
|
|
|
56
58
|
Let's look at a basic example of a discussion question:
|
|
@@ -77,7 +79,8 @@ The second prompt generates longer outputs with better structure. The use of the
|
|
|
77
79
|
|
|
78
80
|
### How to improve quality and effectiveness
|
|
79
81
|
|
|
80
|
-
>
|
|
82
|
+
> \[!TIP]
|
|
83
|
+
>
|
|
81
84
|
> There are several ways to improve the quality and effectiveness of prompts:
|
|
82
85
|
>
|
|
83
86
|
> - Be as clear as possible about your needs. The model will try to fulfill your requirements, so if your requirements are not clear, the output may not meet your expectations.
|
|
@@ -154,7 +157,8 @@ Controls the randomness of the model's output. Higher values increase randomness
|
|
|
154
157
|
- Lower values make the output more focused and deterministic.
|
|
155
158
|
- Higher values make the output more random and creative.
|
|
156
159
|
|
|
157
|
-
>
|
|
160
|
+
> \[!NOTE]
|
|
161
|
+
>
|
|
158
162
|
> Generally, the longer and clearer the prompt, the better the quality and confidence of the generated output. In this case, you can increase the temperature value. Conversely, if the prompt is short and ambiguous, setting a higher temperature value will make the model's output less stable.
|
|
159
163
|
|
|
160
164
|
<br/>
|
|
@@ -163,7 +167,8 @@ Controls the randomness of the model's output. Higher values increase randomness
|
|
|
163
167
|
|
|
164
168
|
Top-p nucleus sampling is another sampling parameter that is different from temperature. Before the model generates the output, it generates a set of tokens. In top-p sampling mode, the candidate word list is dynamic and selected from the tokens based on a percentage. Top-p introduces randomness to the selection of tokens, allowing other high-scoring tokens to have a chance of being selected instead of always choosing the highest-scoring one.
|
|
165
169
|
|
|
166
|
-
>
|
|
170
|
+
> \[!NOTE]
|
|
171
|
+
>
|
|
167
172
|
> Top-p is similar to randomness. In general, it is not recommended to change it together with the randomness parameter, temperature.
|
|
168
173
|
|
|
169
174
|
<br/>
|
|
@@ -175,7 +180,8 @@ The presence penalty parameter can be seen as a punishment for repetitive conten
|
|
|
175
180
|
- Increasing the originality and diversity of the generated text: In some application scenarios, such as creative writing or generating news headlines, it is desirable for the generated text to have high originality and diversity. By increasing the value of the presence penalty parameter, the probability of generating repeated content in the generated text can be effectively reduced, thereby improving its originality and diversity.
|
|
176
181
|
- Preventing generation loops and meaningless content: In some cases, the generative model may produce repetitive and meaningless text that fails to convey useful information. By appropriately increasing the value of the presence penalty parameter, the probability of generating this type of meaningless content can be reduced, thereby improving the readability and usefulness of the generated text.
|
|
177
182
|
|
|
178
|
-
>
|
|
183
|
+
> \[!NOTE]
|
|
184
|
+
>
|
|
179
185
|
> It is worth noting that the presence penalty parameter, along with other parameters such as temperature and top-p, collectively affect the quality of the generated text. Compared to other parameters, the presence penalty parameter focuses more on the originality and repetitiveness of the text, while the temperature and top-p parameters have a greater impact on the randomness and determinism of the generated text. By adjusting these parameters properly, comprehensive control of the quality of the generated text can be achieved.
|
|
180
186
|
|
|
181
187
|
<br/>
|
|
@@ -34,7 +34,8 @@
|
|
|
34
34
|

|
|
35
35
|

|
|
36
36
|
|
|
37
|
-
>
|
|
37
|
+
> \[!NOTE]
|
|
38
|
+
>
|
|
38
39
|
> 快捷设置技巧:可以通过侧边栏的快捷编辑按钮进行 Prompt 的便捷修改
|
|
39
40
|
|
|
40
41
|

|
|
@@ -50,7 +51,8 @@
|
|
|
50
51
|
|
|
51
52
|
### 如何写好一个结构化 prompt
|
|
52
53
|
|
|
53
|
-
>
|
|
54
|
+
> \[!TIP]
|
|
55
|
+
>
|
|
54
56
|
> 结构化 prompt 是指 prompt 的构造应该有明确的逻辑和结构。例如,如果你想让模型生成一篇文章,你的 prompt 可能需要包括文章的主题,文章的大纲,文章的风格等信息。
|
|
55
57
|
|
|
56
58
|
让我们看一个基本的讨论问题的例子:
|
|
@@ -78,7 +80,8 @@
|
|
|
78
80
|
|
|
79
81
|
### 如何提升其质量和效果
|
|
80
82
|
|
|
81
|
-
>
|
|
83
|
+
> \[!TIP]
|
|
84
|
+
>
|
|
82
85
|
> 提升 prompt 质量和效果的方法主要有以下几点:
|
|
83
86
|
>
|
|
84
87
|
> - 尽量明确你的需求。模型的输出会尽可能满足你的需求,所以如果你的需求不明确,输出可能会不如预期。
|
|
@@ -155,7 +158,8 @@ LLM 看似很神奇,但本质还是一个概率问题,神经网络根据输
|
|
|
155
158
|
- 较低的值,输出更集中,更有确定性
|
|
156
159
|
- 较高的值,输出更随机(更有创意 )
|
|
157
160
|
|
|
158
|
-
>
|
|
161
|
+
> \[!NOTE]
|
|
162
|
+
>
|
|
159
163
|
> 一般来说,prompt 越长,描述得越清楚,模型生成的输出质量就越好,置信度越高,这时可以适当调高 temperature 的值;反过来,如果 prompt 很短,很含糊,这时再设置一个比较高的 temperature 值,模型的输出就很不稳定了。
|
|
160
164
|
|
|
161
165
|
<br/>
|
|
@@ -164,7 +168,8 @@ LLM 看似很神奇,但本质还是一个概率问题,神经网络根据输
|
|
|
164
168
|
|
|
165
169
|
核采样 top_p 也是采样参数,跟 temperature 不一样的采样方式。模型在输出之前,会生成一堆 token,这些 token 根据质量高低排名,核采样模式中候选词列表是动态的,从 tokens 里按百分比选择候选词。 top-p 为选择 token 引入了随机性,让其他高分的 token 有被选择的机会,不会总是选最高分的。
|
|
166
170
|
|
|
167
|
-
>
|
|
171
|
+
> \[!NOTE]
|
|
172
|
+
>
|
|
168
173
|
> top_p 与随机性类似,一般来说不建议和随机性 temperature 一起更改
|
|
169
174
|
|
|
170
175
|
<br/>
|
|
@@ -176,7 +181,8 @@ Presence Penalty 参数可以看作是对生成文本中重复内容的一种惩
|
|
|
176
181
|
- 提高生成文本的独创性和多样性:在某些应用场景下,如创意写作、生成新闻标题等,需要生成的文本具有较高的独创性和多样性。通过增加 Presence Penalty 参数的值,可以有效减少生成文本中的重复内容,从而提高文本的独创性和多样性。
|
|
177
182
|
- 防止生成循环和无意义的内容:在某些情况下,生成模型可能会产生循环、重复的文本,这些文本通常无法传达有效的信息。通过适当增加 Presence Penalty 参数的值,可以降低生成这类无意义内容的概率,提高生成文本的可读性和实用性。
|
|
178
183
|
|
|
179
|
-
>
|
|
184
|
+
> \[!NOTE]
|
|
185
|
+
>
|
|
180
186
|
> 值得注意的是,Presence Penalty 参数与其他参数(如 Temperature 和 top-p)共同影响着生成文本的质量。对比其他参数,Presence Penalty 参数主要关注文本的独创性和重复性,而 Temperature 和 top-p 参数则更多地影响着生成文本的随机性和确定性。通过合理地调整这些参数,可以实现对生成文本质量的综合控制
|
|
181
187
|
|
|
182
188
|
<br/>
|
package/docs/Usage-Topics.md
CHANGED
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
In the official ChatGPT app, there is only the concept of topics, as shown in the figure, the sidebar contains the user's historical conversation topic list.
|
|
11
11
|
|
|
12
|
-
>
|
|
12
|
+
> \[!NOTE]
|
|
13
13
|
>
|
|
14
14
|
> However, in our use, we actually find that this mode has many problems, such as the information indexing of historical conversations is too scattered, and when dealing with some repetitive tasks, it is difficult to have a stable entrance. For example, I hope there is a stable entrance to allow ChatGPT to help me translate documents. In this mode, I need to constantly create new topics and then set the translation Prompt I created before. When there are high-frequency tasks, this will be a very low-efficiency interaction form.
|
|
15
15
|
|
|
@@ -9,7 +9,7 @@
|
|
|
9
9
|
|
|
10
10
|
在 ChatGPT 官方应用中,只存在话题的概念,如图所示,在侧边栏中是用户的历史对话话题列表。
|
|
11
11
|
|
|
12
|
-
>
|
|
12
|
+
> \[!NOTE]
|
|
13
13
|
>
|
|
14
14
|
> 但在我们的使用过程中其实会发现这种模式存在很多问题,比如历史对话的信息索引过于分散问题,同时当处理一些重复任务时很难有一个稳定的入口,比如我希望有一个稳定的入口可以让 ChatGPT 帮助我翻译文档,在这个模式下,我需要不断新建新的话题同时再设置我之前创建好的翻译 Prompt 设定,当有高频任务存在时,这将是一个效率很低的交互形式。
|
|
15
15
|
|
package/next.config.mjs
CHANGED
|
@@ -69,7 +69,7 @@ const nextConfig = {
|
|
|
69
69
|
|
|
70
70
|
reactStrictMode: true,
|
|
71
71
|
|
|
72
|
-
transpilePackages: ['
|
|
72
|
+
transpilePackages: ['antd-style', '@lobehub/ui'],
|
|
73
73
|
|
|
74
74
|
webpack(config) {
|
|
75
75
|
config.experiments = {
|
|
@@ -77,7 +77,15 @@ const nextConfig = {
|
|
|
77
77
|
layers: true,
|
|
78
78
|
};
|
|
79
79
|
|
|
80
|
-
|
|
80
|
+
// to fix shikiji compile error
|
|
81
|
+
// refs: https://github.com/antfu/shikiji/issues/23
|
|
82
|
+
config.module.rules.push({
|
|
83
|
+
test: /\.m?js$/,
|
|
84
|
+
type: 'javascript/auto',
|
|
85
|
+
resolve: {
|
|
86
|
+
fullySpecified: false,
|
|
87
|
+
},
|
|
88
|
+
});
|
|
81
89
|
|
|
82
90
|
return config;
|
|
83
91
|
},
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@lobehub/chat",
|
|
3
|
-
"version": "0.101.
|
|
3
|
+
"version": "0.101.5",
|
|
4
4
|
"description": "An open-source, extensible (Function Calling), high-performance chatbot framework. It supports one-click free deployment of your private ChatGPT/LLM web application",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"chatbot",
|
|
@@ -93,7 +93,7 @@
|
|
|
93
93
|
"lucide-react": "latest",
|
|
94
94
|
"modern-screenshot": "^4",
|
|
95
95
|
"nanoid": "^5",
|
|
96
|
-
"next": "14.0.
|
|
96
|
+
"next": "^14.0.2",
|
|
97
97
|
"openai": "^4.17.3",
|
|
98
98
|
"polished": "^4",
|
|
99
99
|
"posthog-js": "^1",
|
|
@@ -0,0 +1,129 @@
|
|
|
1
|
+
import OpenAI, { APIError } from 'openai';
|
|
2
|
+
import { Mock, afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
|
3
|
+
|
|
4
|
+
import { createChatCompletion } from './createChatCompletion';
|
|
5
|
+
|
|
6
|
+
// Mock the console.error to avoid polluting test output
|
|
7
|
+
vi.spyOn(console, 'error').mockImplementation(() => {});
|
|
8
|
+
|
|
9
|
+
describe('createChatCompletion', () => {
|
|
10
|
+
let openaiInstance: OpenAI;
|
|
11
|
+
|
|
12
|
+
beforeEach(() => {
|
|
13
|
+
openaiInstance = new OpenAI({ apiKey: 'test', dangerouslyAllowBrowser: true });
|
|
14
|
+
|
|
15
|
+
// 使用 vi.spyOn 来模拟 chat.completions.create 方法
|
|
16
|
+
vi.spyOn(openaiInstance.chat.completions, 'create').mockResolvedValue(
|
|
17
|
+
new ReadableStream() as any,
|
|
18
|
+
);
|
|
19
|
+
});
|
|
20
|
+
|
|
21
|
+
afterEach(() => {
|
|
22
|
+
vi.clearAllMocks();
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it('should return a StreamingTextResponse on successful API call', async () => {
|
|
26
|
+
// Arrange
|
|
27
|
+
const mockStream = new ReadableStream();
|
|
28
|
+
const mockResponse = Promise.resolve(mockStream);
|
|
29
|
+
|
|
30
|
+
(openaiInstance.chat.completions.create as Mock).mockResolvedValue(mockResponse);
|
|
31
|
+
|
|
32
|
+
// Act
|
|
33
|
+
const result = await createChatCompletion({
|
|
34
|
+
openai: openaiInstance,
|
|
35
|
+
payload: {
|
|
36
|
+
messages: [{ content: 'Hello', name: 'User', role: 'user' }],
|
|
37
|
+
model: 'text-davinci-003',
|
|
38
|
+
temperature: 0,
|
|
39
|
+
},
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
// Assert
|
|
43
|
+
expect(result).toBeInstanceOf(Response); // 注意这里的改动
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('should return an openai error response when OpenAI.APIError is thrown', async () => {
|
|
47
|
+
// Arrange
|
|
48
|
+
const apiError = new OpenAI.APIError(
|
|
49
|
+
400,
|
|
50
|
+
{
|
|
51
|
+
status: 400,
|
|
52
|
+
error: {
|
|
53
|
+
message: 'Bad Request',
|
|
54
|
+
},
|
|
55
|
+
},
|
|
56
|
+
'Error message',
|
|
57
|
+
{},
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
vi.spyOn(openaiInstance.chat.completions, 'create').mockRejectedValue(apiError);
|
|
61
|
+
|
|
62
|
+
// Act
|
|
63
|
+
const result = await createChatCompletion({
|
|
64
|
+
openai: openaiInstance,
|
|
65
|
+
payload: {
|
|
66
|
+
messages: [{ content: 'Hello', name: 'User', role: 'user' }],
|
|
67
|
+
model: 'text-davinci-003',
|
|
68
|
+
temperature: 0,
|
|
69
|
+
},
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
// Assert
|
|
73
|
+
expect(result).toBeInstanceOf(Response);
|
|
74
|
+
expect(result.status).toBe(577); // Your custom error status code
|
|
75
|
+
});
|
|
76
|
+
it('should return an cause response when OpenAI.APIError is thrown with cause', async () => {
|
|
77
|
+
// Arrange
|
|
78
|
+
const errorInfo = {
|
|
79
|
+
stack: 'abc',
|
|
80
|
+
cause: {
|
|
81
|
+
message: 'api is undefined',
|
|
82
|
+
},
|
|
83
|
+
};
|
|
84
|
+
const apiError = new OpenAI.APIError(400, errorInfo, 'module error', {});
|
|
85
|
+
|
|
86
|
+
vi.spyOn(openaiInstance.chat.completions, 'create').mockRejectedValue(apiError);
|
|
87
|
+
|
|
88
|
+
// Act
|
|
89
|
+
const result = await createChatCompletion({
|
|
90
|
+
openai: openaiInstance,
|
|
91
|
+
payload: {
|
|
92
|
+
messages: [{ content: 'Hello', name: 'User', role: 'user' }],
|
|
93
|
+
model: 'text-davinci-003',
|
|
94
|
+
temperature: 0,
|
|
95
|
+
},
|
|
96
|
+
});
|
|
97
|
+
|
|
98
|
+
// Assert
|
|
99
|
+
expect(result).toBeInstanceOf(Response);
|
|
100
|
+
expect(result.status).toBe(577); // Your custom error status code
|
|
101
|
+
|
|
102
|
+
const content = await result.json();
|
|
103
|
+
expect(content.body).toHaveProperty('endpoint');
|
|
104
|
+
expect(content.body.error).toEqual(errorInfo);
|
|
105
|
+
});
|
|
106
|
+
|
|
107
|
+
it('should return a 500 error response for non-OpenAI errors', async () => {
|
|
108
|
+
// Arrange
|
|
109
|
+
const genericError = new Error('Generic Error');
|
|
110
|
+
|
|
111
|
+
vi.spyOn(openaiInstance.chat.completions, 'create').mockRejectedValue(genericError);
|
|
112
|
+
|
|
113
|
+
// Act
|
|
114
|
+
const result = await createChatCompletion({
|
|
115
|
+
openai: openaiInstance,
|
|
116
|
+
payload: {
|
|
117
|
+
messages: [{ content: 'Hello', name: 'User', role: 'user' }],
|
|
118
|
+
model: 'text-davinci-003',
|
|
119
|
+
temperature: 0,
|
|
120
|
+
},
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
// Assert
|
|
124
|
+
expect(result.status).toBe(500);
|
|
125
|
+
const content = await result.json();
|
|
126
|
+
expect(content.body).toHaveProperty('endpoint');
|
|
127
|
+
expect(content.body).toHaveProperty('error');
|
|
128
|
+
});
|
|
129
|
+
});
|
|
@@ -37,13 +37,32 @@ export const createChatCompletion = async ({ payload, openai }: CreateChatComple
|
|
|
37
37
|
} catch (error) {
|
|
38
38
|
// Check if the error is an OpenAI APIError
|
|
39
39
|
if (error instanceof OpenAI.APIError) {
|
|
40
|
+
let errorResult: any;
|
|
41
|
+
|
|
42
|
+
// if error is definitely OpenAI APIError, there will be an error object
|
|
43
|
+
if (error.error) {
|
|
44
|
+
errorResult = error.error;
|
|
45
|
+
}
|
|
46
|
+
// Or if there is a cause, we use error cause
|
|
47
|
+
// This often happened when there is a bug of the `openai` package.
|
|
48
|
+
else if (error.cause) {
|
|
49
|
+
errorResult = error.cause;
|
|
50
|
+
}
|
|
51
|
+
// if there is no other request error, the error object is a Response like object
|
|
52
|
+
else {
|
|
53
|
+
errorResult = { headers: error.headers, stack: error.stack, status: error.status };
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
// track the error at server side
|
|
57
|
+
console.error(errorResult);
|
|
58
|
+
|
|
40
59
|
return createErrorResponse(ChatErrorType.OpenAIBizError, {
|
|
41
60
|
endpoint: openai.baseURL,
|
|
42
|
-
error:
|
|
61
|
+
error: errorResult,
|
|
43
62
|
});
|
|
44
63
|
}
|
|
45
64
|
|
|
46
|
-
// track the error
|
|
65
|
+
// track the non-openai error
|
|
47
66
|
console.error(error);
|
|
48
67
|
|
|
49
68
|
// return as a GatewayTimeout error
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { produce } from 'immer';
|
|
2
|
-
import { merge } from 'lodash-es';
|
|
3
2
|
import { DeepPartial } from 'utility-types';
|
|
4
3
|
import { StateCreator } from 'zustand/vanilla';
|
|
5
4
|
|
|
6
5
|
import { INBOX_SESSION_ID } from '@/const/session';
|
|
7
6
|
import { SESSION_CHAT_URL } from '@/const/url';
|
|
8
|
-
import { useGlobalStore } from '@/store/global';
|
|
7
|
+
import { settingsSelectors, useGlobalStore } from '@/store/global';
|
|
9
8
|
import { SessionStore } from '@/store/session';
|
|
10
9
|
import { LobeAgentSession, LobeAgentSettings, LobeSessions } from '@/types/session';
|
|
10
|
+
import { merge } from '@/utils/merge';
|
|
11
11
|
import { setNamespace } from '@/utils/storeDebug';
|
|
12
12
|
import { uuid } from '@/utils/uuid';
|
|
13
13
|
|
|
@@ -85,8 +85,12 @@ export const createSessionSlice: StateCreator<
|
|
|
85
85
|
const timestamp = Date.now();
|
|
86
86
|
|
|
87
87
|
// 合并 settings 里的 defaultAgent
|
|
88
|
-
const
|
|
89
|
-
|
|
88
|
+
const defaultAgent = merge(
|
|
89
|
+
initLobeSession,
|
|
90
|
+
settingsSelectors.defaultAgent(useGlobalStore.getState()),
|
|
91
|
+
);
|
|
92
|
+
|
|
93
|
+
const newSession: LobeAgentSession = merge(defaultAgent, {
|
|
90
94
|
...agent,
|
|
91
95
|
createAt: timestamp,
|
|
92
96
|
id: uuid(),
|