@leikeduntech/leiai-js 2.7.1 → 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 +17 -2
- 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
|
@@ -347,6 +347,8 @@ Current date: ${currentDate}`;
|
|
|
347
347
|
}
|
|
348
348
|
if (typeof completionParams.pluginList !== "undefined")
|
|
349
349
|
delete completionParams.pluginList;
|
|
350
|
+
if (typeof completionParams.fileList !== "undefined")
|
|
351
|
+
delete completionParams.fileList;
|
|
350
352
|
let body = {
|
|
351
353
|
max_tokens: maxTokens,
|
|
352
354
|
...this._completionParams,
|
|
@@ -510,7 +512,6 @@ Current date: ${currentDate}`;
|
|
|
510
512
|
result.text += result.delta;
|
|
511
513
|
result.role = "assistant";
|
|
512
514
|
if (response.choices[0].finish_reason === "tool_calls") {
|
|
513
|
-
result.role = "function";
|
|
514
515
|
result.name = this.pluginListMap(pluginList);
|
|
515
516
|
} else if (delta.role) {
|
|
516
517
|
result.role = delta.role;
|
|
@@ -690,7 +691,7 @@ Current date: ${currentDate}`;
|
|
|
690
691
|
this._apiOrg = apiOrg;
|
|
691
692
|
}
|
|
692
693
|
async _buildMessages(text, opts) {
|
|
693
|
-
const { systemMessage = this._systemMessage } = opts;
|
|
694
|
+
const { systemMessage = this._systemMessage, completionParams } = opts;
|
|
694
695
|
let { parentMessageId } = opts;
|
|
695
696
|
let errorMessage = "";
|
|
696
697
|
const userLabel = USER_LABEL_DEFAULT;
|
|
@@ -703,6 +704,20 @@ Current date: ${currentDate}`;
|
|
|
703
704
|
content: systemMessage
|
|
704
705
|
});
|
|
705
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
|
+
}
|
|
706
721
|
const systemMessageOffset = messages.length;
|
|
707
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 }];
|
|
708
723
|
let nextMessages = text ? messages.concat(userMessage) : messages;
|