doomiaichat 7.1.13 → 7.1.14
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/corzbot.js +6 -2
- package/package.json +1 -1
- package/src/corzbot.ts +23 -19
package/dist/corzbot.js
CHANGED
|
@@ -31,6 +31,7 @@ const DeepThinkingAction = {
|
|
|
31
31
|
thinking: { start: '<xiaolu-think>', end: '</xiaolu-think>', tag: 'xiaolu-think' },
|
|
32
32
|
reasoning: { start: '<xiaolu-reason>', end: '</xiaolu-reason>', tag: 'xiaolu-reason' },
|
|
33
33
|
card: { start: '<xiaolu-card>', end: '</xiaolu-card>', tag: 'xiaolu-card' },
|
|
34
|
+
preresponse: { start: '<xiaolu-preresponse>', end: '</xiaolu-preresponse>', tag: 'xiaolu-preresponse' },
|
|
34
35
|
};
|
|
35
36
|
// 定义深度思考的状态
|
|
36
37
|
var DeepThinkingStatus;
|
|
@@ -256,7 +257,8 @@ class CorzBot extends gptbase_1.default {
|
|
|
256
257
|
// (status===DeepThinkingStatus.ReasonOutput ? content.indexOf("{\"reasoning_content") : content.indexOf("{\"card_resource")) ;
|
|
257
258
|
const xmlTagLocation = [content.indexOf(DeepThinkingAction.thinking.start),
|
|
258
259
|
content.indexOf(DeepThinkingAction.reasoning.start),
|
|
259
|
-
content.indexOf(DeepThinkingAction.card.start)
|
|
260
|
+
content.indexOf(DeepThinkingAction.card.start),
|
|
261
|
+
content.indexOf(DeepThinkingAction.preresponse.start)];
|
|
260
262
|
let minLocation = 10000, minIndex = -1;
|
|
261
263
|
// 找到最小的并且大于0 的位置的下标
|
|
262
264
|
xmlTagLocation.forEach((x, index) => {
|
|
@@ -269,7 +271,7 @@ class CorzBot extends gptbase_1.default {
|
|
|
269
271
|
const thinkingStartIndex = minIndex >= 0 ? minLocation : -1; //tagLocation.length > 0 ? Math.min(...tagLocation) : -1;
|
|
270
272
|
if (thinkingStartIndex < 0)
|
|
271
273
|
return { content, status: DeepThinkingStatus.ThinkingOver };
|
|
272
|
-
const currentAction = [DeepThinkingAction.thinking, DeepThinkingAction.reasoning, DeepThinkingAction.card][minIndex];
|
|
274
|
+
const currentAction = [DeepThinkingAction.thinking, DeepThinkingAction.reasoning, DeepThinkingAction.card, DeepThinkingAction.preresponse][minIndex];
|
|
273
275
|
const currentActionIsOver = content.indexOf(currentAction.end, thinkingStartIndex);
|
|
274
276
|
const thinkingEndIndex = currentActionIsOver >= 0 ? currentActionIsOver : content.indexOf('</', thinkingStartIndex);
|
|
275
277
|
const thinkingContent = this.extractXmlContent(content.substring(thinkingStartIndex, thinkingEndIndex >= 0 ? thinkingEndIndex : undefined) + currentAction.end, currentAction.tag); //"\"}";
|
|
@@ -327,6 +329,8 @@ class CorzBot extends gptbase_1.default {
|
|
|
327
329
|
if (part.event === api_1.ChatEventType.CONVERSATION_MESSAGE_DELTA ||
|
|
328
330
|
part.event === api_1.WorkflowEventType.MESSAGE) {
|
|
329
331
|
let { conversation_id, content_type, type = 'answer', role = 'assistant', content, reasoning_content: reasoning } = part.data;
|
|
332
|
+
if (content === 'Default')
|
|
333
|
+
continue;
|
|
330
334
|
if (!content && reasoning) {
|
|
331
335
|
this.emit('chatthinking', { text: reasoning, completed: false, action: 'deep-thinking' });
|
|
332
336
|
continue;
|
package/package.json
CHANGED
package/src/corzbot.ts
CHANGED
|
@@ -32,6 +32,7 @@ const DeepThinkingAction: any = {
|
|
|
32
32
|
thinking: { start: '<xiaolu-think>', end: '</xiaolu-think>', tag: 'xiaolu-think' },
|
|
33
33
|
reasoning: { start: '<xiaolu-reason>', end: '</xiaolu-reason>', tag: 'xiaolu-reason' },
|
|
34
34
|
card: { start: '<xiaolu-card>', end: '</xiaolu-card>', tag: 'xiaolu-card' },
|
|
35
|
+
preresponse: { start: '<xiaolu-preresponse>', end: '</xiaolu-preresponse>', tag: 'xiaolu-preresponse' },
|
|
35
36
|
}
|
|
36
37
|
// 定义深度思考的状态
|
|
37
38
|
enum DeepThinkingStatus {
|
|
@@ -56,8 +57,8 @@ export default class CorzBot extends GptBase {
|
|
|
56
57
|
constructor(private authorizationProvider: CorzAuthorization, private setting: any = {}) {
|
|
57
58
|
super();
|
|
58
59
|
////初始化扣子客户端
|
|
59
|
-
|
|
60
|
-
if (this.setting.workflowid)
|
|
60
|
+
|
|
61
|
+
if (this.setting.workflowid)
|
|
61
62
|
this.workflowid = this.setting.workflowid;
|
|
62
63
|
else if (this.setting.talkflowid)
|
|
63
64
|
this.talkflowid = this.setting.talkflowid;
|
|
@@ -126,18 +127,18 @@ export default class CorzBot extends GptBase {
|
|
|
126
127
|
additional_messages: message,
|
|
127
128
|
user_id: callChatOption.userid || callChatOption.cozeUserID,
|
|
128
129
|
conversation_id,
|
|
129
|
-
parameters: Object.assign({ request_src:1 }, callChatOption.parameters || {}),
|
|
130
|
+
parameters: Object.assign({ request_src: 1 }, callChatOption.parameters || {}),
|
|
130
131
|
}
|
|
131
132
|
req.custom_variables = Object.assign({}, this.setting.customVariables || {}, callChatOption.customVariables || {});
|
|
132
133
|
return req as T;
|
|
133
134
|
}
|
|
134
|
-
if (this.workflowid){
|
|
135
|
+
if (this.workflowid) {
|
|
135
136
|
const worflowreq: RunWorkflowReq = {
|
|
136
137
|
ext: callChatOption.ext,
|
|
137
138
|
workflow_id: this.workflowid,//callChatOption.workflowid,
|
|
138
139
|
is_async: false,
|
|
139
140
|
// parameters: Object.assign({ input: message[0]?.content }, this.setting.customVariables || {}, callChatOption.customVariables || {}),
|
|
140
|
-
parameters: Object.assign({ request_src
|
|
141
|
+
parameters: Object.assign({ request_src: 1 }, callChatOption.parameters || {}, { input: message[0]?.content })
|
|
141
142
|
}
|
|
142
143
|
return worflowreq as T;
|
|
143
144
|
}
|
|
@@ -146,7 +147,7 @@ export default class CorzBot extends GptBase {
|
|
|
146
147
|
ext: callChatOption.ext,
|
|
147
148
|
workflow_id: this.talkflowid!,//callChatOption.workflowid,
|
|
148
149
|
conversation_id,
|
|
149
|
-
parameters: Object.assign({request_src:1},callChatOption.parameters || {}) //Object.assign({}, this.setting.customVariables || {}, callChatOption.customVariables || {}),
|
|
150
|
+
parameters: Object.assign({ request_src: 1 }, callChatOption.parameters || {}) //Object.assign({}, this.setting.customVariables || {}, callChatOption.customVariables || {}),
|
|
150
151
|
//parameters: { input: message[0]?.content }
|
|
151
152
|
}
|
|
152
153
|
return worflowreq as T;
|
|
@@ -188,7 +189,7 @@ export default class CorzBot extends GptBase {
|
|
|
188
189
|
////如果参数中用的是Workflow,则调用对话流来输出结果
|
|
189
190
|
////否则用智能体的对话来输出结果
|
|
190
191
|
const params = await this.getRequestStream(client, message, callChatOption);
|
|
191
|
-
const response = this.botid ? await client.chat.create(params as CreateChatReq) :await client.workflows.runs.create(params as RunWorkflowReq);
|
|
192
|
+
const response = this.botid ? await client.chat.create(params as CreateChatReq) : await client.workflows.runs.create(params as RunWorkflowReq);
|
|
192
193
|
if (this.workflowid && (response as RunWorkflowData).msg === 'Success') {
|
|
193
194
|
const resp = (response as RunWorkflowData).data;
|
|
194
195
|
return { successed: true, message: [{ role: 'assistant', type: 'answer', content: resp }] };
|
|
@@ -237,7 +238,8 @@ export default class CorzBot extends GptBase {
|
|
|
237
238
|
// (status===DeepThinkingStatus.ReasonOutput ? content.indexOf("{\"reasoning_content") : content.indexOf("{\"card_resource")) ;
|
|
238
239
|
const xmlTagLocation = [content.indexOf(DeepThinkingAction.thinking.start),
|
|
239
240
|
content.indexOf(DeepThinkingAction.reasoning.start),
|
|
240
|
-
content.indexOf(DeepThinkingAction.card.start)
|
|
241
|
+
content.indexOf(DeepThinkingAction.card.start),
|
|
242
|
+
content.indexOf(DeepThinkingAction.preresponse.start)];
|
|
241
243
|
let minLocation = 10000, minIndex = -1;
|
|
242
244
|
// 找到最小的并且大于0 的位置的下标
|
|
243
245
|
xmlTagLocation.forEach((x, index) => {
|
|
@@ -249,18 +251,19 @@ export default class CorzBot extends GptBase {
|
|
|
249
251
|
// const tagLocation = xmlTagLocation.filter(x => x >= 0);
|
|
250
252
|
const thinkingStartIndex = minIndex >= 0 ? minLocation : -1; //tagLocation.length > 0 ? Math.min(...tagLocation) : -1;
|
|
251
253
|
if (thinkingStartIndex < 0) return { content, status: DeepThinkingStatus.ThinkingOver };
|
|
252
|
-
const currentAction = [DeepThinkingAction.thinking, DeepThinkingAction.reasoning, DeepThinkingAction.card][minIndex];
|
|
254
|
+
const currentAction = [DeepThinkingAction.thinking, DeepThinkingAction.reasoning, DeepThinkingAction.card, DeepThinkingAction.preresponse][minIndex];
|
|
253
255
|
const currentActionIsOver = content.indexOf(currentAction.end, thinkingStartIndex);
|
|
254
|
-
const thinkingEndIndex = currentActionIsOver >= 0 ? currentActionIsOver: content.indexOf('</', thinkingStartIndex);
|
|
256
|
+
const thinkingEndIndex = currentActionIsOver >= 0 ? currentActionIsOver : content.indexOf('</', thinkingStartIndex);
|
|
255
257
|
const thinkingContent = this.extractXmlContent(content.substring(thinkingStartIndex, thinkingEndIndex >= 0 ? thinkingEndIndex : undefined) + currentAction.end, currentAction.tag); //"\"}";
|
|
256
258
|
if (currentActionIsOver >= 0) content = content.substring(currentActionIsOver + currentAction.end.length);
|
|
257
|
-
return {
|
|
259
|
+
return {
|
|
258
260
|
thinking: {
|
|
259
261
|
action: currentAction,
|
|
260
262
|
text: thinkingContent,//Object.values(thinkingObject)[0]
|
|
261
263
|
completed: currentActionIsOver >= 0
|
|
262
|
-
}, content
|
|
263
|
-
|
|
264
|
+
}, content
|
|
265
|
+
};
|
|
266
|
+
|
|
264
267
|
}
|
|
265
268
|
/**
|
|
266
269
|
* 流式传输聊天请求
|
|
@@ -285,9 +288,9 @@ export default class CorzBot extends GptBase {
|
|
|
285
288
|
////否则用智能体的对话来输出结果
|
|
286
289
|
let requestid = Math.ceil(Math.random() * (new Date().getTime() * Math.random()) / 1000), index = 0;
|
|
287
290
|
const params = await this.getRequestStream(client, message, callChatOption);
|
|
288
|
-
const stream = this.botid ? client.chat.stream(params as StreamChatReq) :
|
|
289
|
-
(this.workflowid ? client.workflows.runs.stream(params as RunWorkflowReq) :
|
|
290
|
-
|
|
291
|
+
const stream = this.botid ? client.chat.stream(params as StreamChatReq) :
|
|
292
|
+
(this.workflowid ? client.workflows.runs.stream(params as RunWorkflowReq) :
|
|
293
|
+
client.workflows.chat.stream(params as ChatWorkflowReq));
|
|
291
294
|
let deltaindex = 0, fullanswer: string[] = [], followup: string[] = [], cardData: CardType[] = [];
|
|
292
295
|
let deepThinking = '', thinkingStatus = DeepThinkingStatus.None, cardResource = ''; // 是否在深度思考中
|
|
293
296
|
for await (const part of stream) {
|
|
@@ -296,7 +299,8 @@ export default class CorzBot extends GptBase {
|
|
|
296
299
|
part.event === WorkflowEventType.MESSAGE
|
|
297
300
|
) {
|
|
298
301
|
let { conversation_id, content_type, type = 'answer', role = 'assistant', content, reasoning_content: reasoning } = part.data as any;
|
|
299
|
-
if (
|
|
302
|
+
if (content === 'Default') continue;
|
|
303
|
+
if (!content && reasoning) {
|
|
300
304
|
this.emit('chatthinking', { text: reasoning, completed: false, action: 'deep-thinking' });
|
|
301
305
|
continue;
|
|
302
306
|
}
|
|
@@ -347,8 +351,8 @@ export default class CorzBot extends GptBase {
|
|
|
347
351
|
if (part.event === ChatEventType.CONVERSATION_CHAT_COMPLETED ||
|
|
348
352
|
part.event === WorkflowEventType.DONE
|
|
349
353
|
) {
|
|
350
|
-
const { conversation_id, content } =(
|
|
351
|
-
let output = { successed: true, cards: cardData.length ? cardData : null, followup, type: 'answer', content_type: 'text', role: RoleType.Assistant, requestid, segment: null, text: content??fullanswer.join(''), index: index++, session_id: conversation_id };
|
|
354
|
+
const { conversation_id, content } = (part.data) ?? {} as any;
|
|
355
|
+
let output = { successed: true, cards: cardData.length ? cardData : null, followup, type: 'answer', content_type: 'text', role: RoleType.Assistant, requestid, segment: null, text: content ?? fullanswer.join(''), index: index++, session_id: conversation_id };
|
|
352
356
|
if (attach) output = Object.assign({}, output, attach);
|
|
353
357
|
this.emit('chatdone', output)
|
|
354
358
|
}
|