@lobehub/chat 0.39.2 → 0.39.3
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/package.json +1 -1
- package/src/locales/default/error.ts +1 -0
- package/src/pages/api/openai.ts +12 -7
- package/src/types/fetch.ts +1 -0
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,31 @@
|
|
|
2
2
|
|
|
3
3
|
# Changelog
|
|
4
4
|
|
|
5
|
+
### [Version 0.39.3](https://github.com/lobehub/lobe-chat/compare/v0.39.2...v0.39.3)
|
|
6
|
+
|
|
7
|
+
<sup>Released on **2023-08-04**</sup>
|
|
8
|
+
|
|
9
|
+
#### 🐛 Bug Fixes
|
|
10
|
+
|
|
11
|
+
- **misc**: 优化 405 报错返回内容,并优化 openai 服务端超时处理逻辑.
|
|
12
|
+
|
|
13
|
+
<br/>
|
|
14
|
+
|
|
15
|
+
<details>
|
|
16
|
+
<summary><kbd>Improvements and Fixes</kbd></summary>
|
|
17
|
+
|
|
18
|
+
#### What's fixed
|
|
19
|
+
|
|
20
|
+
- **misc**: 优化 405 报错返回内容,并优化 openai 服务端超时处理逻辑 ([0acc829](https://github.com/lobehub/lobe-chat/commit/0acc829))
|
|
21
|
+
|
|
22
|
+
</details>
|
|
23
|
+
|
|
24
|
+
<div align="right">
|
|
25
|
+
|
|
26
|
+
[](#readme-top)
|
|
27
|
+
|
|
28
|
+
</div>
|
|
29
|
+
|
|
5
30
|
### [Version 0.39.2](https://github.com/lobehub/lobe-chat/compare/v0.39.1...v0.39.2)
|
|
6
31
|
|
|
7
32
|
<sup>Released on **2023-08-04**</sup>
|
package/package.json
CHANGED
|
@@ -4,6 +4,7 @@ export default {
|
|
|
4
4
|
401: '很抱歉,服务器拒绝了您的请求,可能是因为您的权限不足或未提供有效的身份验证',
|
|
5
5
|
403: '很抱歉,服务器拒绝了您的请求,您没有访问此内容的权限 ',
|
|
6
6
|
404: '很抱歉,服务器找不到您请求的页面或资源,请确认您的 URL 是否正确',
|
|
7
|
+
405: '很抱歉,服务器不支持您使用的请求方法,请确认您的请求方法是否正确',
|
|
7
8
|
429: '很抱歉,您的请求太多,服务器有点累了,请稍后再试',
|
|
8
9
|
500: '很抱歉,服务器似乎遇到了一些困难,暂时无法完成您的请求,请稍后再试',
|
|
9
10
|
502: '很抱歉,服务器似乎迷失了方向,暂时无法提供服务,请稍后再试',
|
package/src/pages/api/openai.ts
CHANGED
|
@@ -65,15 +65,20 @@ export const createChatCompletion = async ({
|
|
|
65
65
|
|
|
66
66
|
const requestParams = { functions, messages: formatMessages, stream: true, ...params };
|
|
67
67
|
|
|
68
|
-
|
|
68
|
+
try {
|
|
69
|
+
const response = await openai.createChatCompletion(requestParams);
|
|
69
70
|
|
|
70
|
-
|
|
71
|
-
|
|
71
|
+
if (!response.ok) {
|
|
72
|
+
const error = await response.json();
|
|
72
73
|
|
|
73
|
-
|
|
74
|
-
|
|
74
|
+
return createErrorResponse(ErrorType.OpenAIBizError, error);
|
|
75
|
+
}
|
|
75
76
|
|
|
76
|
-
|
|
77
|
+
const stream = OpenAIStream(response, callbacks?.(requestParams));
|
|
77
78
|
|
|
78
|
-
|
|
79
|
+
return new StreamingTextResponse(stream);
|
|
80
|
+
} catch (error) {
|
|
81
|
+
// 如果 await 超时报错,说明是 OpenAI 服务端的问题
|
|
82
|
+
return createErrorResponse(ErrorType.GatewayTimeout, { message: error });
|
|
83
|
+
}
|
|
79
84
|
};
|