doomiaichat 3.4.0 → 3.6.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/openai.js +9 -4
- package/package.json +1 -1
- package/src/openai.ts +9 -4
package/dist/openai.js
CHANGED
|
@@ -131,12 +131,15 @@ class OpenAIGpt extends gptbase_1.default {
|
|
|
131
131
|
let replytext = [];
|
|
132
132
|
response.data.on('data', (data) => {
|
|
133
133
|
const lines = data.toString().split('\n').filter((line) => line.trim() !== '');
|
|
134
|
+
///已经返回了结束原因
|
|
135
|
+
if (finishreason)
|
|
136
|
+
return;
|
|
134
137
|
for (const line of lines) {
|
|
135
138
|
const message = line.replace(/^data: /, '');
|
|
136
139
|
if (message === '[DONE]') {
|
|
137
|
-
let output = { successed: true, requestid, text: replytext.join(''), finish_reason:
|
|
140
|
+
let output = { successed: true, requestid, text: replytext.join(''), finish_reason: 'stop', usage };
|
|
138
141
|
if (attach)
|
|
139
|
-
output = Object.assign(output, attach);
|
|
142
|
+
output = Object.assign({}, output, attach);
|
|
140
143
|
this.emit('chatdone', output);
|
|
141
144
|
return; // Stream finished
|
|
142
145
|
}
|
|
@@ -150,8 +153,10 @@ class OpenAIGpt extends gptbase_1.default {
|
|
|
150
153
|
replytext.push(streamtext);
|
|
151
154
|
let output = { successed: true, requestid, text: replytext.join(''), finish_reason: finishreason, index: parsed.choices[0].index, usage };
|
|
152
155
|
if (attach)
|
|
153
|
-
output = Object.assign(output, attach);
|
|
154
|
-
this.emit('chattext',
|
|
156
|
+
output = Object.assign({}, output, attach);
|
|
157
|
+
this.emit(finishreason ? 'chatdone' : 'chattext', output);
|
|
158
|
+
if (finishreason)
|
|
159
|
+
return;
|
|
155
160
|
}
|
|
156
161
|
catch (error) {
|
|
157
162
|
this.emit('chaterror', { successed: false, requestid, error: 'JSON parse stream message', message });
|
package/package.json
CHANGED
package/src/openai.ts
CHANGED
|
@@ -118,13 +118,17 @@ export default class OpenAIGpt extends GptBase {
|
|
|
118
118
|
max_tokens: Number(callChatOption?.maxtoken || this.maxtoken)
|
|
119
119
|
}, axiosOption);
|
|
120
120
|
let replytext:string[] = [];
|
|
121
|
+
|
|
121
122
|
response.data.on('data', (data:any) => {
|
|
122
123
|
const lines = data.toString().split('\n').filter((line:string) => line.trim() !== '');
|
|
124
|
+
///已经返回了结束原因
|
|
125
|
+
if (finishreason) return;
|
|
123
126
|
for (const line of lines) {
|
|
127
|
+
|
|
124
128
|
const message = line.replace(/^data: /, '');
|
|
125
129
|
if (message === '[DONE]') {
|
|
126
|
-
let output = { successed: true, requestid, text: replytext.join(''), finish_reason:
|
|
127
|
-
if (attach) output = Object.assign(output, attach);
|
|
130
|
+
let output = { successed: true, requestid, text: replytext.join(''), finish_reason: 'stop', usage };
|
|
131
|
+
if (attach) output = Object.assign({},output, attach);
|
|
128
132
|
this.emit('chatdone', output)
|
|
129
133
|
return; // Stream finished
|
|
130
134
|
}
|
|
@@ -137,8 +141,9 @@ export default class OpenAIGpt extends GptBase {
|
|
|
137
141
|
let streamtext = parsed.choices[0].delta.content;
|
|
138
142
|
replytext.push(streamtext);
|
|
139
143
|
let output = { successed: true, requestid, text: replytext.join(''), finish_reason: finishreason, index: parsed.choices[0].index, usage };
|
|
140
|
-
if (attach) output = Object.assign(output, attach);
|
|
141
|
-
this.emit('chattext',
|
|
144
|
+
if (attach) output = Object.assign({},output, attach);
|
|
145
|
+
this.emit(finishreason ? 'chatdone':'chattext', output )
|
|
146
|
+
if (finishreason) return;
|
|
142
147
|
} catch (error) {
|
|
143
148
|
this.emit('chaterror', { successed: false, requestid, error: 'JSON parse stream message', message });
|
|
144
149
|
}
|