@leikeduntech/leiai-js 2.7.0 → 2.8.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 +3 -1
- package/build/index.js +19 -3
- 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' | 'function';
|
|
3
|
+
type Role = 'user' | 'assistant' | 'system' | 'function' | 'tool';
|
|
4
4
|
type FetchFn = typeof fetch;
|
|
5
5
|
type ChatGPTAPIOptions = {
|
|
6
6
|
/** 模型厂商公司 **/
|
|
@@ -62,6 +62,7 @@ interface ChatMessage {
|
|
|
62
62
|
result?: string;
|
|
63
63
|
need_clear_history?: boolean;
|
|
64
64
|
usage?: object;
|
|
65
|
+
tool_call_id?: string;
|
|
65
66
|
}
|
|
66
67
|
declare class ChatGPTError extends Error {
|
|
67
68
|
statusCode?: number;
|
|
@@ -337,6 +338,7 @@ declare namespace openai {
|
|
|
337
338
|
*/
|
|
338
339
|
user?: string;
|
|
339
340
|
pluginList?: string | object;
|
|
341
|
+
fileList?: Array<any>;
|
|
340
342
|
}
|
|
341
343
|
/**
|
|
342
344
|
* @type CreateChatCompletionRequestStop
|
package/build/index.js
CHANGED
|
@@ -344,8 +344,11 @@ Current date: ${currentDate}`;
|
|
|
344
344
|
let pluginList;
|
|
345
345
|
if (completionParams.pluginList) {
|
|
346
346
|
pluginList = completionParams.pluginList;
|
|
347
|
-
delete completionParams.pluginList;
|
|
348
347
|
}
|
|
348
|
+
if (typeof completionParams.pluginList !== "undefined")
|
|
349
|
+
delete completionParams.pluginList;
|
|
350
|
+
if (typeof completionParams.fileList !== "undefined")
|
|
351
|
+
delete completionParams.fileList;
|
|
349
352
|
let body = {
|
|
350
353
|
max_tokens: maxTokens,
|
|
351
354
|
...this._completionParams,
|
|
@@ -509,7 +512,6 @@ Current date: ${currentDate}`;
|
|
|
509
512
|
result.text += result.delta;
|
|
510
513
|
result.role = "assistant";
|
|
511
514
|
if (response.choices[0].finish_reason === "tool_calls") {
|
|
512
|
-
result.role = "function";
|
|
513
515
|
result.name = this.pluginListMap(pluginList);
|
|
514
516
|
} else if (delta.role) {
|
|
515
517
|
result.role = delta.role;
|
|
@@ -689,7 +691,7 @@ Current date: ${currentDate}`;
|
|
|
689
691
|
this._apiOrg = apiOrg;
|
|
690
692
|
}
|
|
691
693
|
async _buildMessages(text, opts) {
|
|
692
|
-
const { systemMessage = this._systemMessage } = opts;
|
|
694
|
+
const { systemMessage = this._systemMessage, completionParams } = opts;
|
|
693
695
|
let { parentMessageId } = opts;
|
|
694
696
|
let errorMessage = "";
|
|
695
697
|
const userLabel = USER_LABEL_DEFAULT;
|
|
@@ -702,6 +704,20 @@ Current date: ${currentDate}`;
|
|
|
702
704
|
content: systemMessage
|
|
703
705
|
});
|
|
704
706
|
}
|
|
707
|
+
let objText = [{ type: "text", text }];
|
|
708
|
+
if (completionParams.fileList && completionParams.fileList.length > 0 && completionParams.model === "gpt-4-vision-preview") {
|
|
709
|
+
completionParams.fileList.forEach((item) => {
|
|
710
|
+
objText.push({
|
|
711
|
+
type: "image_url",
|
|
712
|
+
image_url: {
|
|
713
|
+
url: item.imgUrl
|
|
714
|
+
}
|
|
715
|
+
});
|
|
716
|
+
});
|
|
717
|
+
if (["openai"].indexOf(this._manufacturer.toLowerCase()) > -1) {
|
|
718
|
+
text = objText;
|
|
719
|
+
}
|
|
720
|
+
}
|
|
705
721
|
const systemMessageOffset = messages.length;
|
|
706
722
|
const userMessage = ["baidu", "azure", "zhipu", "xunfei", "aliyun", "tencent"].indexOf(this._manufacturer.toLowerCase()) > -1 ? [{ role: "user", content: text }] : [{ role: "user", content: text, name: opts.name }];
|
|
707
723
|
let nextMessages = text ? messages.concat(userMessage) : messages;
|