Skip to content

Commit

Permalink
fix: Compatible with unresponsive headers
Browse files Browse the repository at this point in the history
  • Loading branch information
adolphnov committed Aug 4, 2024
1 parent 40357f3 commit b23b9de
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 8 deletions.
2 changes: 1 addition & 1 deletion dist/buildinfo.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"sha": "5c6a9b0", "timestamp": 1722790237}
{"sha": "40357f3", "timestamp": 1722791196}
14 changes: 10 additions & 4 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -182,9 +182,9 @@ var Environment = class {
// -- 版本数据 --
//
// 当前版本
BUILD_TIMESTAMP = 1722790237;
BUILD_TIMESTAMP = 1722791196;
// 当前版本 commit id
BUILD_VERSION = "5c6a9b0";
BUILD_VERSION = "40357f3";
// -- 基础配置 --
/**
* @type {I18n | null}
Expand Down Expand Up @@ -1282,9 +1282,15 @@ function fixOpenAICompatibleOptions(options) {
return options;
}
function isJsonResponse(resp) {
if (!resp.headers?.get("content-type")) {
return false;
}
return resp.headers.get("content-type").indexOf("json") !== -1;
}
function isEventStreamResponse(resp) {
if (!resp.headers?.get("content-type")) {
return false;
}
const types = ["application/stream+json", "text/event-stream"];
const content = resp.headers.get("content-type");
for (const type of types) {
Expand Down Expand Up @@ -1360,9 +1366,9 @@ ERROR: ${e.message}`;
await msgPromise;
return contentFull;
}
if (ENV.DEV_MODE) {
if (ENV.DEBUG_MODE) {
const resp2 = await resp2.clone().text();
console.log("resp result:", resp2);
console.log("resp result: ", resp2);
}
if (!isJsonResponse(resp)) {
throw new Error(resp.statusText);
Expand Down
2 changes: 1 addition & 1 deletion dist/timestamp
Original file line number Diff line number Diff line change
@@ -1 +1 @@
1722790237
1722791196
10 changes: 8 additions & 2 deletions src/agent/request.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@ function fixOpenAICompatibleOptions(options) {
* @return {boolean}
*/
export function isJsonResponse(resp) {
if (!resp.headers?.get('content-type')) {
return false;
}
return resp.headers.get('content-type').indexOf('json') !== -1;
}

Expand All @@ -72,6 +75,9 @@ export function isJsonResponse(resp) {
* @return {boolean}
*/
export function isEventStreamResponse(resp) {
if (!resp.headers?.get('content-type')) {
return false;
}
const types = ['application/stream+json', 'text/event-stream'];
const content = resp.headers.get('content-type');
for (const type of types) {
Expand Down Expand Up @@ -162,9 +168,9 @@ export async function requestChatCompletions(url, header, body, context, onStrea
return contentFull;
}

if (ENV.DEV_MODE) {
if (ENV.DEBUG_MODE) {
const resp = await resp.clone().text();
console.log("resp result:", resp);
console.log("resp result: ", resp);
}

if (!isJsonResponse(resp)) {
Expand Down

0 comments on commit b23b9de

Please sign in to comment.