koishi-plugin-chatluna-google-gemini-adapter 1.1.2 → 1.1.4
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/lib/index.cjs +27 -6
- package/lib/index.mjs +17 -6
- package/lib/types.d.ts +1 -1
- package/lib/utils.d.ts +1 -1
- package/package.json +2 -2
package/lib/index.cjs
CHANGED
|
@@ -1,6 +1,8 @@
|
|
|
1
|
+
var __create = Object.create;
|
|
1
2
|
var __defProp = Object.defineProperty;
|
|
2
3
|
var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
|
|
3
4
|
var __getOwnPropNames = Object.getOwnPropertyNames;
|
|
5
|
+
var __getProtoOf = Object.getPrototypeOf;
|
|
4
6
|
var __hasOwnProp = Object.prototype.hasOwnProperty;
|
|
5
7
|
var __name = (target, value) => __defProp(target, "name", { value, configurable: true });
|
|
6
8
|
var __commonJS = (cb, mod) => function __require() {
|
|
@@ -18,6 +20,14 @@ var __copyProps = (to, from, except, desc) => {
|
|
|
18
20
|
}
|
|
19
21
|
return to;
|
|
20
22
|
};
|
|
23
|
+
var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
|
|
24
|
+
// If the importer is in node compatibility mode or this is not an ESM
|
|
25
|
+
// file that has been converted to a CommonJS file using a Babel-
|
|
26
|
+
// compatible transform (i.e. "__esModule" has not been set), then set
|
|
27
|
+
// "default" to the CommonJS "module.exports" for node compatibility.
|
|
28
|
+
isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
|
|
29
|
+
mod
|
|
30
|
+
));
|
|
21
31
|
var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
|
|
22
32
|
|
|
23
33
|
// src/locales/zh-CN.schema.yml
|
|
@@ -67,7 +77,7 @@ var import_zod_to_json_schema = require("zod-to-json-schema");
|
|
|
67
77
|
async function langchainMessageToGeminiMessage(messages, model) {
|
|
68
78
|
const mappedMessage = await Promise.all(
|
|
69
79
|
messages.map(async (rawMessage) => {
|
|
70
|
-
const role = messageTypeToGeminiRole(rawMessage.
|
|
80
|
+
const role = messageTypeToGeminiRole(rawMessage.getType());
|
|
71
81
|
if (role === "function" || rawMessage.additional_kwargs?.function_call != null) {
|
|
72
82
|
return {
|
|
73
83
|
role: "function",
|
|
@@ -133,14 +143,23 @@ async function langchainMessageToGeminiMessage(messages, model) {
|
|
|
133
143
|
};
|
|
134
144
|
if ((model.includes("vision") || model.includes("gemini")) && images != null && !model.includes("gemini-1.0")) {
|
|
135
145
|
for (const image of images) {
|
|
146
|
+
const mineType = image.split(";")?.[0]?.split(":")?.[1];
|
|
147
|
+
const data = image.replace(/^data:image\/\w+;base64,/, "");
|
|
136
148
|
result2.parts.push({
|
|
137
149
|
inline_data: {
|
|
138
150
|
// base64 image match type
|
|
139
|
-
data
|
|
140
|
-
mime_type: "image/jpeg"
|
|
151
|
+
data,
|
|
152
|
+
mime_type: mineType ?? "image/jpeg"
|
|
141
153
|
}
|
|
142
154
|
});
|
|
143
155
|
}
|
|
156
|
+
result2.parts = result2.parts.filter((uncheckedPart) => {
|
|
157
|
+
const part = partAsTypeCheck(
|
|
158
|
+
uncheckedPart,
|
|
159
|
+
(part2) => part2["text"] != null
|
|
160
|
+
);
|
|
161
|
+
return part == null || part.text.length > 0;
|
|
162
|
+
});
|
|
144
163
|
}
|
|
145
164
|
return result2;
|
|
146
165
|
})
|
|
@@ -297,6 +316,7 @@ function messageTypeToGeminiRole(type) {
|
|
|
297
316
|
__name(messageTypeToGeminiRole, "messageTypeToGeminiRole");
|
|
298
317
|
|
|
299
318
|
// src/requester.ts
|
|
319
|
+
var import_promises = __toESM(require("fs/promises"), 1);
|
|
300
320
|
var GeminiRequester = class extends import_api.ModelRequester {
|
|
301
321
|
constructor(_config, _plugin, _pluginConfig) {
|
|
302
322
|
super();
|
|
@@ -419,7 +439,7 @@ var GeminiRequester = class extends import_api.ModelRequester {
|
|
|
419
439
|
}
|
|
420
440
|
content = messagePart.text;
|
|
421
441
|
} else if (imagePart) {
|
|
422
|
-
messagePart.text = ``;
|
|
423
443
|
content = messagePart.text;
|
|
424
444
|
}
|
|
425
445
|
const deltaFunctionCall = chatFunctionCallingPart?.functionCall;
|
|
@@ -449,7 +469,7 @@ var GeminiRequester = class extends import_api.ModelRequester {
|
|
|
449
469
|
args: functionCall.arguments
|
|
450
470
|
} : void 0,
|
|
451
471
|
images: imagePart ? [
|
|
452
|
-
`data:${imagePart.inlineData.
|
|
472
|
+
`data:${imagePart.inlineData.mimeType ?? "image/png"};base64,${imagePart.inlineData.data}`
|
|
453
473
|
] : void 0
|
|
454
474
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
455
475
|
};
|
|
@@ -573,6 +593,7 @@ ${groundingContent}`
|
|
|
573
593
|
}
|
|
574
594
|
}
|
|
575
595
|
const body = JSON.stringify(data);
|
|
596
|
+
import_promises.default.writeFile("./request.json", body);
|
|
576
597
|
return this._plugin.fetch(requestUrl, {
|
|
577
598
|
body,
|
|
578
599
|
headers: this._buildHeaders(),
|
|
@@ -647,7 +668,7 @@ var GeminiClient = class extends import_client.PlatformModelAndEmbeddingsClient
|
|
|
647
668
|
if (model2.includes("gemini-1.5-pro")) {
|
|
648
669
|
return 1048576;
|
|
649
670
|
}
|
|
650
|
-
if (model2.includes("gemini-1.5-flash") || model2.includes("gemini-2.0-pro")) {
|
|
671
|
+
if (model2.includes("gemini-1.5-flash") || model2.includes("gemini-2.0-pro") || model2.includes("gemini-2.5-pro")) {
|
|
651
672
|
return 2097152;
|
|
652
673
|
}
|
|
653
674
|
if (model2.includes("gemini-1.0-pro")) {
|
package/lib/index.mjs
CHANGED
|
@@ -61,7 +61,7 @@ import { zodToJsonSchema } from "zod-to-json-schema";
|
|
|
61
61
|
async function langchainMessageToGeminiMessage(messages, model) {
|
|
62
62
|
const mappedMessage = await Promise.all(
|
|
63
63
|
messages.map(async (rawMessage) => {
|
|
64
|
-
const role = messageTypeToGeminiRole(rawMessage.
|
|
64
|
+
const role = messageTypeToGeminiRole(rawMessage.getType());
|
|
65
65
|
if (role === "function" || rawMessage.additional_kwargs?.function_call != null) {
|
|
66
66
|
return {
|
|
67
67
|
role: "function",
|
|
@@ -127,14 +127,23 @@ async function langchainMessageToGeminiMessage(messages, model) {
|
|
|
127
127
|
};
|
|
128
128
|
if ((model.includes("vision") || model.includes("gemini")) && images != null && !model.includes("gemini-1.0")) {
|
|
129
129
|
for (const image of images) {
|
|
130
|
+
const mineType = image.split(";")?.[0]?.split(":")?.[1];
|
|
131
|
+
const data = image.replace(/^data:image\/\w+;base64,/, "");
|
|
130
132
|
result2.parts.push({
|
|
131
133
|
inline_data: {
|
|
132
134
|
// base64 image match type
|
|
133
|
-
data
|
|
134
|
-
mime_type: "image/jpeg"
|
|
135
|
+
data,
|
|
136
|
+
mime_type: mineType ?? "image/jpeg"
|
|
135
137
|
}
|
|
136
138
|
});
|
|
137
139
|
}
|
|
140
|
+
result2.parts = result2.parts.filter((uncheckedPart) => {
|
|
141
|
+
const part = partAsTypeCheck(
|
|
142
|
+
uncheckedPart,
|
|
143
|
+
(part2) => part2["text"] != null
|
|
144
|
+
);
|
|
145
|
+
return part == null || part.text.length > 0;
|
|
146
|
+
});
|
|
138
147
|
}
|
|
139
148
|
return result2;
|
|
140
149
|
})
|
|
@@ -291,6 +300,7 @@ function messageTypeToGeminiRole(type) {
|
|
|
291
300
|
__name(messageTypeToGeminiRole, "messageTypeToGeminiRole");
|
|
292
301
|
|
|
293
302
|
// src/requester.ts
|
|
303
|
+
import fs from "fs/promises";
|
|
294
304
|
var GeminiRequester = class extends ModelRequester {
|
|
295
305
|
constructor(_config, _plugin, _pluginConfig) {
|
|
296
306
|
super();
|
|
@@ -413,7 +423,7 @@ var GeminiRequester = class extends ModelRequester {
|
|
|
413
423
|
}
|
|
414
424
|
content = messagePart.text;
|
|
415
425
|
} else if (imagePart) {
|
|
416
|
-
messagePart.text = ``;
|
|
417
427
|
content = messagePart.text;
|
|
418
428
|
}
|
|
419
429
|
const deltaFunctionCall = chatFunctionCallingPart?.functionCall;
|
|
@@ -443,7 +453,7 @@ var GeminiRequester = class extends ModelRequester {
|
|
|
443
453
|
args: functionCall.arguments
|
|
444
454
|
} : void 0,
|
|
445
455
|
images: imagePart ? [
|
|
446
|
-
`data:${imagePart.inlineData.
|
|
456
|
+
`data:${imagePart.inlineData.mimeType ?? "image/png"};base64,${imagePart.inlineData.data}`
|
|
447
457
|
] : void 0
|
|
448
458
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
449
459
|
};
|
|
@@ -567,6 +577,7 @@ ${groundingContent}`
|
|
|
567
577
|
}
|
|
568
578
|
}
|
|
569
579
|
const body = JSON.stringify(data);
|
|
580
|
+
fs.writeFile("./request.json", body);
|
|
570
581
|
return this._plugin.fetch(requestUrl, {
|
|
571
582
|
body,
|
|
572
583
|
headers: this._buildHeaders(),
|
|
@@ -641,7 +652,7 @@ var GeminiClient = class extends PlatformModelAndEmbeddingsClient {
|
|
|
641
652
|
if (model2.includes("gemini-1.5-pro")) {
|
|
642
653
|
return 1048576;
|
|
643
654
|
}
|
|
644
|
-
if (model2.includes("gemini-1.5-flash") || model2.includes("gemini-2.0-pro")) {
|
|
655
|
+
if (model2.includes("gemini-1.5-flash") || model2.includes("gemini-2.0-pro") || model2.includes("gemini-2.5-pro")) {
|
|
645
656
|
return 2097152;
|
|
646
657
|
}
|
|
647
658
|
if (model2.includes("gemini-1.0-pro")) {
|
package/lib/types.d.ts
CHANGED
package/lib/utils.d.ts
CHANGED
|
@@ -8,4 +8,4 @@ export declare function partAsTypeCheck<T extends ChatPart>(part: ChatPart, chec
|
|
|
8
8
|
export declare function formatToolsToGeminiAITools(tools: StructuredTool[], config: Config, model: string): Record<string, any>;
|
|
9
9
|
export declare function formatToolToGeminiAITool(tool: StructuredTool): ChatCompletionFunction;
|
|
10
10
|
export declare function messageTypeToGeminiRole(type: MessageType): ChatCompletionResponseMessageRoleEnum;
|
|
11
|
-
export declare function convertDeltaToMessageChunk(delta: Record<string, any>, defaultRole?: ChatCompletionResponseMessageRoleEnum):
|
|
11
|
+
export declare function convertDeltaToMessageChunk(delta: Record<string, any>, defaultRole?: ChatCompletionResponseMessageRoleEnum): AIMessageChunk | HumanMessageChunk | SystemMessageChunk | ChatMessageChunk;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "koishi-plugin-chatluna-google-gemini-adapter",
|
|
3
3
|
"description": "google-gemini adapter for chatluna",
|
|
4
|
-
"version": "1.1.
|
|
4
|
+
"version": "1.1.4",
|
|
5
5
|
"main": "lib/index.cjs",
|
|
6
6
|
"module": "lib/index.mjs",
|
|
7
7
|
"typings": "lib/index.d.ts",
|
|
@@ -72,7 +72,7 @@
|
|
|
72
72
|
},
|
|
73
73
|
"peerDependencies": {
|
|
74
74
|
"koishi": "^4.18.4",
|
|
75
|
-
"koishi-plugin-chatluna": "^1.1.
|
|
75
|
+
"koishi-plugin-chatluna": "^1.1.4"
|
|
76
76
|
},
|
|
77
77
|
"koishi": {
|
|
78
78
|
"description": {
|