Skip to content

Commit

Permalink
Merge pull request #9 from wolfsilver/master
Browse files Browse the repository at this point in the history
fix: 过滤空字符串导致格式错误
  • Loading branch information
Vinlic authored Jun 20, 2024
2 parents eae48d3 + 19ce3d0 commit 81d2dff
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions src/api/controllers/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -411,7 +411,7 @@ async function receiveStream(model: string, stream: any): Promise<any> {
const result = _.attempt(() => JSON.parse(event.data));
if (_.isError(result))
throw new Error(`Stream response invalid: ${event.data}`);
if (!result.choices || !result.choices[0] || !result.choices[0].delta || !result.choices[0].delta.content || result.choices[0].delta.content == ' ')
if (!result.choices || !result.choices[0] || !result.choices[0].delta || !result.choices[0].delta.content)
return;
data.choices[0].message.content += result.choices[0].delta.content;
if (result.choices && result.choices[0] && result.choices[0].finish_reason === "stop")
Expand Down Expand Up @@ -465,7 +465,7 @@ function createTransStream(model: string, stream: any, endCallback?: Function) {
const result = _.attempt(() => JSON.parse(event.data));
if (_.isError(result))
throw new Error(`Stream response invalid: ${event.data}`);
if (!result.choices || !result.choices[0] || !result.choices[0].delta || !result.choices[0].delta.content || result.choices[0].delta.content == ' ')
if (!result.choices || !result.choices[0] || !result.choices[0].delta || !result.choices[0].delta.content)
return;
result.model = model;
transStream.write(`data: ${JSON.stringify({
Expand Down

0 comments on commit 81d2dff

Please sign in to comment.