fix(ai): correct Gemini SDK payload property thinkingBudgetTokens to thinkingBudget

This commit is contained in:
2026-05-19 16:15:59 -07:00
parent 13520a9fd4
commit a8cdc0344e
3 changed files with 19 additions and 3 deletions

16
fix_genai_bug.js Normal file
View File

@@ -0,0 +1,16 @@
const fs = require('fs');
const file1 = 'lib/ai/gemini-chat.ts';
let code1 = fs.readFileSync(file1, 'utf8');
// The correct property name for @google/genai ^1.0.0 is `thinkingBudget`.
// `thinkingBudgetTokens` is the old deprecated name that throws the 400 error!
code1 = code1.replace(/thinkingBudgetTokens:/g, 'thinkingBudget:');
fs.writeFileSync(file1, code1);
const file2 = 'lib/ai/gemini-client.ts';
let code2 = fs.readFileSync(file2, 'utf8');
code2 = code2.replace(/thinkingBudgetTokens:/g, 'thinkingBudget:');
fs.writeFileSync(file2, code2);
console.log("Fixed thinkingBudget property error for Gemini");

View File

@@ -114,7 +114,7 @@ export async function callGeminiChat(opts: {
}
if (opts.includeThoughts) {
config.thinkingConfig = { thinkingBudgetTokens: 1024 };
config.thinkingConfig = { thinkingBudget: 1024 };
}
const fns = toGeminiFunctions(opts.tools ?? []);
@@ -174,7 +174,7 @@ export async function* streamGeminiChat(opts: {
const config: any = {
temperature: opts.temperature ?? 0.7,
maxOutputTokens: 8192,
thinkingConfig: { thinkingBudgetTokens: 1024 },
thinkingConfig: { thinkingBudget: 1024 },
};
if (opts.systemPrompt) {

View File

@@ -88,7 +88,7 @@ export class GeminiLlmClient implements LlmClient {
if (args.thinking_config) {
config.thinkingConfig = {
thinkingBudgetTokens: 1024,
thinkingBudget: 1024,
};
}