koishi-plugin-chatluna-google-gemini-adapter 1.2.7 → 1.2.9

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: "请求选项", 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 内容获取工具。" }] };
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 为动态思考。目前仅支持 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 (-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" }] };
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). (0: dynamic 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
 
@@ -184,13 +184,12 @@ function extractSystemMessages(messages) {
184
184
  messages.indexOf(lastSystemMessage)
185
185
  );
186
186
  return [
187
- {
188
- role: "user",
189
- parts: systemMessages.reduce((acc, cur) => {
190
- acc.push(...cur.parts);
191
- return acc;
192
- }, [])
193
- },
187
+ systemMessages.reduce((acc, cur) => {
188
+ acc.push(...cur.parts);
189
+ return acc;
190
+ }, []).map((part) => {
191
+ return partAsType(part).text;
192
+ }).join("\n\n\n"),
194
193
  messages.slice(messages.indexOf(lastSystemMessage))
195
194
  ];
196
195
  }
@@ -348,6 +347,12 @@ var GeminiRequester = class extends import_api.ModelRequester {
348
347
  model
349
348
  );
350
349
  const [systemInstruction, modelMessages] = extractSystemMessages(geminiMessages);
350
+ let thinkingBudget = this._pluginConfig.thinkingBudget ?? -1;
351
+ if (!enabledThinking && !model.includes("2.5-pro")) {
352
+ thinkingBudget = 0;
353
+ } else if (thinkingBudget >= 0 && thinkingBudget < 128) {
354
+ thinkingBudget = 128;
355
+ }
351
356
  const response = await this._post(
352
357
  `models/${model}:streamGenerateContent?alt=sse`,
353
358
  {
@@ -384,7 +389,7 @@ var GeminiRequester = class extends import_api.ModelRequester {
384
389
  "gemini-2.0-flash-exp"
385
390
  ) && this._pluginConfig.imageGeneration ? ["TEXT", "IMAGE"] : void 0,
386
391
  thinkingConfig: enabledThinking != null || this._pluginConfig.includeThoughts ? {
387
- thinkingBudget: enabledThinking ? this._pluginConfig.thinkingBudget ?? -1 : -1,
392
+ thinkingBudget,
388
393
  includeThoughts: this._pluginConfig.includeThoughts
389
394
  } : void 0
390
395
  },
@@ -802,7 +807,7 @@ var Config3 = import_koishi.Schema.intersect([
802
807
  googleSearch: import_koishi.Schema.boolean().default(false),
803
808
  codeExecution: import_koishi.Schema.boolean().default(false),
804
809
  urlContext: import_koishi.Schema.boolean().default(false),
805
- thinkingBudget: import_koishi.Schema.number().min(128).max(24576).step(16).default(128),
810
+ thinkingBudget: import_koishi.Schema.number().min(-1).max(24576).default(-1),
806
811
  includeThoughts: import_koishi.Schema.boolean().default(false),
807
812
  imageGeneration: import_koishi.Schema.boolean().default(false),
808
813
  groundingContentDisplay: import_koishi.Schema.boolean().default(false),
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: "思考预算,范围:(-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 内容获取工具。" }] };
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 为动态思考。目前仅支持 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 (-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" }] };
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). (0: dynamic 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
 
@@ -167,13 +167,12 @@ function extractSystemMessages(messages) {
167
167
  messages.indexOf(lastSystemMessage)
168
168
  );
169
169
  return [
170
- {
171
- role: "user",
172
- parts: systemMessages.reduce((acc, cur) => {
173
- acc.push(...cur.parts);
174
- return acc;
175
- }, [])
176
- },
170
+ systemMessages.reduce((acc, cur) => {
171
+ acc.push(...cur.parts);
172
+ return acc;
173
+ }, []).map((part) => {
174
+ return partAsType(part).text;
175
+ }).join("\n\n\n"),
177
176
  messages.slice(messages.indexOf(lastSystemMessage))
178
177
  ];
179
178
  }
@@ -331,6 +330,12 @@ var GeminiRequester = class extends ModelRequester {
331
330
  model
332
331
  );
333
332
  const [systemInstruction, modelMessages] = extractSystemMessages(geminiMessages);
333
+ let thinkingBudget = this._pluginConfig.thinkingBudget ?? -1;
334
+ if (!enabledThinking && !model.includes("2.5-pro")) {
335
+ thinkingBudget = 0;
336
+ } else if (thinkingBudget >= 0 && thinkingBudget < 128) {
337
+ thinkingBudget = 128;
338
+ }
334
339
  const response = await this._post(
335
340
  `models/${model}:streamGenerateContent?alt=sse`,
336
341
  {
@@ -367,7 +372,7 @@ var GeminiRequester = class extends ModelRequester {
367
372
  "gemini-2.0-flash-exp"
368
373
  ) && this._pluginConfig.imageGeneration ? ["TEXT", "IMAGE"] : void 0,
369
374
  thinkingConfig: enabledThinking != null || this._pluginConfig.includeThoughts ? {
370
- thinkingBudget: enabledThinking ? this._pluginConfig.thinkingBudget ?? -1 : -1,
375
+ thinkingBudget,
371
376
  includeThoughts: this._pluginConfig.includeThoughts
372
377
  } : void 0
373
378
  },
@@ -785,7 +790,7 @@ var Config3 = Schema.intersect([
785
790
  googleSearch: Schema.boolean().default(false),
786
791
  codeExecution: Schema.boolean().default(false),
787
792
  urlContext: Schema.boolean().default(false),
788
- thinkingBudget: Schema.number().min(128).max(24576).step(16).default(128),
793
+ thinkingBudget: Schema.number().min(-1).max(24576).default(-1),
789
794
  includeThoughts: Schema.boolean().default(false),
790
795
  imageGeneration: Schema.boolean().default(false),
791
796
  groundingContentDisplay: Schema.boolean().default(false),
package/lib/utils.d.ts CHANGED
@@ -3,7 +3,7 @@ import { StructuredTool } from '@langchain/core/tools';
3
3
  import { ChatCompletionFunction, ChatCompletionResponseMessage, ChatCompletionResponseMessageRoleEnum, ChatPart } from './types';
4
4
  import { Config } from '.';
5
5
  export declare function langchainMessageToGeminiMessage(messages: BaseMessage[], model?: string): Promise<ChatCompletionResponseMessage[]>;
6
- export declare function extractSystemMessages(messages: ChatCompletionResponseMessage[]): [ChatCompletionResponseMessage, ChatCompletionResponseMessage[]];
6
+ export declare function extractSystemMessages(messages: ChatCompletionResponseMessage[]): [string, ChatCompletionResponseMessage[]];
7
7
  export declare function partAsType<T extends ChatPart>(part: ChatPart): T;
8
8
  export declare function partAsTypeCheck<T extends ChatPart>(part: ChatPart, check: (part: ChatPart & unknown) => boolean): T | undefined;
9
9
  export declare function formatToolsToGeminiAITools(tools: StructuredTool[], config: Config, model: string): Record<string, any>;
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.7",
4
+ "version": "1.2.9",
5
5
  "main": "lib/index.cjs",
6
6
  "module": "lib/index.mjs",
7
7
  "typings": "lib/index.d.ts",