doomiaichat 7.0.2 → 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 +10 -9
- package/package.json +1 -1
- package/src/aimp.ts +9 -10
package/dist/aimp.js
CHANGED
|
@@ -48,7 +48,7 @@ class AIMiddlePlatform extends gptbase_1.default {
|
|
|
48
48
|
var _a;
|
|
49
49
|
return __awaiter(this, void 0, void 0, function* () {
|
|
50
50
|
if (!chatText) {
|
|
51
|
-
this.emit('chaterror', { successed: false, error: 'no text in chat' });
|
|
51
|
+
// this.emit('chaterror', { successed: false, error: 'no text in chat' });
|
|
52
52
|
return { successed: false, error: 'no text in chat' };
|
|
53
53
|
}
|
|
54
54
|
const question = typeof chatText === 'object' ? (_a = chatText.text) !== null && _a !== void 0 ? _a : chatText.content : chatText;
|
|
@@ -59,16 +59,15 @@ 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
|
-
console.log('Question===>', question);
|
|
65
65
|
const response = yield (0, declare_1.request)(opts);
|
|
66
|
-
if (!response.successed)
|
|
66
|
+
if (!response.successed || response.data.code)
|
|
67
67
|
return { successed: false, error: 'failed' };
|
|
68
|
-
console.log('reponse===>', response.data);
|
|
69
68
|
const { answer: message, session_id } = response.data.data;
|
|
70
|
-
this.emit('chatdone', { successed: true, segment: message, text: message, finish_reason: 'stop', index: 0, session_id })
|
|
71
|
-
return { successed: true, message, session_id };
|
|
69
|
+
// this.emit('chatdone', { successed: true, segment: message, text: message, finish_reason: 'stop', index: 0, session_id })
|
|
70
|
+
return { successed: true, message: [{ message: { content: message } }], session_id };
|
|
72
71
|
});
|
|
73
72
|
}
|
|
74
73
|
/**
|
|
@@ -101,7 +100,7 @@ class AIMiddlePlatform extends gptbase_1.default {
|
|
|
101
100
|
}, responseType: 'stream' }, axiosOption);
|
|
102
101
|
const response = yield (0, axios_1.default)(opts);
|
|
103
102
|
const readableStream = stream_1.Readable.from(response.data);
|
|
104
|
-
let index = 0, session_id, fullanswer = '', errorKeeped = [];
|
|
103
|
+
let index = 0, session_id, fullanswer = '', errorKeeped = [], chunks = [];
|
|
105
104
|
try {
|
|
106
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;) {
|
|
107
106
|
_c = readableStream_1_1.value;
|
|
@@ -124,15 +123,17 @@ class AIMiddlePlatform extends gptbase_1.default {
|
|
|
124
123
|
continue;
|
|
125
124
|
}
|
|
126
125
|
errorKeeped = [];
|
|
127
|
-
const { answer, running_status } = answerData.data;
|
|
126
|
+
const { answer, running_status, reference } = answerData.data;
|
|
128
127
|
if (running_status === true)
|
|
129
128
|
continue;
|
|
130
129
|
const segment = answer ? answer.replace(fullanswer, '') : '';
|
|
131
130
|
fullanswer = answer !== null && answer !== void 0 ? answer : fullanswer;
|
|
132
131
|
if (!session_id)
|
|
133
132
|
session_id = answerData.data.session_id;
|
|
133
|
+
if (reference && reference.chunks && reference.chunks.length)
|
|
134
|
+
chunks = chunks.concat(reference.chunks);
|
|
134
135
|
const finished = answerData.data === true;
|
|
135
|
-
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 };
|
|
136
137
|
if (attach)
|
|
137
138
|
output = Object.assign({}, output, attach);
|
|
138
139
|
this.emit(finished ? 'chatdone' : 'chattext', output);
|
package/package.json
CHANGED
package/src/aimp.ts
CHANGED
|
@@ -29,7 +29,7 @@ export default class AIMiddlePlatform extends GptBase {
|
|
|
29
29
|
*/
|
|
30
30
|
public async chatRequest(chatText: string | any, callChatOption: any, axiosOption: any = {}): Promise<any> {
|
|
31
31
|
if (!chatText) {
|
|
32
|
-
this.emit('chaterror', { successed: false, error: 'no text in chat' });
|
|
32
|
+
// this.emit('chaterror', { successed: false, error: 'no text in chat' });
|
|
33
33
|
return { successed: false, error: 'no text in chat' };
|
|
34
34
|
}
|
|
35
35
|
const question = typeof chatText === 'object' ? chatText.text ?? chatText.content : chatText;
|
|
@@ -44,18 +44,16 @@ 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
|
-
console.log('Question===>', question)
|
|
52
52
|
const response = await request(opts);
|
|
53
|
-
|
|
54
|
-
if (!response.successed) return { successed: false, error: 'failed' };
|
|
55
|
-
console.log('reponse===>', response.data)
|
|
53
|
+
if (!response.successed || response.data.code) return { successed: false, error: 'failed' };
|
|
56
54
|
const {answer:message,session_id} = response.data.data;
|
|
57
|
-
this.emit('chatdone', { successed: true, segment: message, text: message, finish_reason: 'stop', index: 0, session_id })
|
|
58
|
-
return { successed: true, message,session_id };
|
|
55
|
+
// this.emit('chatdone', { successed: true, segment: message, text: message, finish_reason: 'stop', index: 0, session_id })
|
|
56
|
+
return { successed: true, message:[{message:{content:message}}],session_id };
|
|
59
57
|
}
|
|
60
58
|
/**
|
|
61
59
|
* 流式传输聊天请求
|
|
@@ -90,7 +88,7 @@ export default class AIMiddlePlatform extends GptBase {
|
|
|
90
88
|
}
|
|
91
89
|
const response = await axios(opts);
|
|
92
90
|
const readableStream = Readable.from(response.data);
|
|
93
|
-
let index = 0, session_id,fullanswer='',errorKeeped=[];
|
|
91
|
+
let index = 0, session_id,fullanswer='',errorKeeped=[],chunks:any=[];
|
|
94
92
|
for await (const chunk of readableStream) {
|
|
95
93
|
///可能接收到的数据不完整,导致JSON.parse失败
|
|
96
94
|
let answerData = null, jsonStr = '';
|
|
@@ -106,13 +104,14 @@ export default class AIMiddlePlatform extends GptBase {
|
|
|
106
104
|
continue;
|
|
107
105
|
}
|
|
108
106
|
errorKeeped = [];
|
|
109
|
-
const { answer, running_status } = answerData.data;
|
|
107
|
+
const { answer, running_status, reference } = answerData.data;
|
|
110
108
|
if (running_status === true) continue;
|
|
111
109
|
const segment = answer ? answer.replace(fullanswer,''):''
|
|
112
110
|
fullanswer = answer ?? fullanswer;
|
|
113
111
|
if (!session_id) session_id = answerData.data.session_id;
|
|
112
|
+
if (reference && reference.chunks && reference.chunks.length) chunks = chunks.concat(reference.chunks)
|
|
114
113
|
const finished = answerData.data === true;
|
|
115
|
-
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 };
|
|
116
115
|
if (attach) output = Object.assign({}, output, attach);
|
|
117
116
|
this.emit(finished ? 'chatdone' : 'chattext', output)
|
|
118
117
|
}
|