fix: update google provider to handle gemma 4 thinking levels and route between MINIMAL and HIGH (#2903)
resolves #2812 Co-authored-by: Mario Zechner <badlogicgames@gmail.com>
This commit is contained in:
@@ -2,6 +2,10 @@
|
|||||||
|
|
||||||
## [Unreleased]
|
## [Unreleased]
|
||||||
|
|
||||||
|
### Fixed
|
||||||
|
|
||||||
|
- Fixed thinking levels for Gemma 4 models to use `thinkingLevel` and map Pi reasoning levels to the model's supported thinking levels ([#2903](https://github.com/badlogic/pi-mono/pull/2903) by [@aadishv](https://github.com/aadishv))
|
||||||
|
|
||||||
## [0.66.1] - 2026-04-08
|
## [0.66.1] - 2026-04-08
|
||||||
|
|
||||||
## [0.66.0] - 2026-04-08
|
## [0.66.0] - 2026-04-08
|
||||||
|
|||||||
@@ -293,12 +293,12 @@ export const streamSimpleGoogle: StreamFunction<"google-generative-ai", SimpleSt
|
|||||||
const effort = clampReasoning(options.reasoning)!;
|
const effort = clampReasoning(options.reasoning)!;
|
||||||
const googleModel = model as Model<"google-generative-ai">;
|
const googleModel = model as Model<"google-generative-ai">;
|
||||||
|
|
||||||
if (isGemini3ProModel(googleModel) || isGemini3FlashModel(googleModel)) {
|
if (isGemini3ProModel(googleModel) || isGemini3FlashModel(googleModel) || isGemma4Model(googleModel)) {
|
||||||
return streamGoogle(model, context, {
|
return streamGoogle(model, context, {
|
||||||
...base,
|
...base,
|
||||||
thinking: {
|
thinking: {
|
||||||
enabled: true,
|
enabled: true,
|
||||||
level: getGemini3ThinkingLevel(effort, googleModel),
|
level: getThinkingLevel(effort, googleModel),
|
||||||
},
|
},
|
||||||
} satisfies GoogleOptions);
|
} satisfies GoogleOptions);
|
||||||
}
|
}
|
||||||
@@ -394,6 +394,10 @@ function buildParams(
|
|||||||
|
|
||||||
type ClampedThinkingLevel = Exclude<ThinkingLevel, "xhigh">;
|
type ClampedThinkingLevel = Exclude<ThinkingLevel, "xhigh">;
|
||||||
|
|
||||||
|
function isGemma4Model(model: Model<"google-generative-ai">): boolean {
|
||||||
|
return /gemma-?4/.test(model.id.toLowerCase());
|
||||||
|
}
|
||||||
|
|
||||||
function isGemini3ProModel(model: Model<"google-generative-ai">): boolean {
|
function isGemini3ProModel(model: Model<"google-generative-ai">): boolean {
|
||||||
return /gemini-3(?:\.\d+)?-pro/.test(model.id.toLowerCase());
|
return /gemini-3(?:\.\d+)?-pro/.test(model.id.toLowerCase());
|
||||||
}
|
}
|
||||||
@@ -412,15 +416,15 @@ function getDisabledThinkingConfig(model: Model<"google-generative-ai">): Thinki
|
|||||||
if (isGemini3FlashModel(model)) {
|
if (isGemini3FlashModel(model)) {
|
||||||
return { thinkingLevel: "MINIMAL" as any };
|
return { thinkingLevel: "MINIMAL" as any };
|
||||||
}
|
}
|
||||||
|
if (isGemma4Model(model)) {
|
||||||
|
return { thinkingLevel: "MINIMAL" as any };
|
||||||
|
}
|
||||||
|
|
||||||
// Gemini 2.x supports disabling via thinkingBudget = 0.
|
// Gemini 2.x supports disabling via thinkingBudget = 0.
|
||||||
return { thinkingBudget: 0 };
|
return { thinkingBudget: 0 };
|
||||||
}
|
}
|
||||||
|
|
||||||
function getGemini3ThinkingLevel(
|
function getThinkingLevel(effort: ClampedThinkingLevel, model: Model<"google-generative-ai">): GoogleThinkingLevel {
|
||||||
effort: ClampedThinkingLevel,
|
|
||||||
model: Model<"google-generative-ai">,
|
|
||||||
): GoogleThinkingLevel {
|
|
||||||
if (isGemini3ProModel(model)) {
|
if (isGemini3ProModel(model)) {
|
||||||
switch (effort) {
|
switch (effort) {
|
||||||
case "minimal":
|
case "minimal":
|
||||||
@@ -431,6 +435,16 @@ function getGemini3ThinkingLevel(
|
|||||||
return "HIGH";
|
return "HIGH";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
if (isGemma4Model(model)) {
|
||||||
|
switch (effort) {
|
||||||
|
case "minimal":
|
||||||
|
case "low":
|
||||||
|
return "MINIMAL";
|
||||||
|
case "medium":
|
||||||
|
case "high":
|
||||||
|
return "HIGH";
|
||||||
|
}
|
||||||
|
}
|
||||||
switch (effort) {
|
switch (effort) {
|
||||||
case "minimal":
|
case "minimal":
|
||||||
return "MINIMAL";
|
return "MINIMAL";
|
||||||
|
|||||||
@@ -90,6 +90,33 @@ Override defaults when you need specific values:
|
|||||||
|
|
||||||
The file reloads each time you open `/model`. Edit during session; no restart needed.
|
The file reloads each time you open `/model`. Edit during session; no restart needed.
|
||||||
|
|
||||||
|
## Google AI Studio Example
|
||||||
|
|
||||||
|
Use `google-generative-ai` with a `baseUrl` to add models from Google AI Studio, including custom Gemma 4 entries:
|
||||||
|
|
||||||
|
```json
|
||||||
|
{
|
||||||
|
"providers": {
|
||||||
|
"my-google": {
|
||||||
|
"baseUrl": "https://generativelanguage.googleapis.com/v1beta",
|
||||||
|
"api": "google-generative-ai",
|
||||||
|
"apiKey": "GEMINI_API_KEY",
|
||||||
|
"models": [
|
||||||
|
{
|
||||||
|
"id": "gemma-4-31b-it",
|
||||||
|
"name": "Gemma 4 31B",
|
||||||
|
"input": ["text", "image"],
|
||||||
|
"contextWindow": 262144,
|
||||||
|
"reasoning": true
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
```
|
||||||
|
|
||||||
|
The `baseUrl` is required when adding custom models to the `google-generative-ai` API type.
|
||||||
|
|
||||||
## Supported APIs
|
## Supported APIs
|
||||||
|
|
||||||
| API | Description |
|
| API | Description |
|
||||||
|
|||||||
Reference in New Issue
Block a user