Skip to content

Commit

Permalink
支持去除索引标签
Browse files Browse the repository at this point in the history
  • Loading branch information
Vinlic committed Apr 12, 2024
1 parent e36a028 commit 9f32215
Showing 1 changed file with 11 additions and 2 deletions.
13 changes: 11 additions & 2 deletions src/api/controllers/chat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,15 @@ function messagesPrepare(model: string, messages: any[], tempature: number) {
};
}

/**
* 去除内容的索引标签
*
* @param content 内容
*/
function removeIndexLabel(content: string) {
return content.replace(/\[\[\d+\]\]/g, '');
}

/**
* 检查请求结果
*
Expand Down Expand Up @@ -347,7 +356,7 @@ async function receiveStream(model: string, convId: string, stream: any) {
if (_.isError(result))
throw new Error(`Stream response invalid: ${event.data}`);
if (result.type == "append-text")
data.choices[0].message.content += result.text;
data.choices[0].message.content += removeIndexLabel(result.text);
} catch (err) {
logger.error(err);
reject(err);
Expand Down Expand Up @@ -431,7 +440,7 @@ function createTransStream(
choices: [
{
index: 0,
delta: { content: result.text },
delta: { content: removeIndexLabel(result.text) },
finish_reason: null,
},
],
Expand Down

0 comments on commit 9f32215

Please sign in to comment.