doomiaichat 3.1.0 → 3.3.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/gptbase.d.ts CHANGED
@@ -24,7 +24,7 @@ export default abstract class GptBase extends EventEmitter {
24
24
  * @param _paramOption
25
25
  * @param axiosOption
26
26
  */
27
- abstract chatRequestInStream(chatText: string | Array<any>, _paramOption: any, axiosOption: any): void;
27
+ abstract chatRequestInStream(chatText: string | Array<any>, _paramOption: any, axiosOption: any): any;
28
28
  /**
29
29
  * 点评问题回答的评价
30
30
  * @param question 问题题干
package/dist/openai.d.ts CHANGED
@@ -34,7 +34,7 @@ export default class OpenAIGpt extends GptBase {
34
34
  * @param _paramOption
35
35
  * @param axiosOption
36
36
  */
37
- chatRequestInStream(chatText: string | Array<any>, callChatOption: OpenAIApiParameters, axiosOption: any): Promise<void>;
37
+ chatRequestInStream(chatText: string | Array<any>, callChatOption: OpenAIApiParameters, axiosOption: any): Promise<any>;
38
38
  /**
39
39
  * 点评问题回答的评价
40
40
  * @param question
package/dist/openai.js CHANGED
@@ -116,8 +116,11 @@ class OpenAIGpt extends gptbase_1.default {
116
116
  let message = typeof (chatText) == 'string' ?
117
117
  [{ role: 'user', content: chatText }] : chatText;
118
118
  axiosOption = Object.assign({}, axiosOption || { timeout: 60000 }, { responseType: 'stream' });
119
+ let requestid = Math.ceil(Math.random() * (new Date().getTime() * Math.random()) / 1000);
119
120
  try {
120
121
  let finishreason = null, usage = null;
122
+ ///便于知道返回的requestid
123
+ console.log('model', (callChatOption === null || callChatOption === void 0 ? void 0 : callChatOption.model) || this.chatModel);
121
124
  const response = yield this.aiApi.createChatCompletion({
122
125
  model: (callChatOption === null || callChatOption === void 0 ? void 0 : callChatOption.model) || this.chatModel,
123
126
  messages: message,
@@ -131,7 +134,7 @@ class OpenAIGpt extends gptbase_1.default {
131
134
  for (const line of lines) {
132
135
  const message = line.replace(/^data: /, '');
133
136
  if (message === '[DONE]') {
134
- this.emit('chatdone', { successed: true, text: replytext.join(''), finish_reason: finishreason, usage });
137
+ this.emit('chatdone', { successed: true, requestid, text: replytext.join(''), finish_reason: finishreason, usage });
135
138
  return; // Stream finished
136
139
  }
137
140
  try {
@@ -142,16 +145,18 @@ class OpenAIGpt extends gptbase_1.default {
142
145
  usage = parsed.usage;
143
146
  let streamtext = parsed.choices[0].delta.content;
144
147
  replytext.push(streamtext);
145
- this.emit('chattext', { successed: true, text: streamtext, finish_reason: parsed.choices[0].finish_reason, index: parsed.choices[0].index, usage });
148
+ this.emit('chattext', { successed: true, requestid, text: streamtext, finish_reason: parsed.choices[0].finish_reason, index: parsed.choices[0].index, usage });
146
149
  }
147
150
  catch (error) {
148
- this.emit('chaterror', { successed: false, error: 'JSON parse stream message', message });
151
+ this.emit('chaterror', { successed: false, requestid, error: 'JSON parse stream message', message });
149
152
  }
150
153
  }
151
154
  });
155
+ return { successed: true, requestid };
152
156
  }
153
157
  catch (error) {
154
- this.emit('error', { successed: false, error: 'call axios faied ' + error });
158
+ this.emit('requesterror', { successed: false, requestid, error: 'call axios faied ' + error });
159
+ return { successed: false, requestid };
155
160
  }
156
161
  });
157
162
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "doomiaichat",
3
- "version": "3.1.0",
3
+ "version": "3.3.0",
4
4
  "description": "Doomisoft OpenAI",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
package/src/gptbase.ts CHANGED
@@ -26,7 +26,7 @@ export default abstract class GptBase extends EventEmitter {
26
26
  * @param _paramOption
27
27
  * @param axiosOption
28
28
  */
29
- abstract chatRequestInStream(chatText: string | Array<any>, _paramOption: any, axiosOption: any):void;
29
+ abstract chatRequestInStream(chatText: string | Array<any>, _paramOption: any, axiosOption: any):any;
30
30
  /**
31
31
  * 点评问题回答的评价
32
32
  * @param question 问题题干
package/src/openai.ts CHANGED
@@ -97,7 +97,7 @@ export default class OpenAIGpt extends GptBase {
97
97
  * @param _paramOption
98
98
  * @param axiosOption
99
99
  */
100
- async chatRequestInStream(chatText: string | Array<any>, callChatOption: OpenAIApiParameters, axiosOption: any):Promise<void>{
100
+ async chatRequestInStream(chatText: string | Array<any>, callChatOption: OpenAIApiParameters, axiosOption: any):Promise<any>{
101
101
  if (!chatText) this.emit('chaterror', { successed: false, error:'no text in chat'});
102
102
  if (!this.aiApi) {
103
103
  this.aiApi = this.createOpenAI(this.apiKey);
@@ -105,8 +105,11 @@ export default class OpenAIGpt extends GptBase {
105
105
  let message: Array<ChatCompletionRequestMessage> = typeof (chatText) == 'string' ?
106
106
  [{ role: 'user', content: chatText }] : chatText;
107
107
  axiosOption = Object.assign({}, axiosOption || { timeout: 60000 }, { responseType: 'stream' })
108
+ let requestid = Math.ceil(Math.random() * (new Date().getTime() * Math.random()) / 1000);
108
109
  try {
109
110
  let finishreason:any = null,usage:any = null;
111
+ ///便于知道返回的requestid
112
+ console.log('model', callChatOption?.model || this.chatModel,)
110
113
  const response: any = await this.aiApi.createChatCompletion({
111
114
  model: callChatOption?.model || this.chatModel,
112
115
  messages: message,
@@ -120,7 +123,7 @@ export default class OpenAIGpt extends GptBase {
120
123
  for (const line of lines) {
121
124
  const message = line.replace(/^data: /, '');
122
125
  if (message === '[DONE]') {
123
- this.emit('chatdone', { successed: true, text: replytext.join(''), finish_reason: finishreason, usage })
126
+ this.emit('chatdone', { successed: true, requestid,text: replytext.join(''), finish_reason: finishreason, usage })
124
127
  return; // Stream finished
125
128
  }
126
129
  try {
@@ -131,14 +134,16 @@ export default class OpenAIGpt extends GptBase {
131
134
  usage = parsed.usage;
132
135
  let streamtext = parsed.choices[0].delta.content;
133
136
  replytext.push(streamtext)
134
- this.emit('chattext', { successed: true, text: streamtext, finish_reason: parsed.choices[0].finish_reason, index: parsed.choices[0].index, usage})
137
+ this.emit('chattext', { successed: true, requestid, text: streamtext, finish_reason: parsed.choices[0].finish_reason, index: parsed.choices[0].index, usage})
135
138
  } catch (error) {
136
- this.emit('chaterror', { successed: false, error: 'JSON parse stream message', message });
139
+ this.emit('chaterror', { successed: false, requestid, error: 'JSON parse stream message', message });
137
140
  }
138
141
  }
139
142
  });
143
+ return { successed: true, requestid }
140
144
  } catch (error) {
141
- this.emit('error', { successed: false, error: 'call axios faied ' + error });
145
+ this.emit('requesterror', { successed: false, requestid, error: 'call axios faied ' + error });
146
+ return { successed: false, requestid }
142
147
  }
143
148
  }
144
149