@leikeduntech/leiai-js 3.3.0 → 3.4.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.
Files changed (2) hide show
  1. package/build/index.js +18 -8
  2. package/package.json +1 -1
package/build/index.js CHANGED
@@ -355,7 +355,7 @@ Current date: ${currentDate}`;
355
355
  };
356
356
  const responseP = new Promise(
357
357
  async (resolve, reject) => {
358
- var _a2, _b, _c, _d, _e, _f;
358
+ var _a2, _b, _c, _d, _e, _f, _g;
359
359
  let url = `${this._apiBaseUrl}/chat/completions`;
360
360
  const headers = {
361
361
  "Content-Type": "application/json",
@@ -463,10 +463,20 @@ Current date: ${currentDate}`;
463
463
  delete body.model;
464
464
  delete body.max_tokens;
465
465
  headers["Authorization"] = signTencentHunyuan(body, url, keyList);
466
+ } else if (this._manufacturer.toLowerCase() === "baidu") {
467
+ if (pluginList.indexOf("zhishiku") > -1) {
468
+ let query = messages.splice(messages.length - 1, 1);
469
+ body = Object.assign(body, { query: (_a2 = query[0]) == null ? void 0 : _a2.content, history: messages });
470
+ delete body.messages;
471
+ }
466
472
  }
467
473
  if (this._apiOrg && this._manufacturer.toLowerCase() === "openai") {
468
474
  headers["OpenAI-Organization"] = this._apiOrg;
469
475
  }
476
+ if (this._manufacturer.toLowerCase() !== "baidu" || pluginList.indexOf("zhishiku") < 0) {
477
+ if (typeof body.plugins !== void 0)
478
+ delete body.plugins;
479
+ }
470
480
  if (this._debug) {
471
481
  console.log(`api url ${url}`);
472
482
  console.log(`api header ${JSON.stringify(headers)}`);
@@ -520,7 +530,7 @@ Current date: ${currentDate}`;
520
530
  body: JSON.stringify(body),
521
531
  signal: abortSignal,
522
532
  onMessage: (data) => {
523
- var _a3, _b2, _c2, _d2, _e2, _f2, _g, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v;
533
+ var _a3, _b2, _c2, _d2, _e2, _f2, _g2, _h, _i, _j, _k, _l, _m, _n, _o, _p, _q, _r, _s, _t, _u, _v;
524
534
  if (data === "[DONE]") {
525
535
  result.text = result.text.trim();
526
536
  return resolve(result);
@@ -549,7 +559,7 @@ Current date: ${currentDate}`;
549
559
  return resolve(result);
550
560
  }
551
561
  } else if (this._manufacturer.toLowerCase() === "tencent") {
552
- if (((_g = response.choices[0]) == null ? void 0 : _g.finish_reason) === "stop") {
562
+ if (((_g2 = response.choices[0]) == null ? void 0 : _g2.finish_reason) === "stop") {
553
563
  result.text += (_i = (_h = response == null ? void 0 : response.choices[0]) == null ? void 0 : _h.delta) == null ? void 0 : _i.content.trim();
554
564
  return resolve(result);
555
565
  }
@@ -641,7 +651,7 @@ Current date: ${currentDate}`;
641
651
  }
642
652
  const response = await res.json();
643
653
  if (this._debug) {
644
- console.log(`row data ${typeof response} : `, response, (_a2 = response == null ? void 0 : response.choices[0]) == null ? void 0 : _a2.message);
654
+ console.log(`row data ${typeof response} : `, response, (_b = response == null ? void 0 : response.choices[0]) == null ? void 0 : _b.message);
645
655
  }
646
656
  if (this._manufacturer.toLowerCase() === "aliyun") {
647
657
  if (response == null ? void 0 : response.request_id) {
@@ -652,7 +662,7 @@ Current date: ${currentDate}`;
652
662
  result.id = response.id;
653
663
  }
654
664
  }
655
- if (((_b = response == null ? void 0 : response.choices) == null ? void 0 : _b.length) && ["openai", "azure"].indexOf(this._manufacturer.toLowerCase()) > -1) {
665
+ if (((_c = response == null ? void 0 : response.choices) == null ? void 0 : _c.length) && ["openai", "azure"].indexOf(this._manufacturer.toLowerCase()) > -1) {
656
666
  const message2 = response.choices[0].message;
657
667
  result.text = message2.content;
658
668
  if (message2.role) {
@@ -661,14 +671,14 @@ Current date: ${currentDate}`;
661
671
  } else if ((response == null ? void 0 : response.result) && this._manufacturer.toLowerCase() === "baidu") {
662
672
  result.text = response.result;
663
673
  result.role = "assistant";
664
- } else if (((_c = response == null ? void 0 : response.output) == null ? void 0 : _c.text) && this._manufacturer.toLowerCase() === "aliyun") {
665
- result.text = (_d = response == null ? void 0 : response.output) == null ? void 0 : _d.text;
674
+ } else if (((_d = response == null ? void 0 : response.output) == null ? void 0 : _d.text) && this._manufacturer.toLowerCase() === "aliyun") {
675
+ result.text = (_e = response == null ? void 0 : response.output) == null ? void 0 : _e.text;
666
676
  result.role = "assistant";
667
677
  } else {
668
678
  const res2 = response;
669
679
  return reject(
670
680
  new Error(
671
- `${this._manufacturer} error: ${((_e = res2 == null ? void 0 : res2.detail) == null ? void 0 : _e.message) || ((_f = res2 == null ? void 0 : res2.detail) == null ? void 0 : _f.error_msg) || (res2 == null ? void 0 : res2.detail) || "unknown"}`
681
+ `${this._manufacturer} error: ${((_f = res2 == null ? void 0 : res2.detail) == null ? void 0 : _f.message) || ((_g = res2 == null ? void 0 : res2.detail) == null ? void 0 : _g.error_msg) || (res2 == null ? void 0 : res2.detail) || "unknown"}`
672
682
  )
673
683
  );
674
684
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leikeduntech/leiai-js",
3
- "version": "3.3.0",
3
+ "version": "3.4.0",
4
4
  "author": "liuhean",
5
5
  "repository": {
6
6
  "type": "git",