koishi-plugin-chatluna-google-gemini-adapter 1.2.0-alpha.1 → 1.2.0-alpha.3
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 +22 -10
- package/lib/index.d.ts +2 -0
- package/lib/index.mjs +20 -9
- package/package.json +1 -1
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
|
|
|
@@ -51,7 +51,8 @@ __export(index_exports, {
|
|
|
51
51
|
apply: () => apply,
|
|
52
52
|
inject: () => inject,
|
|
53
53
|
logger: () => logger,
|
|
54
|
-
name: () => name
|
|
54
|
+
name: () => name,
|
|
55
|
+
reusable: () => reusable
|
|
55
56
|
});
|
|
56
57
|
module.exports = __toCommonJS(index_exports);
|
|
57
58
|
var import_chat = require("koishi-plugin-chatluna/services/chat");
|
|
@@ -226,7 +227,12 @@ function formatToolsToGeminiAITools(tools, config, model) {
|
|
|
226
227
|
const unsupportedModels = [
|
|
227
228
|
"gemini-1.0",
|
|
228
229
|
"gemini-2.0-flash-lite",
|
|
229
|
-
"gemini-1.5-flash"
|
|
230
|
+
"gemini-1.5-flash",
|
|
231
|
+
"gemini-2.0-flash-exp"
|
|
232
|
+
];
|
|
233
|
+
const imageInputModels = [
|
|
234
|
+
"gemini-2.0-flash-exp",
|
|
235
|
+
"gemini-2.0-flash-exp-image-generation"
|
|
230
236
|
];
|
|
231
237
|
let googleSearch = config.googleSearch;
|
|
232
238
|
if (functions.length > 0 && !googleSearch) {
|
|
@@ -235,9 +241,11 @@ function formatToolsToGeminiAITools(tools, config, model) {
|
|
|
235
241
|
});
|
|
236
242
|
} else if (functions.length > 0 && googleSearch) {
|
|
237
243
|
logger.warn("Google search is enabled, tool calling will be disable.");
|
|
238
|
-
} else if (unsupportedModels.some(
|
|
244
|
+
} else if ((unsupportedModels.some(
|
|
239
245
|
(unsupportedModel) => model.includes(unsupportedModel)
|
|
240
|
-
)
|
|
246
|
+
) || imageInputModels.some(
|
|
247
|
+
(unsupportedModels2) => model.includes(unsupportedModels2)
|
|
248
|
+
) && config.imageGeneration) && googleSearch) {
|
|
241
249
|
logger.warn(
|
|
242
250
|
`The model ${model} does not support google search. google search will be disable.`
|
|
243
251
|
);
|
|
@@ -639,6 +647,7 @@ var GeminiClient = class extends import_client.PlatformModelAndEmbeddingsClient
|
|
|
639
647
|
constructor(ctx, _config, clientConfig, plugin) {
|
|
640
648
|
super(ctx, clientConfig);
|
|
641
649
|
this._config = _config;
|
|
650
|
+
this.platform = this.config.platform;
|
|
642
651
|
this._requester = new GeminiRequester(
|
|
643
652
|
clientConfig,
|
|
644
653
|
plugin,
|
|
@@ -712,7 +721,7 @@ var GeminiClient = class extends import_client.PlatformModelAndEmbeddingsClient
|
|
|
712
721
|
timeout: this._config.timeout,
|
|
713
722
|
temperature: this._config.temperature,
|
|
714
723
|
maxRetries: this._config.maxRetries,
|
|
715
|
-
llmType:
|
|
724
|
+
llmType: this.platform
|
|
716
725
|
});
|
|
717
726
|
}
|
|
718
727
|
return new import_model.ChatLunaEmbeddings({
|
|
@@ -726,8 +735,9 @@ var GeminiClient = class extends import_client.PlatformModelAndEmbeddingsClient
|
|
|
726
735
|
// src/index.ts
|
|
727
736
|
var import_logger = require("koishi-plugin-chatluna/utils/logger");
|
|
728
737
|
var logger;
|
|
738
|
+
var reusable = true;
|
|
729
739
|
function apply(ctx, config) {
|
|
730
|
-
const plugin = new import_chat.ChatLunaPlugin(ctx, config,
|
|
740
|
+
const plugin = new import_chat.ChatLunaPlugin(ctx, config, config.platform);
|
|
731
741
|
logger = (0, import_logger.createLogger)(ctx, "chatluna-gemini-adapter");
|
|
732
742
|
ctx.on("ready", async () => {
|
|
733
743
|
plugin.registerToService();
|
|
@@ -736,7 +746,7 @@ function apply(ctx, config) {
|
|
|
736
746
|
return {
|
|
737
747
|
apiKey,
|
|
738
748
|
apiEndpoint,
|
|
739
|
-
platform:
|
|
749
|
+
platform: config2.platform,
|
|
740
750
|
chatLimit: config2.chatTimeLimit,
|
|
741
751
|
timeout: config2.timeout,
|
|
742
752
|
maxRetries: config2.maxRetries,
|
|
@@ -754,6 +764,7 @@ __name(apply, "apply");
|
|
|
754
764
|
var Config3 = import_koishi.Schema.intersect([
|
|
755
765
|
import_chat.ChatLunaPlugin.Config,
|
|
756
766
|
import_koishi.Schema.object({
|
|
767
|
+
platform: import_koishi.Schema.string().default("gemini"),
|
|
757
768
|
apiKeys: import_koishi.Schema.array(
|
|
758
769
|
import_koishi.Schema.tuple([
|
|
759
770
|
import_koishi.Schema.string().role("secret"),
|
|
@@ -784,5 +795,6 @@ var name = "chatluna-google-gemini-adapter";
|
|
|
784
795
|
apply,
|
|
785
796
|
inject,
|
|
786
797
|
logger,
|
|
787
|
-
name
|
|
798
|
+
name,
|
|
799
|
+
reusable
|
|
788
800
|
});
|
package/lib/index.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
import { ChatLunaPlugin } from 'koishi-plugin-chatluna/services/chat';
|
|
2
2
|
import { Context, Logger, Schema } from 'koishi';
|
|
3
3
|
export declare let logger: Logger;
|
|
4
|
+
export declare const reusable = true;
|
|
4
5
|
export declare function apply(ctx: Context, config: Config): void;
|
|
5
6
|
export interface Config extends ChatLunaPlugin.Config {
|
|
6
7
|
apiKeys: [string, string][];
|
|
7
8
|
maxTokens: number;
|
|
9
|
+
platform: string;
|
|
8
10
|
temperature: number;
|
|
9
11
|
googleSearch: boolean;
|
|
10
12
|
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
|
);
|
|
@@ -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:
|
|
707
|
+
llmType: this.platform
|
|
700
708
|
});
|
|
701
709
|
}
|
|
702
710
|
return new ChatLunaEmbeddings({
|
|
@@ -710,8 +718,9 @@ var GeminiClient = class extends PlatformModelAndEmbeddingsClient {
|
|
|
710
718
|
// src/index.ts
|
|
711
719
|
import { createLogger } from "koishi-plugin-chatluna/utils/logger";
|
|
712
720
|
var logger;
|
|
721
|
+
var reusable = true;
|
|
713
722
|
function apply(ctx, config) {
|
|
714
|
-
const plugin = new ChatLunaPlugin(ctx, config,
|
|
723
|
+
const plugin = new ChatLunaPlugin(ctx, config, config.platform);
|
|
715
724
|
logger = createLogger(ctx, "chatluna-gemini-adapter");
|
|
716
725
|
ctx.on("ready", async () => {
|
|
717
726
|
plugin.registerToService();
|
|
@@ -720,7 +729,7 @@ function apply(ctx, config) {
|
|
|
720
729
|
return {
|
|
721
730
|
apiKey,
|
|
722
731
|
apiEndpoint,
|
|
723
|
-
platform:
|
|
732
|
+
platform: config2.platform,
|
|
724
733
|
chatLimit: config2.chatTimeLimit,
|
|
725
734
|
timeout: config2.timeout,
|
|
726
735
|
maxRetries: config2.maxRetries,
|
|
@@ -738,6 +747,7 @@ __name(apply, "apply");
|
|
|
738
747
|
var Config3 = Schema.intersect([
|
|
739
748
|
ChatLunaPlugin.Config,
|
|
740
749
|
Schema.object({
|
|
750
|
+
platform: Schema.string().default("gemini"),
|
|
741
751
|
apiKeys: Schema.array(
|
|
742
752
|
Schema.tuple([
|
|
743
753
|
Schema.string().role("secret"),
|
|
@@ -767,5 +777,6 @@ export {
|
|
|
767
777
|
apply,
|
|
768
778
|
inject,
|
|
769
779
|
logger,
|
|
770
|
-
name
|
|
780
|
+
name,
|
|
781
|
+
reusable
|
|
771
782
|
};
|
package/package.json
CHANGED