koishi-plugin-chatluna-google-gemini-adapter 1.0.0-beta.27 → 1.0.0-beta.28
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 +49 -13
- package/lib/index.d.ts +5 -2
- package/lib/index.mjs +49 -13
- package/package.json +2 -2
package/lib/index.cjs
CHANGED
|
@@ -23,21 +23,21 @@ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: tru
|
|
|
23
23
|
// src/locales/zh-CN.schema.yml
|
|
24
24
|
var require_zh_CN_schema = __commonJS({
|
|
25
25
|
"src/locales/zh-CN.schema.yml"(exports2, module2) {
|
|
26
|
-
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)。" }] };
|
|
26
|
+
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: "为模型启用谷歌搜索。", searchThreshold: "搜索的置信度阈值,范围:0~1,设置的数值越低,则越倾向于使用谷歌搜索。" }] };
|
|
27
27
|
}
|
|
28
28
|
});
|
|
29
29
|
|
|
30
30
|
// src/locales/en-US.schema.yml
|
|
31
31
|
var require_en_US_schema = __commonJS({
|
|
32
32
|
"src/locales/en-US.schema.yml"(exports2, module2) {
|
|
33
|
-
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" }] };
|
|
33
|
+
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", 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" }] };
|
|
34
34
|
}
|
|
35
35
|
});
|
|
36
36
|
|
|
37
37
|
// src/index.ts
|
|
38
38
|
var src_exports = {};
|
|
39
39
|
__export(src_exports, {
|
|
40
|
-
Config: () =>
|
|
40
|
+
Config: () => Config3,
|
|
41
41
|
apply: () => apply,
|
|
42
42
|
inject: () => inject,
|
|
43
43
|
logger: () => logger,
|
|
@@ -237,11 +237,38 @@ function partAsType(part) {
|
|
|
237
237
|
return part;
|
|
238
238
|
}
|
|
239
239
|
__name(partAsType, "partAsType");
|
|
240
|
-
function formatToolsToGeminiAITools(tools) {
|
|
241
|
-
if (tools.length < 1) {
|
|
240
|
+
function formatToolsToGeminiAITools(tools, config, model) {
|
|
241
|
+
if (tools.length < 1 && !config.googleSearch) {
|
|
242
242
|
return void 0;
|
|
243
243
|
}
|
|
244
|
-
|
|
244
|
+
const functions = tools.map(formatToolToGeminiAITool);
|
|
245
|
+
const result = [];
|
|
246
|
+
if (functions.length > 0 && !config.googleSearch) {
|
|
247
|
+
result.push({
|
|
248
|
+
functionDeclarations: functions
|
|
249
|
+
});
|
|
250
|
+
} else if (functions.length > 0 && config.googleSearch) {
|
|
251
|
+
logger.warn(
|
|
252
|
+
"Google search is enabled, function calls will be disabled."
|
|
253
|
+
);
|
|
254
|
+
}
|
|
255
|
+
if (config.googleSearch) {
|
|
256
|
+
if (model.includes("gemini-2")) {
|
|
257
|
+
result.push({
|
|
258
|
+
google_search: {}
|
|
259
|
+
});
|
|
260
|
+
} else {
|
|
261
|
+
result.push({
|
|
262
|
+
google_search_retrieval: {
|
|
263
|
+
dynamic_retrieval_config: {
|
|
264
|
+
mode: "MODE_DYNAMIC",
|
|
265
|
+
dynamic_threshold: config.searchThreshold
|
|
266
|
+
}
|
|
267
|
+
}
|
|
268
|
+
});
|
|
269
|
+
}
|
|
270
|
+
}
|
|
271
|
+
return result;
|
|
245
272
|
}
|
|
246
273
|
__name(formatToolsToGeminiAITools, "formatToolsToGeminiAITools");
|
|
247
274
|
function formatToolToGeminiAITool(tool) {
|
|
@@ -274,10 +301,11 @@ __name(messageTypeToGeminiRole, "messageTypeToGeminiRole");
|
|
|
274
301
|
|
|
275
302
|
// src/requester.ts
|
|
276
303
|
var GeminiRequester = class extends import_api.ModelRequester {
|
|
277
|
-
constructor(_config, _plugin) {
|
|
304
|
+
constructor(_config, _plugin, _pluginConfig) {
|
|
278
305
|
super();
|
|
279
306
|
this._config = _config;
|
|
280
307
|
this._plugin = _plugin;
|
|
308
|
+
this._pluginConfig = _pluginConfig;
|
|
281
309
|
}
|
|
282
310
|
static {
|
|
283
311
|
__name(this, "GeminiRequester");
|
|
@@ -315,9 +343,11 @@ var GeminiRequester = class extends import_api.ModelRequester {
|
|
|
315
343
|
maxOutputTokens: params.model.includes("vision") ? void 0 : params.maxTokens,
|
|
316
344
|
topP: params.topP
|
|
317
345
|
},
|
|
318
|
-
tools:
|
|
319
|
-
|
|
320
|
-
|
|
346
|
+
tools: params.tools != null || this._pluginConfig.googleSearch ? formatToolsToGeminiAITools(
|
|
347
|
+
params.tools ?? [],
|
|
348
|
+
this._pluginConfig,
|
|
349
|
+
params.model
|
|
350
|
+
) : void 0
|
|
321
351
|
},
|
|
322
352
|
{
|
|
323
353
|
signal: params.signal
|
|
@@ -543,7 +573,11 @@ var GeminiClient = class extends import_client.PlatformModelAndEmbeddingsClient
|
|
|
543
573
|
constructor(ctx, _config, clientConfig, plugin) {
|
|
544
574
|
super(ctx, clientConfig);
|
|
545
575
|
this._config = _config;
|
|
546
|
-
this._requester = new GeminiRequester(
|
|
576
|
+
this._requester = new GeminiRequester(
|
|
577
|
+
clientConfig,
|
|
578
|
+
plugin,
|
|
579
|
+
this._config
|
|
580
|
+
);
|
|
547
581
|
}
|
|
548
582
|
static {
|
|
549
583
|
__name(this, "GeminiClient");
|
|
@@ -651,7 +685,7 @@ function apply(ctx, config) {
|
|
|
651
685
|
});
|
|
652
686
|
}
|
|
653
687
|
__name(apply, "apply");
|
|
654
|
-
var
|
|
688
|
+
var Config3 = import_koishi.Schema.intersect([
|
|
655
689
|
import_chat.ChatLunaPlugin.Config,
|
|
656
690
|
import_koishi.Schema.object({
|
|
657
691
|
apiKeys: import_koishi.Schema.array(
|
|
@@ -665,7 +699,9 @@ var Config = import_koishi.Schema.intersect([
|
|
|
665
699
|
}),
|
|
666
700
|
import_koishi.Schema.object({
|
|
667
701
|
maxTokens: import_koishi.Schema.number().min(16).max(2097e3).step(16).default(8064),
|
|
668
|
-
temperature: import_koishi.Schema.percent().min(0).max(2).step(0.1).default(0.8)
|
|
702
|
+
temperature: import_koishi.Schema.percent().min(0).max(2).step(0.1).default(0.8),
|
|
703
|
+
googleSearch: import_koishi.Schema.boolean().default(false),
|
|
704
|
+
searchThreshold: import_koishi.Schema.number().min(0).max(1).step(0.1).default(0.5)
|
|
669
705
|
})
|
|
670
706
|
]).i18n({
|
|
671
707
|
"zh-CN": require_zh_CN_schema(),
|
package/lib/index.d.ts
CHANGED
|
@@ -14,6 +14,8 @@ export interface Config extends ChatLunaPlugin.Config {
|
|
|
14
14
|
apiKeys: [string, string][];
|
|
15
15
|
maxTokens: number;
|
|
16
16
|
temperature: number;
|
|
17
|
+
googleSearch: boolean;
|
|
18
|
+
searchThreshold: number;
|
|
17
19
|
}
|
|
18
20
|
export const Config: Schema<Config>;
|
|
19
21
|
export const inject: string[];
|
|
@@ -80,14 +82,15 @@ export interface CreateEmbeddingResponse {
|
|
|
80
82
|
export type ChatCompletionResponseMessageRoleEnum = 'system' | 'model' | 'user' | 'function';
|
|
81
83
|
export function langchainMessageToGeminiMessage(messages: BaseMessage[], model?: string): Promise<ChatCompletionResponseMessage[]>;
|
|
82
84
|
export function partAsType<T extends ChatPart>(part: ChatPart): T;
|
|
83
|
-
export function formatToolsToGeminiAITools(tools: StructuredTool[]):
|
|
85
|
+
export function formatToolsToGeminiAITools(tools: StructuredTool[], config: Config, model: string): Record<string, any>;
|
|
84
86
|
export function formatToolToGeminiAITool(tool: StructuredTool): ChatCompletionFunction;
|
|
85
87
|
export function messageTypeToGeminiRole(type: MessageType): ChatCompletionResponseMessageRoleEnum;
|
|
86
88
|
export function convertDeltaToMessageChunk(delta: Record<string, any>, defaultRole?: ChatCompletionResponseMessageRoleEnum): HumanMessageChunk | AIMessageChunk | SystemMessageChunk | ChatMessageChunk;
|
|
87
89
|
export class GeminiRequester extends ModelRequester implements EmbeddingsRequester {
|
|
88
90
|
private _config;
|
|
89
91
|
private _plugin;
|
|
90
|
-
|
|
92
|
+
private _pluginConfig;
|
|
93
|
+
constructor(_config: ClientConfig, _plugin: ChatLunaPlugin, _pluginConfig: Config);
|
|
91
94
|
completionStream(params: ModelRequestParams): AsyncGenerator<ChatGenerationChunk>;
|
|
92
95
|
embeddings(params: EmbeddingsRequestParams): Promise<number[] | number[][]>;
|
|
93
96
|
getModels(): Promise<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: "请求选项", apiKeys: { $inner: ["Gemini 的 API Key", "Gemini API 的请求地址"], $desc: "Gemini 的 API Key 和请求地址列表。" } }, { $desc: "模型配置", maxTokens: "回复的最大 Token 数(16~2097000,必须是 16 的倍数)。注意:仅当您使用的模型最大 Token 为 8000 及以上时,才建议设置超过 2000 token。", temperature: "回复的随机性程度,数值越高,回复越随机(范围:0~2)。" }] };
|
|
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: "为模型启用谷歌搜索。", 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" }] };
|
|
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", 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
|
|
|
@@ -231,11 +231,38 @@ function partAsType(part) {
|
|
|
231
231
|
return part;
|
|
232
232
|
}
|
|
233
233
|
__name(partAsType, "partAsType");
|
|
234
|
-
function formatToolsToGeminiAITools(tools) {
|
|
235
|
-
if (tools.length < 1) {
|
|
234
|
+
function formatToolsToGeminiAITools(tools, config, model) {
|
|
235
|
+
if (tools.length < 1 && !config.googleSearch) {
|
|
236
236
|
return void 0;
|
|
237
237
|
}
|
|
238
|
-
|
|
238
|
+
const functions = tools.map(formatToolToGeminiAITool);
|
|
239
|
+
const result = [];
|
|
240
|
+
if (functions.length > 0 && !config.googleSearch) {
|
|
241
|
+
result.push({
|
|
242
|
+
functionDeclarations: functions
|
|
243
|
+
});
|
|
244
|
+
} else if (functions.length > 0 && config.googleSearch) {
|
|
245
|
+
logger.warn(
|
|
246
|
+
"Google search is enabled, function calls will be disabled."
|
|
247
|
+
);
|
|
248
|
+
}
|
|
249
|
+
if (config.googleSearch) {
|
|
250
|
+
if (model.includes("gemini-2")) {
|
|
251
|
+
result.push({
|
|
252
|
+
google_search: {}
|
|
253
|
+
});
|
|
254
|
+
} else {
|
|
255
|
+
result.push({
|
|
256
|
+
google_search_retrieval: {
|
|
257
|
+
dynamic_retrieval_config: {
|
|
258
|
+
mode: "MODE_DYNAMIC",
|
|
259
|
+
dynamic_threshold: config.searchThreshold
|
|
260
|
+
}
|
|
261
|
+
}
|
|
262
|
+
});
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
return result;
|
|
239
266
|
}
|
|
240
267
|
__name(formatToolsToGeminiAITools, "formatToolsToGeminiAITools");
|
|
241
268
|
function formatToolToGeminiAITool(tool) {
|
|
@@ -268,10 +295,11 @@ __name(messageTypeToGeminiRole, "messageTypeToGeminiRole");
|
|
|
268
295
|
|
|
269
296
|
// src/requester.ts
|
|
270
297
|
var GeminiRequester = class extends ModelRequester {
|
|
271
|
-
constructor(_config, _plugin) {
|
|
298
|
+
constructor(_config, _plugin, _pluginConfig) {
|
|
272
299
|
super();
|
|
273
300
|
this._config = _config;
|
|
274
301
|
this._plugin = _plugin;
|
|
302
|
+
this._pluginConfig = _pluginConfig;
|
|
275
303
|
}
|
|
276
304
|
static {
|
|
277
305
|
__name(this, "GeminiRequester");
|
|
@@ -309,9 +337,11 @@ var GeminiRequester = class extends ModelRequester {
|
|
|
309
337
|
maxOutputTokens: params.model.includes("vision") ? void 0 : params.maxTokens,
|
|
310
338
|
topP: params.topP
|
|
311
339
|
},
|
|
312
|
-
tools:
|
|
313
|
-
|
|
314
|
-
|
|
340
|
+
tools: params.tools != null || this._pluginConfig.googleSearch ? formatToolsToGeminiAITools(
|
|
341
|
+
params.tools ?? [],
|
|
342
|
+
this._pluginConfig,
|
|
343
|
+
params.model
|
|
344
|
+
) : void 0
|
|
315
345
|
},
|
|
316
346
|
{
|
|
317
347
|
signal: params.signal
|
|
@@ -537,7 +567,11 @@ var GeminiClient = class extends PlatformModelAndEmbeddingsClient {
|
|
|
537
567
|
constructor(ctx, _config, clientConfig, plugin) {
|
|
538
568
|
super(ctx, clientConfig);
|
|
539
569
|
this._config = _config;
|
|
540
|
-
this._requester = new GeminiRequester(
|
|
570
|
+
this._requester = new GeminiRequester(
|
|
571
|
+
clientConfig,
|
|
572
|
+
plugin,
|
|
573
|
+
this._config
|
|
574
|
+
);
|
|
541
575
|
}
|
|
542
576
|
static {
|
|
543
577
|
__name(this, "GeminiClient");
|
|
@@ -645,7 +679,7 @@ function apply(ctx, config) {
|
|
|
645
679
|
});
|
|
646
680
|
}
|
|
647
681
|
__name(apply, "apply");
|
|
648
|
-
var
|
|
682
|
+
var Config3 = Schema.intersect([
|
|
649
683
|
ChatLunaPlugin.Config,
|
|
650
684
|
Schema.object({
|
|
651
685
|
apiKeys: Schema.array(
|
|
@@ -659,7 +693,9 @@ var Config = Schema.intersect([
|
|
|
659
693
|
}),
|
|
660
694
|
Schema.object({
|
|
661
695
|
maxTokens: Schema.number().min(16).max(2097e3).step(16).default(8064),
|
|
662
|
-
temperature: Schema.percent().min(0).max(2).step(0.1).default(0.8)
|
|
696
|
+
temperature: Schema.percent().min(0).max(2).step(0.1).default(0.8),
|
|
697
|
+
googleSearch: Schema.boolean().default(false),
|
|
698
|
+
searchThreshold: Schema.number().min(0).max(1).step(0.1).default(0.5)
|
|
663
699
|
})
|
|
664
700
|
]).i18n({
|
|
665
701
|
"zh-CN": require_zh_CN_schema(),
|
|
@@ -669,7 +705,7 @@ var Config = Schema.intersect([
|
|
|
669
705
|
var inject = ["chatluna"];
|
|
670
706
|
var name = "chatluna-google-gemini-adapter";
|
|
671
707
|
export {
|
|
672
|
-
Config,
|
|
708
|
+
Config3 as Config,
|
|
673
709
|
apply,
|
|
674
710
|
inject,
|
|
675
711
|
logger,
|
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.0.0-beta.
|
|
4
|
+
"version": "1.0.0-beta.28",
|
|
5
5
|
"main": "lib/index.cjs",
|
|
6
6
|
"module": "lib/index.mjs",
|
|
7
7
|
"typings": "lib/index.d.ts",
|
|
@@ -73,7 +73,7 @@
|
|
|
73
73
|
},
|
|
74
74
|
"peerDependencies": {
|
|
75
75
|
"koishi": "^4.18.1",
|
|
76
|
-
"koishi-plugin-chatluna": "^1.0.0-
|
|
76
|
+
"koishi-plugin-chatluna": "^1.0.0-beta.131"
|
|
77
77
|
},
|
|
78
78
|
"koishi": {
|
|
79
79
|
"description": {
|