Update index.ts

fix the common request err
このコミットが含まれているのは:
LuChao 2023-05-09 16:34:44 +08:00
コミット 4ce56a07e3
1個のファイルの変更10行の追加9行の削除

ファイルの表示

@ -73,17 +73,18 @@ export class Forefront extends Chat {
return new Promise(resolve => { return new Promise(resolve => {
res.text.pipe(es.split(/\r?\n\r?\n/)).pipe(es.map(async (chunk: any, cb: any) => { res.text.pipe(es.split(/\r?\n\r?\n/)).pipe(es.map(async (chunk: any, cb: any) => {
const str = chunk.replace('data: ', ''); const str = chunk.replace('data: ', '');
if (!str || str === '[DONE]') { if (!str || str === '[DONE]'.trim()) {
cb(null, ''); cb(null, '');
return; return;
} }
const data = parseJSON(str, {}) as ChatCompletionChunk; // const data = parseJSON(str, {}) as ChatCompletionChunk;
if (!data.choices) { // if (!data.choices) {
cb(null, ''); // cb(null, '');
return; // return;
} // }
const [{delta: {content}}] = data.choices; // const [{delta: {content}}] = data.choices;
cb(null, content); // cb(null, content);
cb(null, str);
})).on('data', (data) => { })).on('data', (data) => {
if (!data) { if (!data) {
return; 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 stream = response.data.pipe(es.split(/\r?\n\r?\n/)).pipe(es.map(async (chunk: any, cb: any) => {
const str = chunk.replace('data: ', ''); const str = chunk.replace('data: ', '');
if (!str || str === '[DONE]') { if (!str || str.trim() === '[DONE]') {
cb(null, ''); cb(null, '');
return; return;
} }