From 3c089fc04e7617562271541babc762def52f5d95 Mon Sep 17 00:00:00 2001 From: mic Date: Fri, 26 Dec 2025 23:16:56 +0100 Subject: [PATCH] temperature added to the google gemini class. see #572 --- js/api/google_gemini.js | 14 ++++++++++---- 1 file changed, 10 insertions(+), 4 deletions(-) diff --git a/js/api/google_gemini.js b/js/api/google_gemini.js index f2e2eb67..aae8ab09 100644 --- a/js/api/google_gemini.js +++ b/js/api/google_gemini.js @@ -25,6 +25,7 @@ export class GoogleGemini { system_instruction = ''; stream = false; thinking_budget = ''; // Model default + temperature = ''; // no temperature defined constructor({ apiKey = '', @@ -32,12 +33,14 @@ export class GoogleGemini { system_instruction = '', stream = false, thinking_budget = '', + temperature = '', } = {}) { this.apiKey = apiKey; this.model = model; this.system_instruction = system_instruction; this.stream = stream; this.thinking_budget = String(thinking_budget ?? '').trim(); + this.temperature = String(temperature ?? '').trim(); /* Info from: https://ai.google.dev/gemini-api/docs/thinking?#set-budget # Turn on thinking with a specific token limit: "thinking_budget": 1024 # Thinking off: "thinking_budget": 0 @@ -87,7 +90,8 @@ export class GoogleGemini { try { let google_gemini_body = { - contents:messages + contents: messages, + generationConfig: {}, }; // console.log("[ThunderAI] Google Gemini API system_instruction: " + JSON.stringify(this.system_instruction)); @@ -101,13 +105,15 @@ export class GoogleGemini { } if(this.thinking_budget !== '') { - google_gemini_body.generationConfig = { - thinkingConfig: { + google_gemini_body.generationConfig.thinkingConfig = { thinking_budget: this.thinking_budget, - } }; } + if(this.temperature !== ''){ + google_gemini_body.generationConfig.temperature = this.temperature; + } + // console.log("[ThunderAI] Google Gemini API request: " + JSON.stringify(google_gemini_body)); const response = await fetch("https://generativelanguage.googleapis.com/v1beta/models/" + this.model + ":" + (this.stream ? 'streamGenerateContent?alt=sse&' : 'generateContent?') + "key=" + this.apiKey, {