doomiaichat 7.1.13 → 7.1.15

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 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); //"\"}";
@@ -315,7 +317,7 @@ class CorzBot extends gptbase_1.default {
315
317
  (this.workflowid ? client.workflows.runs.stream(params) :
316
318
  client.workflows.chat.stream(params));
317
319
  let deltaindex = 0, fullanswer = [], followup = [], cardData = [];
318
- let deepThinking = '', thinkingStatus = DeepThinkingStatus.None, cardResource = ''; // 是否在深度思考中
320
+ let deepThinking = '', thinkingStatus = DeepThinkingStatus.None, cardResource = '', preresponseText = ''; // 是否在深度思考中
319
321
  try {
320
322
  for (var _g = true, stream_1 = __asyncValues(stream), stream_1_1; stream_1_1 = yield stream_1.next(), _a = stream_1_1.done, !_a;) {
321
323
  _c = stream_1_1.value;
@@ -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;
@@ -357,6 +361,16 @@ class CorzBot extends gptbase_1.default {
357
361
  this.emit('chatcard', cardData);
358
362
  }
359
363
  }
364
+ else if (thinking.action === DeepThinkingAction.preresponse) {
365
+ /// 当正文一样输出
366
+ const spiltPreresponse = result.thinking.text.slice(preresponseText.length);
367
+ preresponseText = result.thinking.text;
368
+ fullanswer.push(spiltPreresponse); // = [result.thinking.text];// .push(result.thinking.text);
369
+ let output = { successed: true, type, content_type, role, requestid, segment: spiltPreresponse, text: fullanswer.join(''), index: index++, session_id: conversation_id };
370
+ if (attach)
371
+ output = Object.assign({}, output, attach);
372
+ this.emit('chattext', output);
373
+ }
360
374
  else {
361
375
  this.emit('chatthinking', { text: result.thinking.text, completed: result.thinking.completed, action: (_d = thinking.action) === null || _d === void 0 ? void 0 : _d.tag });
362
376
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "doomiaichat",
3
- "version": "7.1.13",
3
+ "version": "7.1.15",
4
4
  "description": "Doomisoft OpenAI",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
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 :1},callChatOption.parameters || {}, { input: message[0]?.content})
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,18 +288,19 @@ 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
- client.workflows.chat.stream(params as ChatWorkflowReq)) ;
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
- let deepThinking = '', thinkingStatus = DeepThinkingStatus.None, cardResource = ''; // 是否在深度思考中
295
+ let deepThinking = '', thinkingStatus = DeepThinkingStatus.None, cardResource = '', preresponseText=''; // 是否在深度思考中
293
296
  for await (const part of stream) {
294
297
  if (part.event === ChatEventType.ERROR) return this.emit('chaterror', { successed: false, error: 'call failed' });
295
298
  if (part.event === ChatEventType.CONVERSATION_MESSAGE_DELTA ||
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 (!content&& reasoning) {
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
  }
@@ -324,7 +328,16 @@ export default class CorzBot extends GptBase {
324
328
  // 将卡片资源返回给客户端
325
329
  this.emit('chatcard', cardData);
326
330
  }
327
- } else {
331
+ } else if(thinking.action === DeepThinkingAction.preresponse){
332
+ /// 当正文一样输出
333
+ const spiltPreresponse = result.thinking.text.slice(preresponseText.length)
334
+ preresponseText = result.thinking.text;
335
+ fullanswer.push(spiltPreresponse);// = [result.thinking.text];// .push(result.thinking.text);
336
+ let output = { successed: true, type, content_type, role, requestid, segment: spiltPreresponse, text: fullanswer.join(''), index: index++, session_id: conversation_id };
337
+ if (attach) output = Object.assign({}, output, attach);
338
+ this.emit('chattext', output)
339
+ }
340
+ else {
328
341
  this.emit('chatthinking', { text: result.thinking.text, completed: result.thinking.completed, action: thinking.action?.tag });
329
342
  }
330
343
  }
@@ -347,8 +360,8 @@ export default class CorzBot extends GptBase {
347
360
  if (part.event === ChatEventType.CONVERSATION_CHAT_COMPLETED ||
348
361
  part.event === WorkflowEventType.DONE
349
362
  ) {
350
- const { conversation_id, content } =( part.data )?? {} as any;
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 };
363
+ const { conversation_id, content } = (part.data) ?? {} as any;
364
+ 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
365
  if (attach) output = Object.assign({}, output, attach);
353
366
  this.emit('chatdone', output)
354
367
  }