koishi-plugin-satori-ai 1.1.2 → 1.1.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/lib/index.js +8 -5
- package/package.json +1 -1
package/lib/index.js
CHANGED
|
@@ -133,8 +133,11 @@ var APIClient = class {
|
|
|
133
133
|
async tryRequest(payload) {
|
|
134
134
|
const url = `${trimSlash(this.config.baseURL)}/v1/chat/completions`;
|
|
135
135
|
const headers = this.createHeaders();
|
|
136
|
-
const response = await this.ctx.http.post(url, payload, { headers, responseType: "text", timeout:
|
|
137
|
-
|
|
136
|
+
const response = await this.ctx.http.post(url, payload, { headers, responseType: "text", timeout: 30 * 60 * 1e3 });
|
|
137
|
+
if (response === "") {
|
|
138
|
+
logger.error("API返回空响应");
|
|
139
|
+
return { content: "API返回空响应", error: true };
|
|
140
|
+
}
|
|
138
141
|
const filteredResponse = response.split("\n").filter((line) => line.trim() !== "").join("\n");
|
|
139
142
|
const jsonResponse = JSON.parse(filteredResponse);
|
|
140
143
|
return { content: jsonResponse.choices[0].message.content, error: false };
|
|
@@ -150,7 +153,7 @@ var APIClient = class {
|
|
|
150
153
|
handleAPIError(error) {
|
|
151
154
|
if (!isErrorWithMessage(error))
|
|
152
155
|
throw error;
|
|
153
|
-
const status = error.response?.status ||
|
|
156
|
+
const status = error.response?.status || 0;
|
|
154
157
|
const errorCode = error.response?.data?.error?.code || "unknown";
|
|
155
158
|
const message = error.response?.data?.error?.message || error.message;
|
|
156
159
|
logger.error(`API Error [${status}]: ${errorCode} - ${message}`);
|
|
@@ -177,8 +180,8 @@ var APIClient = class {
|
|
|
177
180
|
logger.error("api服务器负载过高");
|
|
178
181
|
return { content: "api服务器负载过高", error: true };
|
|
179
182
|
default:
|
|
180
|
-
logger.error(
|
|
181
|
-
|
|
183
|
+
logger.error(message);
|
|
184
|
+
return { content: message, error: true };
|
|
182
185
|
}
|
|
183
186
|
}
|
|
184
187
|
// 切换API密钥
|