Skip to content

Commit

Permalink
解决首字符是空格问题
Browse files Browse the repository at this point in the history
  • Loading branch information
Vinlic committed May 7, 2024
1 parent f369671 commit a0a9d9b
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)
if (!result.choices || !result.choices[0] || !result.choices[0].delta || !result.choices[0].delta.content || result.choices[0].delta.content.trim() == '')
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)
if (!result.choices || !result.choices[0] || !result.choices[0].delta || !result.choices[0].delta.content || result.choices[0].delta.content.trim() == '')
return;
result.model = model;
transStream.write(`data: ${JSON.stringify({
Expand Down

0 comments on commit a0a9d9b

Please sign in to comment.