doomiaichat 7.0.3 → 7.0.4
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/aimp.js +7 -4
- package/package.json +1 -1
- package/src/aimp.ts +6 -4
package/dist/aimp.js
CHANGED
|
@@ -59,10 +59,11 @@ class AIMiddlePlatform extends gptbase_1.default {
|
|
|
59
59
|
}, method: 'post', url: `${this.agent.endpoint}/api/v1/agents/${this.agent.agentid}/completions`, data: {
|
|
60
60
|
question,
|
|
61
61
|
session_id: callChatOption.session_id,
|
|
62
|
+
optional: callChatOption.optional,
|
|
62
63
|
stream: false
|
|
63
64
|
} }, axiosOption);
|
|
64
65
|
const response = yield (0, declare_1.request)(opts);
|
|
65
|
-
if (!response.successed)
|
|
66
|
+
if (!response.successed || response.data.code)
|
|
66
67
|
return { successed: false, error: 'failed' };
|
|
67
68
|
const { answer: message, session_id } = response.data.data;
|
|
68
69
|
// this.emit('chatdone', { successed: true, segment: message, text: message, finish_reason: 'stop', index: 0, session_id })
|
|
@@ -99,7 +100,7 @@ class AIMiddlePlatform extends gptbase_1.default {
|
|
|
99
100
|
}, responseType: 'stream' }, axiosOption);
|
|
100
101
|
const response = yield (0, axios_1.default)(opts);
|
|
101
102
|
const readableStream = stream_1.Readable.from(response.data);
|
|
102
|
-
let index = 0, session_id, fullanswer = '', errorKeeped = [];
|
|
103
|
+
let index = 0, session_id, fullanswer = '', errorKeeped = [], chunks = [];
|
|
103
104
|
try {
|
|
104
105
|
for (var _e = true, readableStream_1 = __asyncValues(readableStream), readableStream_1_1; readableStream_1_1 = yield readableStream_1.next(), _a = readableStream_1_1.done, !_a;) {
|
|
105
106
|
_c = readableStream_1_1.value;
|
|
@@ -122,15 +123,17 @@ class AIMiddlePlatform extends gptbase_1.default {
|
|
|
122
123
|
continue;
|
|
123
124
|
}
|
|
124
125
|
errorKeeped = [];
|
|
125
|
-
const { answer, running_status } = answerData.data;
|
|
126
|
+
const { answer, running_status, reference } = answerData.data;
|
|
126
127
|
if (running_status === true)
|
|
127
128
|
continue;
|
|
128
129
|
const segment = answer ? answer.replace(fullanswer, '') : '';
|
|
129
130
|
fullanswer = answer !== null && answer !== void 0 ? answer : fullanswer;
|
|
130
131
|
if (!session_id)
|
|
131
132
|
session_id = answerData.data.session_id;
|
|
133
|
+
if (reference && reference.chunks && reference.chunks.length)
|
|
134
|
+
chunks = chunks.concat(reference.chunks);
|
|
132
135
|
const finished = answerData.data === true;
|
|
133
|
-
let output = { successed: true, requestid, segment: segment, text: fullanswer, finish_reason: finished ? 'stop' : null, index: index++, session_id };
|
|
136
|
+
let output = { successed: true, requestid, segment: segment, chunks, text: fullanswer, finish_reason: finished ? 'stop' : null, index: index++, session_id };
|
|
134
137
|
if (attach)
|
|
135
138
|
output = Object.assign({}, output, attach);
|
|
136
139
|
this.emit(finished ? 'chatdone' : 'chattext', output);
|
package/package.json
CHANGED
package/src/aimp.ts
CHANGED
|
@@ -44,12 +44,13 @@ export default class AIMiddlePlatform extends GptBase {
|
|
|
44
44
|
data: {
|
|
45
45
|
question,
|
|
46
46
|
session_id: callChatOption.session_id,
|
|
47
|
+
optional: callChatOption.optional,
|
|
47
48
|
stream: false
|
|
48
49
|
},
|
|
49
50
|
...axiosOption
|
|
50
51
|
}
|
|
51
52
|
const response = await request(opts);
|
|
52
|
-
if (!response.successed) return { successed: false, error: 'failed' };
|
|
53
|
+
if (!response.successed || response.data.code) return { successed: false, error: 'failed' };
|
|
53
54
|
const {answer:message,session_id} = response.data.data;
|
|
54
55
|
// this.emit('chatdone', { successed: true, segment: message, text: message, finish_reason: 'stop', index: 0, session_id })
|
|
55
56
|
return { successed: true, message:[{message:{content:message}}],session_id };
|
|
@@ -87,7 +88,7 @@ export default class AIMiddlePlatform extends GptBase {
|
|
|
87
88
|
}
|
|
88
89
|
const response = await axios(opts);
|
|
89
90
|
const readableStream = Readable.from(response.data);
|
|
90
|
-
let index = 0, session_id,fullanswer='',errorKeeped=[];
|
|
91
|
+
let index = 0, session_id,fullanswer='',errorKeeped=[],chunks:any=[];
|
|
91
92
|
for await (const chunk of readableStream) {
|
|
92
93
|
///可能接收到的数据不完整,导致JSON.parse失败
|
|
93
94
|
let answerData = null, jsonStr = '';
|
|
@@ -103,13 +104,14 @@ export default class AIMiddlePlatform extends GptBase {
|
|
|
103
104
|
continue;
|
|
104
105
|
}
|
|
105
106
|
errorKeeped = [];
|
|
106
|
-
const { answer, running_status } = answerData.data;
|
|
107
|
+
const { answer, running_status, reference } = answerData.data;
|
|
107
108
|
if (running_status === true) continue;
|
|
108
109
|
const segment = answer ? answer.replace(fullanswer,''):''
|
|
109
110
|
fullanswer = answer ?? fullanswer;
|
|
110
111
|
if (!session_id) session_id = answerData.data.session_id;
|
|
112
|
+
if (reference && reference.chunks && reference.chunks.length) chunks = chunks.concat(reference.chunks)
|
|
111
113
|
const finished = answerData.data === true;
|
|
112
|
-
let output = { successed: true, requestid, segment: segment, text: fullanswer, finish_reason: finished ? 'stop' : null, index: index++, session_id };
|
|
114
|
+
let output = { successed: true, requestid, segment: segment, chunks, text: fullanswer, finish_reason: finished ? 'stop' : null, index: index++, session_id };
|
|
113
115
|
if (attach) output = Object.assign({}, output, attach);
|
|
114
116
|
this.emit(finished ? 'chatdone' : 'chattext', output)
|
|
115
117
|
}
|