koishi-plugin-chatluna-google-gemini-adapter 1.2.0-alpha.1 → 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 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
- ) && googleSearch) {
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
  );
@@ -639,6 +646,7 @@ var GeminiClient = class extends import_client.PlatformModelAndEmbeddingsClient
639
646
  constructor(ctx, _config, clientConfig, plugin) {
640
647
  super(ctx, clientConfig);
641
648
  this._config = _config;
649
+ this.platform = this.config.platform;
642
650
  this._requester = new GeminiRequester(
643
651
  clientConfig,
644
652
  plugin,
@@ -712,7 +720,7 @@ var GeminiClient = class extends import_client.PlatformModelAndEmbeddingsClient
712
720
  timeout: this._config.timeout,
713
721
  temperature: this._config.temperature,
714
722
  maxRetries: this._config.maxRetries,
715
- llmType: "gemini"
723
+ llmType: this.platform
716
724
  });
717
725
  }
718
726
  return new import_model.ChatLunaEmbeddings({
@@ -727,7 +735,7 @@ var GeminiClient = class extends import_client.PlatformModelAndEmbeddingsClient
727
735
  var import_logger = require("koishi-plugin-chatluna/utils/logger");
728
736
  var logger;
729
737
  function apply(ctx, config) {
730
- const plugin = new import_chat.ChatLunaPlugin(ctx, config, "gemini");
738
+ const plugin = new import_chat.ChatLunaPlugin(ctx, config, config.platform);
731
739
  logger = (0, import_logger.createLogger)(ctx, "chatluna-gemini-adapter");
732
740
  ctx.on("ready", async () => {
733
741
  plugin.registerToService();
@@ -736,7 +744,7 @@ function apply(ctx, config) {
736
744
  return {
737
745
  apiKey,
738
746
  apiEndpoint,
739
- platform: "gemini",
747
+ platform: config2.platform,
740
748
  chatLimit: config2.chatTimeLimit,
741
749
  timeout: config2.timeout,
742
750
  maxRetries: config2.maxRetries,
@@ -754,6 +762,7 @@ __name(apply, "apply");
754
762
  var Config3 = import_koishi.Schema.intersect([
755
763
  import_chat.ChatLunaPlugin.Config,
756
764
  import_koishi.Schema.object({
765
+ platform: import_koishi.Schema.string().default("gemini"),
757
766
  apiKeys: import_koishi.Schema.array(
758
767
  import_koishi.Schema.tuple([
759
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
- ) && googleSearch) {
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
  );
@@ -623,6 +630,7 @@ var GeminiClient = class extends PlatformModelAndEmbeddingsClient {
623
630
  constructor(ctx, _config, clientConfig, plugin) {
624
631
  super(ctx, clientConfig);
625
632
  this._config = _config;
633
+ this.platform = this.config.platform;
626
634
  this._requester = new GeminiRequester(
627
635
  clientConfig,
628
636
  plugin,
@@ -696,7 +704,7 @@ var GeminiClient = class extends PlatformModelAndEmbeddingsClient {
696
704
  timeout: this._config.timeout,
697
705
  temperature: this._config.temperature,
698
706
  maxRetries: this._config.maxRetries,
699
- llmType: "gemini"
707
+ llmType: this.platform
700
708
  });
701
709
  }
702
710
  return new ChatLunaEmbeddings({
@@ -711,7 +719,7 @@ var GeminiClient = class extends PlatformModelAndEmbeddingsClient {
711
719
  import { createLogger } from "koishi-plugin-chatluna/utils/logger";
712
720
  var logger;
713
721
  function apply(ctx, config) {
714
- const plugin = new ChatLunaPlugin(ctx, config, "gemini");
722
+ const plugin = new ChatLunaPlugin(ctx, config, config.platform);
715
723
  logger = createLogger(ctx, "chatluna-gemini-adapter");
716
724
  ctx.on("ready", async () => {
717
725
  plugin.registerToService();
@@ -720,7 +728,7 @@ function apply(ctx, config) {
720
728
  return {
721
729
  apiKey,
722
730
  apiEndpoint,
723
- platform: "gemini",
731
+ platform: config2.platform,
724
732
  chatLimit: config2.chatTimeLimit,
725
733
  timeout: config2.timeout,
726
734
  maxRetries: config2.maxRetries,
@@ -738,6 +746,7 @@ __name(apply, "apply");
738
746
  var Config3 = Schema.intersect([
739
747
  ChatLunaPlugin.Config,
740
748
  Schema.object({
749
+ platform: Schema.string().default("gemini"),
741
750
  apiKeys: Schema.array(
742
751
  Schema.tuple([
743
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.1",
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",