mirror of
https://github.com/LLM-Red-Team/kimi-free-api.git
synced 2024-11-01 20:29:19 +08:00
处理有几率遇到�输出的情况
This commit is contained in:
parent
980b506e94
commit
ae541f533e
@ -570,8 +570,9 @@ async function receiveStream(model: string, convId: string, stream: any) {
|
||||
if (_.isError(result))
|
||||
throw new Error(`Stream response invalid: ${event.data}`);
|
||||
// 处理消息
|
||||
if (result.event == 'cmpl') {
|
||||
data.choices[0].message.content += result.text;
|
||||
if (result.event == 'cmpl' && result.text) {
|
||||
const exceptCharIndex = result.text.indexOf("<22>");
|
||||
data.choices[0].message.content += result.text.substring(0, exceptCharIndex == -1 ? result.text.length : exceptCharIndex);
|
||||
}
|
||||
// 处理结束或错误
|
||||
else if (result.event == 'all_done' || result.event == 'error') {
|
||||
@ -632,12 +633,14 @@ function createTransStream(model: string, convId: string, stream: any, endCallba
|
||||
throw new Error(`Stream response invalid: ${event.data}`);
|
||||
// 处理消息
|
||||
if (result.event == 'cmpl') {
|
||||
const exceptCharIndex = result.text.indexOf("<22>");
|
||||
const chunk = result.text.substring(0, exceptCharIndex == -1 ? result.text.length : exceptCharIndex);
|
||||
const data = `data: ${JSON.stringify({
|
||||
id: convId,
|
||||
model,
|
||||
object: 'chat.completion.chunk',
|
||||
choices: [
|
||||
{ index: 0, delta: { content: (searchFlag ? '\n' : '') + result.text }, finish_reason: null }
|
||||
{ index: 0, delta: { content: (searchFlag ? '\n' : '') + chunk }, finish_reason: null }
|
||||
],
|
||||
created
|
||||
})}\n\n`;
|
||||
|
Loading…
Reference in New Issue
Block a user