@leikeduntech/leiai-js 2.6.0 → 2.7.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
@@ -1,6 +1,6 @@
1
1
  import Keyv from 'keyv';
2
2
 
3
- type Role = 'user' | 'assistant' | 'system';
3
+ type Role = 'user' | 'assistant' | 'system' | 'function';
4
4
  type FetchFn = typeof fetch;
5
5
  type ChatGPTAPIOptions = {
6
6
  /** 模型厂商公司 **/
@@ -336,6 +336,7 @@ declare namespace openai {
336
336
  * @memberof CreateChatCompletionRequest
337
337
  */
338
338
  user?: string;
339
+ pluginList?: string | object;
339
340
  }
340
341
  /**
341
342
  * @type CreateChatCompletionRequestStop
@@ -473,6 +474,11 @@ declare class ChatGPTAPI {
473
474
  * @param fetch - Optional override for the `fetch` implementation to use. Defaults to the global `fetch` function.
474
475
  */
475
476
  constructor(opts: ChatGPTAPIOptions);
477
+ pluginListMap(pluginList: any): any;
478
+ DallE3Fun(): {
479
+ pluginList: string;
480
+ description: string;
481
+ };
476
482
  /**
477
483
  * Sends a message to the OpenAI chat completions endpoint, waits for the response
478
484
  * to resolve, and returns the response.
package/build/index.js CHANGED
@@ -225,6 +225,16 @@ var ChatGPTAPI = class {
225
225
  throw new Error('Invalid "fetch" is not a function');
226
226
  }
227
227
  }
228
+ pluginListMap(pluginList) {
229
+ const list = {
230
+ "dall-e-3": "DallE3Fun"
231
+ };
232
+ return list[pluginList];
233
+ }
234
+ // DallE3文生图插件
235
+ DallE3Fun() {
236
+ return { pluginList: "dall-e-3", description: "\u4F7F\u7528DALL-E3\u6A21\u578B\u6839\u636E\u7528\u6237\u63CF\u8FF0\u63D0\u793A\u7ED8\u56FE\u753B\u753B\u4F5C\u56FE" };
237
+ }
228
238
  /**
229
239
  * Sends a message to the OpenAI chat completions endpoint, waits for the response
230
240
  * to resolve, and returns the response.
@@ -331,6 +341,11 @@ Current date: ${currentDate}`;
331
341
  url = "";
332
342
  delete headers.Authorization;
333
343
  }
344
+ let pluginList;
345
+ if (completionParams.pluginList) {
346
+ pluginList = completionParams.pluginList;
347
+ delete completionParams.pluginList;
348
+ }
334
349
  let body = {
335
350
  max_tokens: maxTokens,
336
351
  ...this._completionParams,
@@ -338,7 +353,33 @@ Current date: ${currentDate}`;
338
353
  messages,
339
354
  stream
340
355
  };
341
- if (this._manufacturer.toLowerCase() === "aliyun") {
356
+ if (["openai"].indexOf(this._manufacturer.toLowerCase()) > -1) {
357
+ switch (pluginList) {
358
+ case "plugin1":
359
+ break;
360
+ case "dall-e-3":
361
+ body = Object.assign(body, { tools: [{
362
+ type: "function",
363
+ function: {
364
+ "name": "DallE3Fun",
365
+ "description": this.DallE3Fun().description,
366
+ "parameters": {
367
+ "type": "object",
368
+ "properties": {
369
+ "prompt": {
370
+ "type": "string",
371
+ "description": "\u7528\u6237\u7684\u63D0\u793A\u8BCD"
372
+ }
373
+ },
374
+ "required": ["prompt"]
375
+ }
376
+ }
377
+ }], tool_choice: "auto" });
378
+ break;
379
+ default:
380
+ break;
381
+ }
382
+ } else if (this._manufacturer.toLowerCase() === "aliyun") {
342
383
  body = Object.assign(body, { parameters: { result_format: "message" }, input: { messages } });
343
384
  delete body.messages;
344
385
  } else if (this._manufacturer.toLowerCase() === "zhipu") {
@@ -458,11 +499,19 @@ Current date: ${currentDate}`;
458
499
  }
459
500
  if (((_j = response.choices) == null ? void 0 : _j.length) && ["openai", "azure", "tencent"].indexOf(this._manufacturer.toLowerCase()) > -1) {
460
501
  const delta = response.choices[0].delta;
461
- result.delta = delta.content;
502
+ result.delta = "";
503
+ if (response.choices[0].finish_reason === "tool_calls") {
504
+ result.delta = text;
505
+ } else if (delta.content) {
506
+ result.delta = delta.content;
507
+ }
462
508
  if (delta == null ? void 0 : delta.content)
463
- result.text += delta.content;
509
+ result.text += result.delta;
464
510
  result.role = "assistant";
465
- if (delta.role) {
511
+ if (response.choices[0].finish_reason === "tool_calls") {
512
+ result.role = "function";
513
+ result.name = this.pluginListMap(pluginList);
514
+ } else if (delta.role) {
466
515
  result.role = delta.role;
467
516
  }
468
517
  result.detail = response;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@leikeduntech/leiai-js",
3
- "version": "2.6.0",
3
+ "version": "2.7.0",
4
4
  "author": "liuhean",
5
5
  "repository": {
6
6
  "type": "git",