From 4ce56a07e399a8379b45d498ca1d69d4ae57aec4 Mon Sep 17 00:00:00 2001 From: LuChao Date: Tue, 9 May 2023 16:34:44 +0800 Subject: [PATCH] Update index.ts fix the common request err --- model/forefront/index.ts | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/model/forefront/index.ts b/model/forefront/index.ts index 238c921..33790b1 100644 --- a/model/forefront/index.ts +++ b/model/forefront/index.ts @@ -73,17 +73,18 @@ export class Forefront extends Chat { return new Promise(resolve => { res.text.pipe(es.split(/\r?\n\r?\n/)).pipe(es.map(async (chunk: any, cb: any) => { const str = chunk.replace('data: ', ''); - if (!str || str === '[DONE]') { + if (!str || str === '[DONE]'.trim()) { cb(null, ''); return; } - const data = parseJSON(str, {}) as ChatCompletionChunk; - if (!data.choices) { - cb(null, ''); - return; - } - const [{delta: {content}}] = data.choices; - cb(null, content); + // const data = parseJSON(str, {}) as ChatCompletionChunk; + // if (!data.choices) { + // cb(null, ''); + // return; + // } + // const [{delta: {content}}] = data.choices; + // cb(null, content); + cb(null, str); })).on('data', (data) => { if (!data) { return; @@ -132,7 +133,7 @@ export class Forefront extends Chat { ); const stream = response.data.pipe(es.split(/\r?\n\r?\n/)).pipe(es.map(async (chunk: any, cb: any) => { const str = chunk.replace('data: ', ''); - if (!str || str === '[DONE]') { + if (!str || str.trim() === '[DONE]') { cb(null, ''); return; }