doomiaichat 3.5.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 CHANGED
@@ -131,10 +131,13 @@ 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: finishreason, usage };
140
+ let output = { successed: true, requestid, text: replytext.join(''), finish_reason: 'stop', usage };
138
141
  if (attach)
139
142
  output = Object.assign({}, output, attach);
140
143
  this.emit('chatdone', output);
@@ -151,7 +154,9 @@ class OpenAIGpt extends gptbase_1.default {
151
154
  let output = { successed: true, requestid, text: replytext.join(''), finish_reason: finishreason, index: parsed.choices[0].index, usage };
152
155
  if (attach)
153
156
  output = Object.assign({}, output, attach);
154
- this.emit('chattext', output);
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "doomiaichat",
3
- "version": "3.5.0",
3
+ "version": "3.6.0",
4
4
  "description": "Doomisoft OpenAI",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
package/src/openai.ts CHANGED
@@ -118,12 +118,16 @@ 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: finishreason, usage };
130
+ let output = { successed: true, requestid, text: replytext.join(''), finish_reason: 'stop', usage };
127
131
  if (attach) output = Object.assign({},output, attach);
128
132
  this.emit('chatdone', output)
129
133
  return; // Stream finished
@@ -138,7 +142,8 @@ export default class OpenAIGpt extends GptBase {
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
144
  if (attach) output = Object.assign({},output, attach);
141
- this.emit('chattext', output )
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
  }