@leikeduntech/leiai-js 2.6.0 → 2.7.1
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 +7 -1
- package/build/index.js +54 -4
- package/package.json +1 -1
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,12 @@ 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
|
+
}
|
|
348
|
+
if (typeof completionParams.pluginList !== "undefined")
|
|
349
|
+
delete completionParams.pluginList;
|
|
334
350
|
let body = {
|
|
335
351
|
max_tokens: maxTokens,
|
|
336
352
|
...this._completionParams,
|
|
@@ -338,7 +354,33 @@ Current date: ${currentDate}`;
|
|
|
338
354
|
messages,
|
|
339
355
|
stream
|
|
340
356
|
};
|
|
341
|
-
if (this._manufacturer.toLowerCase()
|
|
357
|
+
if (["openai"].indexOf(this._manufacturer.toLowerCase()) > -1) {
|
|
358
|
+
switch (pluginList) {
|
|
359
|
+
case "plugin1":
|
|
360
|
+
break;
|
|
361
|
+
case "dall-e-3":
|
|
362
|
+
body = Object.assign(body, { tools: [{
|
|
363
|
+
type: "function",
|
|
364
|
+
function: {
|
|
365
|
+
"name": "DallE3Fun",
|
|
366
|
+
"description": this.DallE3Fun().description,
|
|
367
|
+
"parameters": {
|
|
368
|
+
"type": "object",
|
|
369
|
+
"properties": {
|
|
370
|
+
"prompt": {
|
|
371
|
+
"type": "string",
|
|
372
|
+
"description": "\u7528\u6237\u7684\u63D0\u793A\u8BCD"
|
|
373
|
+
}
|
|
374
|
+
},
|
|
375
|
+
"required": ["prompt"]
|
|
376
|
+
}
|
|
377
|
+
}
|
|
378
|
+
}], tool_choice: "auto" });
|
|
379
|
+
break;
|
|
380
|
+
default:
|
|
381
|
+
break;
|
|
382
|
+
}
|
|
383
|
+
} else if (this._manufacturer.toLowerCase() === "aliyun") {
|
|
342
384
|
body = Object.assign(body, { parameters: { result_format: "message" }, input: { messages } });
|
|
343
385
|
delete body.messages;
|
|
344
386
|
} else if (this._manufacturer.toLowerCase() === "zhipu") {
|
|
@@ -458,11 +500,19 @@ Current date: ${currentDate}`;
|
|
|
458
500
|
}
|
|
459
501
|
if (((_j = response.choices) == null ? void 0 : _j.length) && ["openai", "azure", "tencent"].indexOf(this._manufacturer.toLowerCase()) > -1) {
|
|
460
502
|
const delta = response.choices[0].delta;
|
|
461
|
-
result.delta =
|
|
503
|
+
result.delta = "";
|
|
504
|
+
if (response.choices[0].finish_reason === "tool_calls") {
|
|
505
|
+
result.delta = text;
|
|
506
|
+
} else if (delta.content) {
|
|
507
|
+
result.delta = delta.content;
|
|
508
|
+
}
|
|
462
509
|
if (delta == null ? void 0 : delta.content)
|
|
463
|
-
result.text += delta
|
|
510
|
+
result.text += result.delta;
|
|
464
511
|
result.role = "assistant";
|
|
465
|
-
if (
|
|
512
|
+
if (response.choices[0].finish_reason === "tool_calls") {
|
|
513
|
+
result.role = "function";
|
|
514
|
+
result.name = this.pluginListMap(pluginList);
|
|
515
|
+
} else if (delta.role) {
|
|
466
516
|
result.role = delta.role;
|
|
467
517
|
}
|
|
468
518
|
result.detail = response;
|