@leikeduntech/leiai-js 2.9.0 → 3.0.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.
package/build/index.d.ts CHANGED
@@ -467,7 +467,6 @@ declare class ChatGPTAPI {
467
467
  protected _getMessageById: GetMessageByIdFunction;
468
468
  protected _upsertMessage: UpsertMessageFunction;
469
469
  protected _messageStore: Keyv<ChatMessage>;
470
- protected _DallE3FunData: any;
471
470
  /**
472
471
  * Creates a new client wrapper around OpenAI's chat completion API, mimicing the official ChatGPT webapp's functionality as closely as possible.
473
472
  *
@@ -485,7 +484,6 @@ declare class ChatGPTAPI {
485
484
  */
486
485
  constructor(opts: ChatGPTAPIOptions);
487
486
  pluginListMap(pluginList: any): any;
488
- DallE3Fun(): any;
489
487
  /**
490
488
  * Sends a message to the OpenAI chat completions endpoint, waits for the response
491
489
  * to resolve, and returns the response.
package/build/index.js CHANGED
@@ -229,15 +229,15 @@ var ChatGPTAPI = class {
229
229
  const list = {
230
230
  "dall-e-3": {
231
231
  name: "DallE3Fun",
232
- description: "\u4F7F\u7528DALL-E3\u6A21\u578B\u6839\u636E\u7528\u6237\u63CF\u8FF0\u63D0\u793A\u7ED8\u56FE\u753B\u753B\u4F5C\u56FE"
232
+ description: "\u4F7F\u7528DALL-E3\u6A21\u578B\u6839\u636E\u7528\u6237\u63CF\u8FF0\u63D0\u793A\u521B\u4F5C\u4E00\u5F20\u65B0\u7684\u56FE\u7247"
233
+ },
234
+ "dall-e-2": {
235
+ name: "DallE2Fun",
236
+ description: "\u4F7F\u7528DALL-E2\u6A21\u578B\u57FA\u4E8E\u7528\u6237\u63D0\u4F9B\u7684\u56FE\u7247\u5730\u5740url\u548C\u63D0\u793A\u8BCD\u91CD\u65B0\u4FEE\u6539\u56FE\u7247\u7F16\u8F91\u56FE\u7247\u66FF\u6362\u56FE\u7247\u5220\u9664\u56FE\u7247\u90E8\u4EFD\u5185\u5BB9"
233
237
  }
234
238
  };
235
239
  return list[pluginList];
236
240
  }
237
- // DallE3文生图插件
238
- DallE3Fun() {
239
- return this._DallE3FunData;
240
- }
241
241
  /**
242
242
  * Sends a message to the OpenAI chat completions endpoint, waits for the response
243
243
  * to resolve, and returns the response.
@@ -295,6 +295,8 @@ Current date: ${currentDate}`;
295
295
  parentMessageId,
296
296
  text
297
297
  };
298
+ if (this._debug)
299
+ console.log("\u8DDF\u8E2A1, \u8D85\u65F6\u65F6\u95F4ms", timeoutMs);
298
300
  let latestQuestion = message, last_assistant_res_message = null, last_assistant_res = null, last_plugin_res = null;
299
301
  if (pluginParams) {
300
302
  last_assistant_res_message = pluginParams.assistant_res.detail.choices[0];
@@ -318,8 +320,9 @@ Current date: ${currentDate}`;
318
320
  };
319
321
  await this._upsertMessage(last_assistant_res);
320
322
  latestQuestion = last_plugin_res;
321
- this[`_${last_plugin_res.name}Data`] = pluginParams.plugin_res;
322
323
  }
324
+ if (this._debug)
325
+ console.log("\u8DDF\u8E2A2");
323
326
  const { messages, maxTokens, numTokens, errorMessage } = await this._buildMessages(
324
327
  text,
325
328
  opts,
@@ -391,10 +394,28 @@ Current date: ${currentDate}`;
391
394
  };
392
395
  if (["openai"].indexOf(this._manufacturer.toLowerCase()) > -1) {
393
396
  switch (pluginList) {
394
- case "plugin1":
395
- break;
396
397
  case "dall-e-3":
397
398
  body = Object.assign(body, { tools: [{
399
+ type: "function",
400
+ function: {
401
+ "name": "DallE2Fun",
402
+ "description": this.pluginListMap(pluginList).description,
403
+ "parameters": {
404
+ "type": "object",
405
+ "properties": {
406
+ "prompt": {
407
+ "type": "string",
408
+ "description": "\u7528\u6237\u5BF9\u9700\u8981\u7F16\u8F91\u7684\u56FE\u7247\u4FEE\u6539\u7684\u63D0\u793A\u5185\u5BB9"
409
+ },
410
+ "image_url": {
411
+ "type": "string",
412
+ "description": "\u4ECE\u5BF9\u8BDD\u5386\u53F2\u8BB0\u5F55\u548C\u7528\u6237\u63D0\u793A\u8BCD\u91CC\u5339\u914D\u6700\u8FD1\u4E00\u6B21\u51FA\u73B0\u7684\u4EE5http\u5F00\u5934\u7684\u56FE\u7247\u7684\u94FE\u63A5\u5730\u5740"
413
+ }
414
+ },
415
+ "required": ["prompt", "image_url"]
416
+ }
417
+ }
418
+ }, {
398
419
  type: "function",
399
420
  function: {
400
421
  "name": "DallE3Fun",
@@ -404,7 +425,7 @@ Current date: ${currentDate}`;
404
425
  "properties": {
405
426
  "prompt": {
406
427
  "type": "string",
407
- "description": "\u7528\u6237\u7684\u63D0\u793A\u8BCD"
428
+ "description": "\u7ED8\u56FE\u7684\u63D0\u793A\u8BCD"
408
429
  }
409
430
  },
410
431
  "required": ["prompt"]
@@ -587,12 +608,16 @@ Current date: ${currentDate}`;
587
608
  ).catch(reject);
588
609
  } else {
589
610
  try {
611
+ if (this._debug)
612
+ console.log("\u8DDF\u8E2A3");
590
613
  const res = await this._fetch(url, {
591
614
  method: "POST",
592
615
  headers,
593
616
  body: JSON.stringify(body),
594
617
  signal: abortSignal
595
618
  });
619
+ if (this._debug)
620
+ console.log("\u8DDF\u8E2A4");
596
621
  if (!res.ok) {
597
622
  const reason = await res.text();
598
623
  const msg = `${this._manufacturer} error ${res.status || res.statusText}: ${reason}`;
@@ -635,8 +660,12 @@ Current date: ${currentDate}`;
635
660
  );
636
661
  }
637
662
  result.detail = response;
663
+ if (this._debug)
664
+ console.log("\u8DDF\u8E2A5");
638
665
  return resolve(result);
639
666
  } catch (err) {
667
+ if (this._debug)
668
+ console.log("\u8DDF\u8E2A6");
640
669
  return reject(err);
641
670
  }
642
671
  }
@@ -644,6 +673,8 @@ Current date: ${currentDate}`;
644
673
  }
645
674
  ).then(async (message2) => {
646
675
  var _a2, _b;
676
+ if (this._debug)
677
+ console.log("\u8DDF\u8E2A7", JSON.stringify(message2));
647
678
  if (message2.detail && !message2.detail.usage) {
648
679
  try {
649
680
  const promptTokens = numTokens;
@@ -668,7 +699,11 @@ Current date: ${currentDate}`;
668
699
  ]).then(() => message2);
669
700
  return pRes;
670
701
  });
702
+ if (this._debug)
703
+ console.log("\u8DDF\u8E2A8");
671
704
  if (timeoutMs) {
705
+ if (this._debug)
706
+ console.log("\u8DDF\u8E2A9");
672
707
  if (abortController) {
673
708
  ;
674
709
  responseP.cancel = () => {
@@ -680,6 +715,8 @@ Current date: ${currentDate}`;
680
715
  message: `${this._manufacturer} timed out waiting for response`
681
716
  });
682
717
  } else {
718
+ if (this._debug)
719
+ console.log("\u8DDF\u8E2A10");
683
720
  return responseP;
684
721
  }
685
722
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leikeduntech/leiai-js",
3
- "version": "2.9.0",
3
+ "version": "3.0.0",
4
4
  "author": "liuhean",
5
5
  "repository": {
6
6
  "type": "git",