Skip to content

Commit

Permalink
Update index.ts
Browse files Browse the repository at this point in the history
fix the common request err
  • Loading branch information
atorber committed May 9, 2023
1 parent 5d38348 commit 4ce56a0
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions model/forefront/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
}
Expand Down

0 comments on commit 4ce56a0

Please sign in to comment.