Skip to content

Commit

Permalink
响应为json时将错误输出
Browse files Browse the repository at this point in the history
  • Loading branch information
Vinlic committed Apr 9, 2024
1 parent 26e1735 commit 0dd4fa0
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/api/controllers/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -215,12 +215,13 @@ async function createCompletion(
responseType: "stream",
}
);

if (result.headers["content-type"].indexOf("text/event-stream") == -1)
if (result.headers["content-type"].indexOf("text/event-stream") == -1) {
result.data.on("data", buffer => logger.error(buffer.toString()));
throw new APIException(
EX.API_REQUEST_FAILED,
`Stream response Content-Type invalid: ${result.headers["content-type"]}`
);
}

const streamStartTime = util.timestamp();
// 接收流为输出文本
Expand Down Expand Up @@ -316,6 +317,7 @@ async function createCompletionStream(
`Invalid response Content-Type:`,
result.headers["content-type"]
);
result.data.on("data", buffer => logger.error(buffer.toString()));
const transStream = new PassThrough();
transStream.end(
`data: ${JSON.stringify({
Expand Down

0 comments on commit 0dd4fa0

Please sign in to comment.