doomiaichat 3.1.0 → 3.2.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 +1 -1
- package/dist/openai.d.ts +1 -1
- package/dist/openai.js +8 -4
- package/package.json +1 -1
- package/src/gptbase.ts +1 -1
- package/src/openai.ts +10 -5
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):
|
|
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<
|
|
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,10 @@ 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
|
|
121
123
|
const response = yield this.aiApi.createChatCompletion({
|
|
122
124
|
model: (callChatOption === null || callChatOption === void 0 ? void 0 : callChatOption.model) || this.chatModel,
|
|
123
125
|
messages: message,
|
|
@@ -131,7 +133,7 @@ class OpenAIGpt extends gptbase_1.default {
|
|
|
131
133
|
for (const line of lines) {
|
|
132
134
|
const message = line.replace(/^data: /, '');
|
|
133
135
|
if (message === '[DONE]') {
|
|
134
|
-
this.emit('chatdone', { successed: true, text: replytext.join(''), finish_reason: finishreason, usage });
|
|
136
|
+
this.emit('chatdone', { successed: true, requestid, text: replytext.join(''), finish_reason: finishreason, usage });
|
|
135
137
|
return; // Stream finished
|
|
136
138
|
}
|
|
137
139
|
try {
|
|
@@ -142,16 +144,18 @@ class OpenAIGpt extends gptbase_1.default {
|
|
|
142
144
|
usage = parsed.usage;
|
|
143
145
|
let streamtext = parsed.choices[0].delta.content;
|
|
144
146
|
replytext.push(streamtext);
|
|
145
|
-
this.emit('chattext', { successed: true, text: streamtext, finish_reason: parsed.choices[0].finish_reason, index: parsed.choices[0].index, usage });
|
|
147
|
+
this.emit('chattext', { successed: true, requestid, text: streamtext, finish_reason: parsed.choices[0].finish_reason, index: parsed.choices[0].index, usage });
|
|
146
148
|
}
|
|
147
149
|
catch (error) {
|
|
148
|
-
this.emit('chaterror', { successed: false, error: 'JSON parse stream message', message });
|
|
150
|
+
this.emit('chaterror', { successed: false, requestid, error: 'JSON parse stream message', message });
|
|
149
151
|
}
|
|
150
152
|
}
|
|
151
153
|
});
|
|
154
|
+
return { successed: true, requestid };
|
|
152
155
|
}
|
|
153
156
|
catch (error) {
|
|
154
|
-
this.emit('error', { successed: false, error: 'call axios faied ' + error });
|
|
157
|
+
// this.emit('error', { successed: false, requestid, error: 'call axios faied ' + error });
|
|
158
|
+
return { successed: false, requestid };
|
|
155
159
|
}
|
|
156
160
|
});
|
|
157
161
|
}
|
package/package.json
CHANGED
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):
|
|
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<
|
|
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
|
+
|
|
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('error', { successed: false, requestid, error: 'call axios faied ' + error });
|
|
146
|
+
return { successed: false, requestid }
|
|
142
147
|
}
|
|
143
148
|
}
|
|
144
149
|
|