koishi-plugin-chatluna-google-gemini-adapter 1.2.0-alpha.0 → 1.2.0-alpha.2
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 +20 -9
- package/lib/index.d.ts +1 -0
- package/lib/index.mjs +20 -9
- package/package.json +2 -2
package/lib/index.cjs
CHANGED
|
@@ -33,14 +33,14 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
33
33
|
// src/locales/zh-CN.schema.yml
|
|
34
34
|
var require_zh_CN_schema = __commonJS({
|
|
35
35
|
"src/locales/zh-CN.schema.yml"(exports2, module2) {
|
|
36
|
-
module2.exports = { $inner: [{}, { $desc: "请求选项", apiKeys: { $inner: ["Gemini 的 API Key", "Gemini API 的请求地址"], $desc: "Gemini 的 API Key 和请求地址列表。" } }, { $desc: "模型配置", maxTokens: "输入的最大上下文 Token(16~2097000,必须是 16 的倍数)。注意:仅当您使用的模型最大 Token 为 8000 及以上时,才建议设置超过 2000 token。", temperature: "回复的随机性程度,数值越高,回复越随机(范围:0~2)。", googleSearch: "为模型启用谷歌搜索。", groundingContentDisplay: "是否显示谷歌搜索结果。", imageGeneration: "为模型启用图像生成。目前仅支持 `gemini-2.0-flash-exp` 模型。", searchThreshold: "搜索的置信度阈值,范围:0~1,设置的数值越低,则越倾向于使用谷歌搜索。" }] };
|
|
36
|
+
module2.exports = { $inner: [{}, { $desc: "请求选项", platform: "适配器的平台名。(不懂请不要修改)", apiKeys: { $inner: ["Gemini 的 API Key", "Gemini API 的请求地址"], $desc: "Gemini 的 API Key 和请求地址列表。" } }, { $desc: "模型配置", maxTokens: "输入的最大上下文 Token(16~2097000,必须是 16 的倍数)。注意:仅当您使用的模型最大 Token 为 8000 及以上时,才建议设置超过 2000 token。", temperature: "回复的随机性程度,数值越高,回复越随机(范围:0~2)。", googleSearch: "为模型启用谷歌搜索。", groundingContentDisplay: "是否显示谷歌搜索结果。", imageGeneration: "为模型启用图像生成。目前仅支持 `gemini-2.0-flash-exp` 模型。", searchThreshold: "搜索的置信度阈值,范围:0~1,设置的数值越低,则越倾向于使用谷歌搜索。" }] };
|
|
37
37
|
}
|
|
38
38
|
});
|
|
39
39
|
|
|
40
40
|
// src/locales/en-US.schema.yml
|
|
41
41
|
var require_en_US_schema = __commonJS({
|
|
42
42
|
"src/locales/en-US.schema.yml"(exports2, module2) {
|
|
43
|
-
module2.exports = { $inner: [{}, { $desc: "API Configuration", apiKeys: { $inner: ["Gemini API Key", "Gemini API Endpoint (optional)"], $desc: "Gemini API access credentials" } }, { $desc: "Model Parameters", maxTokens: "Max output tokens (16-2097000, multiple of 16). >2000 for 8k+ models", temperature: "Sampling temperature (0-2). Higher: more random, Lower: more deterministic", googleSearch: "Enable Google search", groundingContentDisplay: "Enable display of search results", imageGeneration: "Enable image generation (only for `gemini-2.0-flash-exp` model)", searchThreshold: "Search confidence [threshold](https://ai.google.dev/gemini-api/docs/grounding?lang=rest#dynamic-retrieval) (0-1). Lower: more likely to use Google search" }] };
|
|
43
|
+
module2.exports = { $inner: [{}, { $desc: "API Configuration", platform: "Adapter platform name. (Do not modify if you do not understand)", apiKeys: { $inner: ["Gemini API Key", "Gemini API Endpoint (optional)"], $desc: "Gemini API access credentials" } }, { $desc: "Model Parameters", maxTokens: "Max output tokens (16-2097000, multiple of 16). >2000 for 8k+ models", temperature: "Sampling temperature (0-2). Higher: more random, Lower: more deterministic", googleSearch: "Enable Google search", groundingContentDisplay: "Enable display of search results", imageGeneration: "Enable image generation (only for `gemini-2.0-flash-exp` model)", searchThreshold: "Search confidence [threshold](https://ai.google.dev/gemini-api/docs/grounding?lang=rest#dynamic-retrieval) (0-1). Lower: more likely to use Google search" }] };
|
|
44
44
|
}
|
|
45
45
|
});
|
|
46
46
|
|
|
@@ -226,7 +226,12 @@ function formatToolsToGeminiAITools(tools, config, model) {
|
|
|
226
226
|
const unsupportedModels = [
|
|
227
227
|
"gemini-1.0",
|
|
228
228
|
"gemini-2.0-flash-lite",
|
|
229
|
-
"gemini-1.5-flash"
|
|
229
|
+
"gemini-1.5-flash",
|
|
230
|
+
"gemini-2.0-flash-exp"
|
|
231
|
+
];
|
|
232
|
+
const imageInputModels = [
|
|
233
|
+
"gemini-2.0-flash-exp",
|
|
234
|
+
"gemini-2.0-flash-exp-image-generation"
|
|
230
235
|
];
|
|
231
236
|
let googleSearch = config.googleSearch;
|
|
232
237
|
if (functions.length > 0 && !googleSearch) {
|
|
@@ -235,9 +240,11 @@ function formatToolsToGeminiAITools(tools, config, model) {
|
|
|
235
240
|
});
|
|
236
241
|
} else if (functions.length > 0 && googleSearch) {
|
|
237
242
|
logger.warn("Google search is enabled, tool calling will be disable.");
|
|
238
|
-
} else if (unsupportedModels.some(
|
|
243
|
+
} else if ((unsupportedModels.some(
|
|
239
244
|
(unsupportedModel) => model.includes(unsupportedModel)
|
|
240
|
-
)
|
|
245
|
+
) || imageInputModels.some(
|
|
246
|
+
(unsupportedModels2) => model.includes(unsupportedModels2)
|
|
247
|
+
) && config.imageGeneration) && googleSearch) {
|
|
241
248
|
logger.warn(
|
|
242
249
|
`The model ${model} does not support google search. google search will be disable.`
|
|
243
250
|
);
|
|
@@ -265,7 +272,9 @@ __name(formatToolsToGeminiAITools, "formatToolsToGeminiAITools");
|
|
|
265
272
|
function formatToolToGeminiAITool(tool) {
|
|
266
273
|
const parameters = removeAdditionalProperties(
|
|
267
274
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
268
|
-
(0, import_zod_to_json_schema.zodToJsonSchema)(tool.schema
|
|
275
|
+
(0, import_zod_to_json_schema.zodToJsonSchema)(tool.schema, {
|
|
276
|
+
allowedAdditionalProperties: void 0
|
|
277
|
+
})
|
|
269
278
|
);
|
|
270
279
|
return {
|
|
271
280
|
name: tool.name,
|
|
@@ -637,6 +646,7 @@ var GeminiClient = class extends import_client.PlatformModelAndEmbeddingsClient
|
|
|
637
646
|
constructor(ctx, _config, clientConfig, plugin) {
|
|
638
647
|
super(ctx, clientConfig);
|
|
639
648
|
this._config = _config;
|
|
649
|
+
this.platform = this.config.platform;
|
|
640
650
|
this._requester = new GeminiRequester(
|
|
641
651
|
clientConfig,
|
|
642
652
|
plugin,
|
|
@@ -710,7 +720,7 @@ var GeminiClient = class extends import_client.PlatformModelAndEmbeddingsClient
|
|
|
710
720
|
timeout: this._config.timeout,
|
|
711
721
|
temperature: this._config.temperature,
|
|
712
722
|
maxRetries: this._config.maxRetries,
|
|
713
|
-
llmType:
|
|
723
|
+
llmType: this.platform
|
|
714
724
|
});
|
|
715
725
|
}
|
|
716
726
|
return new import_model.ChatLunaEmbeddings({
|
|
@@ -725,7 +735,7 @@ var GeminiClient = class extends import_client.PlatformModelAndEmbeddingsClient
|
|
|
725
735
|
var import_logger = require("koishi-plugin-chatluna/utils/logger");
|
|
726
736
|
var logger;
|
|
727
737
|
function apply(ctx, config) {
|
|
728
|
-
const plugin = new import_chat.ChatLunaPlugin(ctx, config,
|
|
738
|
+
const plugin = new import_chat.ChatLunaPlugin(ctx, config, config.platform);
|
|
729
739
|
logger = (0, import_logger.createLogger)(ctx, "chatluna-gemini-adapter");
|
|
730
740
|
ctx.on("ready", async () => {
|
|
731
741
|
plugin.registerToService();
|
|
@@ -734,7 +744,7 @@ function apply(ctx, config) {
|
|
|
734
744
|
return {
|
|
735
745
|
apiKey,
|
|
736
746
|
apiEndpoint,
|
|
737
|
-
platform:
|
|
747
|
+
platform: config2.platform,
|
|
738
748
|
chatLimit: config2.chatTimeLimit,
|
|
739
749
|
timeout: config2.timeout,
|
|
740
750
|
maxRetries: config2.maxRetries,
|
|
@@ -752,6 +762,7 @@ __name(apply, "apply");
|
|
|
752
762
|
var Config3 = import_koishi.Schema.intersect([
|
|
753
763
|
import_chat.ChatLunaPlugin.Config,
|
|
754
764
|
import_koishi.Schema.object({
|
|
765
|
+
platform: import_koishi.Schema.string().default("gemini"),
|
|
755
766
|
apiKeys: import_koishi.Schema.array(
|
|
756
767
|
import_koishi.Schema.tuple([
|
|
757
768
|
import_koishi.Schema.string().role("secret"),
|
package/lib/index.d.ts
CHANGED
|
@@ -5,6 +5,7 @@ export declare function apply(ctx: Context, config: Config): void;
|
|
|
5
5
|
export interface Config extends ChatLunaPlugin.Config {
|
|
6
6
|
apiKeys: [string, string][];
|
|
7
7
|
maxTokens: number;
|
|
8
|
+
platform: string;
|
|
8
9
|
temperature: number;
|
|
9
10
|
googleSearch: boolean;
|
|
10
11
|
searchThreshold: number;
|
package/lib/index.mjs
CHANGED
|
@@ -8,14 +8,14 @@ var __commonJS = (cb, mod) => function __require() {
|
|
|
8
8
|
// src/locales/zh-CN.schema.yml
|
|
9
9
|
var require_zh_CN_schema = __commonJS({
|
|
10
10
|
"src/locales/zh-CN.schema.yml"(exports, module) {
|
|
11
|
-
module.exports = { $inner: [{}, { $desc: "请求选项", apiKeys: { $inner: ["Gemini 的 API Key", "Gemini API 的请求地址"], $desc: "Gemini 的 API Key 和请求地址列表。" } }, { $desc: "模型配置", maxTokens: "输入的最大上下文 Token(16~2097000,必须是 16 的倍数)。注意:仅当您使用的模型最大 Token 为 8000 及以上时,才建议设置超过 2000 token。", temperature: "回复的随机性程度,数值越高,回复越随机(范围:0~2)。", googleSearch: "为模型启用谷歌搜索。", groundingContentDisplay: "是否显示谷歌搜索结果。", imageGeneration: "为模型启用图像生成。目前仅支持 `gemini-2.0-flash-exp` 模型。", searchThreshold: "搜索的置信度阈值,范围:0~1,设置的数值越低,则越倾向于使用谷歌搜索。" }] };
|
|
11
|
+
module.exports = { $inner: [{}, { $desc: "请求选项", platform: "适配器的平台名。(不懂请不要修改)", apiKeys: { $inner: ["Gemini 的 API Key", "Gemini API 的请求地址"], $desc: "Gemini 的 API Key 和请求地址列表。" } }, { $desc: "模型配置", maxTokens: "输入的最大上下文 Token(16~2097000,必须是 16 的倍数)。注意:仅当您使用的模型最大 Token 为 8000 及以上时,才建议设置超过 2000 token。", temperature: "回复的随机性程度,数值越高,回复越随机(范围:0~2)。", googleSearch: "为模型启用谷歌搜索。", groundingContentDisplay: "是否显示谷歌搜索结果。", imageGeneration: "为模型启用图像生成。目前仅支持 `gemini-2.0-flash-exp` 模型。", searchThreshold: "搜索的置信度阈值,范围:0~1,设置的数值越低,则越倾向于使用谷歌搜索。" }] };
|
|
12
12
|
}
|
|
13
13
|
});
|
|
14
14
|
|
|
15
15
|
// src/locales/en-US.schema.yml
|
|
16
16
|
var require_en_US_schema = __commonJS({
|
|
17
17
|
"src/locales/en-US.schema.yml"(exports, module) {
|
|
18
|
-
module.exports = { $inner: [{}, { $desc: "API Configuration", apiKeys: { $inner: ["Gemini API Key", "Gemini API Endpoint (optional)"], $desc: "Gemini API access credentials" } }, { $desc: "Model Parameters", maxTokens: "Max output tokens (16-2097000, multiple of 16). >2000 for 8k+ models", temperature: "Sampling temperature (0-2). Higher: more random, Lower: more deterministic", googleSearch: "Enable Google search", groundingContentDisplay: "Enable display of search results", imageGeneration: "Enable image generation (only for `gemini-2.0-flash-exp` model)", searchThreshold: "Search confidence [threshold](https://ai.google.dev/gemini-api/docs/grounding?lang=rest#dynamic-retrieval) (0-1). Lower: more likely to use Google search" }] };
|
|
18
|
+
module.exports = { $inner: [{}, { $desc: "API Configuration", platform: "Adapter platform name. (Do not modify if you do not understand)", apiKeys: { $inner: ["Gemini API Key", "Gemini API Endpoint (optional)"], $desc: "Gemini API access credentials" } }, { $desc: "Model Parameters", maxTokens: "Max output tokens (16-2097000, multiple of 16). >2000 for 8k+ models", temperature: "Sampling temperature (0-2). Higher: more random, Lower: more deterministic", googleSearch: "Enable Google search", groundingContentDisplay: "Enable display of search results", imageGeneration: "Enable image generation (only for `gemini-2.0-flash-exp` model)", searchThreshold: "Search confidence [threshold](https://ai.google.dev/gemini-api/docs/grounding?lang=rest#dynamic-retrieval) (0-1). Lower: more likely to use Google search" }] };
|
|
19
19
|
}
|
|
20
20
|
});
|
|
21
21
|
|
|
@@ -210,7 +210,12 @@ function formatToolsToGeminiAITools(tools, config, model) {
|
|
|
210
210
|
const unsupportedModels = [
|
|
211
211
|
"gemini-1.0",
|
|
212
212
|
"gemini-2.0-flash-lite",
|
|
213
|
-
"gemini-1.5-flash"
|
|
213
|
+
"gemini-1.5-flash",
|
|
214
|
+
"gemini-2.0-flash-exp"
|
|
215
|
+
];
|
|
216
|
+
const imageInputModels = [
|
|
217
|
+
"gemini-2.0-flash-exp",
|
|
218
|
+
"gemini-2.0-flash-exp-image-generation"
|
|
214
219
|
];
|
|
215
220
|
let googleSearch = config.googleSearch;
|
|
216
221
|
if (functions.length > 0 && !googleSearch) {
|
|
@@ -219,9 +224,11 @@ function formatToolsToGeminiAITools(tools, config, model) {
|
|
|
219
224
|
});
|
|
220
225
|
} else if (functions.length > 0 && googleSearch) {
|
|
221
226
|
logger.warn("Google search is enabled, tool calling will be disable.");
|
|
222
|
-
} else if (unsupportedModels.some(
|
|
227
|
+
} else if ((unsupportedModels.some(
|
|
223
228
|
(unsupportedModel) => model.includes(unsupportedModel)
|
|
224
|
-
)
|
|
229
|
+
) || imageInputModels.some(
|
|
230
|
+
(unsupportedModels2) => model.includes(unsupportedModels2)
|
|
231
|
+
) && config.imageGeneration) && googleSearch) {
|
|
225
232
|
logger.warn(
|
|
226
233
|
`The model ${model} does not support google search. google search will be disable.`
|
|
227
234
|
);
|
|
@@ -249,7 +256,9 @@ __name(formatToolsToGeminiAITools, "formatToolsToGeminiAITools");
|
|
|
249
256
|
function formatToolToGeminiAITool(tool) {
|
|
250
257
|
const parameters = removeAdditionalProperties(
|
|
251
258
|
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
|
252
|
-
zodToJsonSchema(tool.schema
|
|
259
|
+
zodToJsonSchema(tool.schema, {
|
|
260
|
+
allowedAdditionalProperties: void 0
|
|
261
|
+
})
|
|
253
262
|
);
|
|
254
263
|
return {
|
|
255
264
|
name: tool.name,
|
|
@@ -621,6 +630,7 @@ var GeminiClient = class extends PlatformModelAndEmbeddingsClient {
|
|
|
621
630
|
constructor(ctx, _config, clientConfig, plugin) {
|
|
622
631
|
super(ctx, clientConfig);
|
|
623
632
|
this._config = _config;
|
|
633
|
+
this.platform = this.config.platform;
|
|
624
634
|
this._requester = new GeminiRequester(
|
|
625
635
|
clientConfig,
|
|
626
636
|
plugin,
|
|
@@ -694,7 +704,7 @@ var GeminiClient = class extends PlatformModelAndEmbeddingsClient {
|
|
|
694
704
|
timeout: this._config.timeout,
|
|
695
705
|
temperature: this._config.temperature,
|
|
696
706
|
maxRetries: this._config.maxRetries,
|
|
697
|
-
llmType:
|
|
707
|
+
llmType: this.platform
|
|
698
708
|
});
|
|
699
709
|
}
|
|
700
710
|
return new ChatLunaEmbeddings({
|
|
@@ -709,7 +719,7 @@ var GeminiClient = class extends PlatformModelAndEmbeddingsClient {
|
|
|
709
719
|
import { createLogger } from "koishi-plugin-chatluna/utils/logger";
|
|
710
720
|
var logger;
|
|
711
721
|
function apply(ctx, config) {
|
|
712
|
-
const plugin = new ChatLunaPlugin(ctx, config,
|
|
722
|
+
const plugin = new ChatLunaPlugin(ctx, config, config.platform);
|
|
713
723
|
logger = createLogger(ctx, "chatluna-gemini-adapter");
|
|
714
724
|
ctx.on("ready", async () => {
|
|
715
725
|
plugin.registerToService();
|
|
@@ -718,7 +728,7 @@ function apply(ctx, config) {
|
|
|
718
728
|
return {
|
|
719
729
|
apiKey,
|
|
720
730
|
apiEndpoint,
|
|
721
|
-
platform:
|
|
731
|
+
platform: config2.platform,
|
|
722
732
|
chatLimit: config2.chatTimeLimit,
|
|
723
733
|
timeout: config2.timeout,
|
|
724
734
|
maxRetries: config2.maxRetries,
|
|
@@ -736,6 +746,7 @@ __name(apply, "apply");
|
|
|
736
746
|
var Config3 = Schema.intersect([
|
|
737
747
|
ChatLunaPlugin.Config,
|
|
738
748
|
Schema.object({
|
|
749
|
+
platform: Schema.string().default("gemini"),
|
|
739
750
|
apiKeys: Schema.array(
|
|
740
751
|
Schema.tuple([
|
|
741
752
|
Schema.string().role("secret"),
|
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.2.0-alpha.
|
|
4
|
+
"version": "1.2.0-alpha.2",
|
|
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.7",
|
|
75
|
-
"koishi-plugin-chatluna": "^1.2.0-alpha.
|
|
75
|
+
"koishi-plugin-chatluna": "^1.2.0-alpha.1"
|
|
76
76
|
},
|
|
77
77
|
"koishi": {
|
|
78
78
|
"description": {
|