koishi-plugin-chatluna-google-gemini-adapter 1.2.1 → 1.2.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 +31 -13
- package/lib/index.d.ts +3 -0
- package/lib/index.mjs +31 -13
- package/lib/utils.d.ts +1 -1
- 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: "请求选项", 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: "为模型启用谷歌搜索。", thinkingBudget: "思考预算,范围:
|
|
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: "为模型启用谷歌搜索。", thinkingBudget: "思考预算,范围:(-1~24576),设置的数值越大,思考时花费的 Token 越多,-1 为动态思考,0 为不思考。目前仅支持 gemini 2.5 系列模型。", groundingContentDisplay: "是否显示谷歌搜索结果。", imageGeneration: "为模型启用图像生成。目前仅支持 `gemini-2.0-flash-exp` 模型。", searchThreshold: "搜索的[置信度阈值](https://ai.google.dev/gemini-api/docs/grounding?lang=rest#dynamic-retrieval),范围:0~1,设置的数值越低,则越倾向于使用谷歌搜索。(仅支持 `gemini-1.5` 系列模型。gemini 2.0 模型起使用动态的工具调用)", includeThoughts: "是否获取模型的思考内容。", codeExecution: "为模型启用代码执行工具。", urlContext: "为模型启用 URL 内容获取工具。" }] };
|
|
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", 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", thinkingBudget: "Thinking budget (
|
|
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", thinkingBudget: "Thinking budget (-1-24576). (-1: dynamic thinking, 0: no thinking) Higher: more tokens spent on thinking. Currently only supports `gemini-2.5` series models.", 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", includeThoughts: "Enable retrieval of model thoughts", codeExecution: "Enable code execution tool", urlContext: "Enable URL context retrieval tool" }] };
|
|
44
44
|
}
|
|
45
45
|
});
|
|
46
46
|
|
|
@@ -235,21 +235,26 @@ function formatToolsToGeminiAITools(tools, config, model) {
|
|
|
235
235
|
"gemini-2.0-flash-exp-image-generation"
|
|
236
236
|
];
|
|
237
237
|
let googleSearch = config.googleSearch;
|
|
238
|
-
|
|
238
|
+
let codeExecution = config.codeExecution;
|
|
239
|
+
let urlContext = config.urlContext;
|
|
240
|
+
const useCustomTools = config.googleSearch || config.codeExecution || config.urlContext;
|
|
241
|
+
if (functions.length > 0 && !useCustomTools) {
|
|
239
242
|
result.push({
|
|
240
243
|
functionDeclarations: functions
|
|
241
244
|
});
|
|
242
|
-
} else if (functions.length > 0 &&
|
|
243
|
-
logger.warn("
|
|
245
|
+
} else if (functions.length > 0 && useCustomTools) {
|
|
246
|
+
logger.warn("Use custom tools instead of tool calls.");
|
|
244
247
|
} else if ((unsupportedModels.some(
|
|
245
248
|
(unsupportedModel) => model.includes(unsupportedModel)
|
|
246
249
|
) || imageGenerationModels.some(
|
|
247
250
|
(unsupportedModels2) => model.includes(unsupportedModels2)
|
|
248
|
-
) && config.imageGeneration) &&
|
|
251
|
+
) && config.imageGeneration) && useCustomTools) {
|
|
249
252
|
logger.warn(
|
|
250
253
|
`The model ${model} does not support google search. google search will be disable.`
|
|
251
254
|
);
|
|
252
255
|
googleSearch = false;
|
|
256
|
+
codeExecution = false;
|
|
257
|
+
urlContext = false;
|
|
253
258
|
}
|
|
254
259
|
if (googleSearch) {
|
|
255
260
|
if (model.includes("gemini-2")) {
|
|
@@ -267,6 +272,16 @@ function formatToolsToGeminiAITools(tools, config, model) {
|
|
|
267
272
|
});
|
|
268
273
|
}
|
|
269
274
|
}
|
|
275
|
+
if (codeExecution) {
|
|
276
|
+
result.push({
|
|
277
|
+
code_execution: {}
|
|
278
|
+
});
|
|
279
|
+
}
|
|
280
|
+
if (urlContext) {
|
|
281
|
+
result.push({
|
|
282
|
+
urlContext: {}
|
|
283
|
+
});
|
|
284
|
+
}
|
|
270
285
|
return result;
|
|
271
286
|
}
|
|
272
287
|
__name(formatToolsToGeminiAITools, "formatToolsToGeminiAITools");
|
|
@@ -381,12 +396,12 @@ var GeminiRequester = class extends import_api.ModelRequester {
|
|
|
381
396
|
// TODO: Wait for google release to all models
|
|
382
397
|
"gemini-2.0-flash-exp"
|
|
383
398
|
) && this._pluginConfig.imageGeneration ? ["TEXT", "IMAGE"] : void 0,
|
|
384
|
-
thinkingConfig: enabledThinking != null ? {
|
|
385
|
-
thinkingBudget: enabledThinking ? this._pluginConfig.thinkingBudget ??
|
|
386
|
-
|
|
399
|
+
thinkingConfig: enabledThinking != null || this._pluginConfig.includeThoughts ? {
|
|
400
|
+
thinkingBudget: enabledThinking ? this._pluginConfig.thinkingBudget ?? -1 : 0,
|
|
401
|
+
includeThoughts: this._pluginConfig.includeThoughts
|
|
387
402
|
} : void 0
|
|
388
403
|
},
|
|
389
|
-
tools: params.tools != null || this._pluginConfig.googleSearch ? formatToolsToGeminiAITools(
|
|
404
|
+
tools: params.tools != null || this._pluginConfig.googleSearch || this._pluginConfig.codeExecution || this._pluginConfig.urlContext ? formatToolsToGeminiAITools(
|
|
390
405
|
params.tools ?? [],
|
|
391
406
|
this._pluginConfig,
|
|
392
407
|
params.model
|
|
@@ -696,8 +711,8 @@ var GeminiClient = class extends import_client.PlatformModelAndEmbeddingsClient
|
|
|
696
711
|
if (model.name.includes("gemini-2.5")) {
|
|
697
712
|
if (!model.name.includes("-thinking")) {
|
|
698
713
|
models.push(
|
|
699
|
-
{ ...info, name: model + "-no-thinking" },
|
|
700
|
-
{ ...info, name: model + "-thinking" },
|
|
714
|
+
{ ...info, name: model.name + "-no-thinking" },
|
|
715
|
+
{ ...info, name: model.name + "-thinking" },
|
|
701
716
|
info
|
|
702
717
|
);
|
|
703
718
|
} else {
|
|
@@ -794,7 +809,10 @@ var Config3 = import_koishi.Schema.intersect([
|
|
|
794
809
|
maxTokens: import_koishi.Schema.number().min(16).max(2097e3).step(16).default(8064),
|
|
795
810
|
temperature: import_koishi.Schema.percent().min(0).max(2).step(0.1).default(0.8),
|
|
796
811
|
googleSearch: import_koishi.Schema.boolean().default(false),
|
|
797
|
-
|
|
812
|
+
codeExecution: import_koishi.Schema.boolean().default(false),
|
|
813
|
+
urlContext: import_koishi.Schema.boolean().default(false),
|
|
814
|
+
thinkingBudget: import_koishi.Schema.number().min(-1).max(24576).step(16).default(-1),
|
|
815
|
+
includeThoughts: import_koishi.Schema.boolean().default(false),
|
|
798
816
|
imageGeneration: import_koishi.Schema.boolean().default(false),
|
|
799
817
|
groundingContentDisplay: import_koishi.Schema.boolean().default(false),
|
|
800
818
|
searchThreshold: import_koishi.Schema.number().min(0).max(1).step(0.1).default(0.5)
|
package/lib/index.d.ts
CHANGED
|
@@ -9,10 +9,13 @@ export interface Config extends ChatLunaPlugin.Config {
|
|
|
9
9
|
platform: string;
|
|
10
10
|
temperature: number;
|
|
11
11
|
googleSearch: boolean;
|
|
12
|
+
codeExecution: boolean;
|
|
13
|
+
urlContext: boolean;
|
|
12
14
|
searchThreshold: number;
|
|
13
15
|
groundingContentDisplay: boolean;
|
|
14
16
|
imageGeneration: boolean;
|
|
15
17
|
thinkingBudget: number;
|
|
18
|
+
includeThoughts: boolean;
|
|
16
19
|
}
|
|
17
20
|
export declare const Config: Schema<Config>;
|
|
18
21
|
export declare const inject: string[];
|
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: "请求选项", 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: "为模型启用谷歌搜索。", thinkingBudget: "思考预算,范围:
|
|
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: "为模型启用谷歌搜索。", thinkingBudget: "思考预算,范围:(-1~24576),设置的数值越大,思考时花费的 Token 越多,-1 为动态思考,0 为不思考。目前仅支持 gemini 2.5 系列模型。", groundingContentDisplay: "是否显示谷歌搜索结果。", imageGeneration: "为模型启用图像生成。目前仅支持 `gemini-2.0-flash-exp` 模型。", searchThreshold: "搜索的[置信度阈值](https://ai.google.dev/gemini-api/docs/grounding?lang=rest#dynamic-retrieval),范围:0~1,设置的数值越低,则越倾向于使用谷歌搜索。(仅支持 `gemini-1.5` 系列模型。gemini 2.0 模型起使用动态的工具调用)", includeThoughts: "是否获取模型的思考内容。", codeExecution: "为模型启用代码执行工具。", urlContext: "为模型启用 URL 内容获取工具。" }] };
|
|
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", 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", thinkingBudget: "Thinking budget (
|
|
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", thinkingBudget: "Thinking budget (-1-24576). (-1: dynamic thinking, 0: no thinking) Higher: more tokens spent on thinking. Currently only supports `gemini-2.5` series models.", 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", includeThoughts: "Enable retrieval of model thoughts", codeExecution: "Enable code execution tool", urlContext: "Enable URL context retrieval tool" }] };
|
|
19
19
|
}
|
|
20
20
|
});
|
|
21
21
|
|
|
@@ -218,21 +218,26 @@ function formatToolsToGeminiAITools(tools, config, model) {
|
|
|
218
218
|
"gemini-2.0-flash-exp-image-generation"
|
|
219
219
|
];
|
|
220
220
|
let googleSearch = config.googleSearch;
|
|
221
|
-
|
|
221
|
+
let codeExecution = config.codeExecution;
|
|
222
|
+
let urlContext = config.urlContext;
|
|
223
|
+
const useCustomTools = config.googleSearch || config.codeExecution || config.urlContext;
|
|
224
|
+
if (functions.length > 0 && !useCustomTools) {
|
|
222
225
|
result.push({
|
|
223
226
|
functionDeclarations: functions
|
|
224
227
|
});
|
|
225
|
-
} else if (functions.length > 0 &&
|
|
226
|
-
logger.warn("
|
|
228
|
+
} else if (functions.length > 0 && useCustomTools) {
|
|
229
|
+
logger.warn("Use custom tools instead of tool calls.");
|
|
227
230
|
} else if ((unsupportedModels.some(
|
|
228
231
|
(unsupportedModel) => model.includes(unsupportedModel)
|
|
229
232
|
) || imageGenerationModels.some(
|
|
230
233
|
(unsupportedModels2) => model.includes(unsupportedModels2)
|
|
231
|
-
) && config.imageGeneration) &&
|
|
234
|
+
) && config.imageGeneration) && useCustomTools) {
|
|
232
235
|
logger.warn(
|
|
233
236
|
`The model ${model} does not support google search. google search will be disable.`
|
|
234
237
|
);
|
|
235
238
|
googleSearch = false;
|
|
239
|
+
codeExecution = false;
|
|
240
|
+
urlContext = false;
|
|
236
241
|
}
|
|
237
242
|
if (googleSearch) {
|
|
238
243
|
if (model.includes("gemini-2")) {
|
|
@@ -250,6 +255,16 @@ function formatToolsToGeminiAITools(tools, config, model) {
|
|
|
250
255
|
});
|
|
251
256
|
}
|
|
252
257
|
}
|
|
258
|
+
if (codeExecution) {
|
|
259
|
+
result.push({
|
|
260
|
+
code_execution: {}
|
|
261
|
+
});
|
|
262
|
+
}
|
|
263
|
+
if (urlContext) {
|
|
264
|
+
result.push({
|
|
265
|
+
urlContext: {}
|
|
266
|
+
});
|
|
267
|
+
}
|
|
253
268
|
return result;
|
|
254
269
|
}
|
|
255
270
|
__name(formatToolsToGeminiAITools, "formatToolsToGeminiAITools");
|
|
@@ -364,12 +379,12 @@ var GeminiRequester = class extends ModelRequester {
|
|
|
364
379
|
// TODO: Wait for google release to all models
|
|
365
380
|
"gemini-2.0-flash-exp"
|
|
366
381
|
) && this._pluginConfig.imageGeneration ? ["TEXT", "IMAGE"] : void 0,
|
|
367
|
-
thinkingConfig: enabledThinking != null ? {
|
|
368
|
-
thinkingBudget: enabledThinking ? this._pluginConfig.thinkingBudget ??
|
|
369
|
-
|
|
382
|
+
thinkingConfig: enabledThinking != null || this._pluginConfig.includeThoughts ? {
|
|
383
|
+
thinkingBudget: enabledThinking ? this._pluginConfig.thinkingBudget ?? -1 : 0,
|
|
384
|
+
includeThoughts: this._pluginConfig.includeThoughts
|
|
370
385
|
} : void 0
|
|
371
386
|
},
|
|
372
|
-
tools: params.tools != null || this._pluginConfig.googleSearch ? formatToolsToGeminiAITools(
|
|
387
|
+
tools: params.tools != null || this._pluginConfig.googleSearch || this._pluginConfig.codeExecution || this._pluginConfig.urlContext ? formatToolsToGeminiAITools(
|
|
373
388
|
params.tools ?? [],
|
|
374
389
|
this._pluginConfig,
|
|
375
390
|
params.model
|
|
@@ -679,8 +694,8 @@ var GeminiClient = class extends PlatformModelAndEmbeddingsClient {
|
|
|
679
694
|
if (model.name.includes("gemini-2.5")) {
|
|
680
695
|
if (!model.name.includes("-thinking")) {
|
|
681
696
|
models.push(
|
|
682
|
-
{ ...info, name: model + "-no-thinking" },
|
|
683
|
-
{ ...info, name: model + "-thinking" },
|
|
697
|
+
{ ...info, name: model.name + "-no-thinking" },
|
|
698
|
+
{ ...info, name: model.name + "-thinking" },
|
|
684
699
|
info
|
|
685
700
|
);
|
|
686
701
|
} else {
|
|
@@ -777,7 +792,10 @@ var Config3 = Schema.intersect([
|
|
|
777
792
|
maxTokens: Schema.number().min(16).max(2097e3).step(16).default(8064),
|
|
778
793
|
temperature: Schema.percent().min(0).max(2).step(0.1).default(0.8),
|
|
779
794
|
googleSearch: Schema.boolean().default(false),
|
|
780
|
-
|
|
795
|
+
codeExecution: Schema.boolean().default(false),
|
|
796
|
+
urlContext: Schema.boolean().default(false),
|
|
797
|
+
thinkingBudget: Schema.number().min(-1).max(24576).step(16).default(-1),
|
|
798
|
+
includeThoughts: Schema.boolean().default(false),
|
|
781
799
|
imageGeneration: Schema.boolean().default(false),
|
|
782
800
|
groundingContentDisplay: Schema.boolean().default(false),
|
|
783
801
|
searchThreshold: Schema.number().min(0).max(1).step(0.1).default(0.5)
|
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): HumanMessageChunk | AIMessageChunk | 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.2.
|
|
4
|
+
"version": "1.2.3",
|
|
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.3.0-alpha.
|
|
75
|
+
"koishi-plugin-chatluna": "^1.3.0-alpha.2"
|
|
76
76
|
},
|
|
77
77
|
"koishi": {
|
|
78
78
|
"description": {
|