From ef940e40b550b8d577f64f4a27b45b845e29b115 Mon Sep 17 00:00:00 2001 From: mic Date: Sun, 28 Dec 2025 21:45:05 +0100 Subject: [PATCH] NaN check fixed --- js/api/anthropic.js | 4 +++- js/api/google_gemini.js | 6 ++++-- js/api/ollama.js | 3 ++- js/api/openai_comp.js | 9 +++++---- js/api/openai_responses.js | 4 +++- 5 files changed, 17 insertions(+), 9 deletions(-) diff --git a/js/api/anthropic.js b/js/api/anthropic.js index 1328ff5f..b8c5f844 100644 --- a/js/api/anthropic.js +++ b/js/api/anthropic.js @@ -99,7 +99,9 @@ export class Anthropic { stream: this.stream, }; - if(this.temperature != '' && parseFloat(this.temperature) != NaN) claude_body.temperature = parseFloat(this.temperature); + const tempFloat = parseFloat(this.temperature); + + if(this.temperature != '' && !Number.isNaN(tempFloat)) claude_body.temperature = tempFloat; const response = await fetch("https://api.anthropic.com/v1/messages", { method: "POST", diff --git a/js/api/google_gemini.js b/js/api/google_gemini.js index 0d174291..e16c52e5 100644 --- a/js/api/google_gemini.js +++ b/js/api/google_gemini.js @@ -110,8 +110,10 @@ export class GoogleGemini { }; } - if(parseFloat(this.temperature) != NaN){ - google_gemini_body.generationConfig.temperature = parseFloat(this.temperature); + const tempFloat = parseFloat(this.temperature); + + if(this.temperature != '' && !Number.isNaN(tempFloat)) { + google_gemini_body.generationConfig.temperature = tempFloat; } // console.log("[ThunderAI] Google Gemini API request: " + JSON.stringify(google_gemini_body)); diff --git a/js/api/ollama.js b/js/api/ollama.js index a77653f1..f9f7e0ad 100644 --- a/js/api/ollama.js +++ b/js/api/ollama.js @@ -81,6 +81,7 @@ export class Ollama { fetchResponse = async (messages) => { try { + const tempFloat = parseFloat(this.temperature); //console.log(">>>>>>>>>> messages: " +JSON.stringify(messages)); const response = await fetch(this.host + "/api/chat", { method: "POST", @@ -93,7 +94,7 @@ export class Ollama { stream: this.stream, think: this.think, ...(this.num_ctx > 0 ? { options: { num_ctx: parseInt(this.num_ctx) } } : {}), - ...(parseFloat(this.temperature) != NaN ? { options: { temperature: parseFloat(this.temperature) } } : {}), + ...(this.temperature != '' && !Number.isNaN(tempFloat) ? { options: { temperature: tempFloat } } : {}), }), }); return response; diff --git a/js/api/openai_comp.js b/js/api/openai_comp.js index e6ea5333..683a0b8c 100644 --- a/js/api/openai_comp.js +++ b/js/api/openai_comp.js @@ -26,7 +26,7 @@ export class OpenAIComp { apiKey = ''; use_v1 = true; stream = false; - openai_comp_temperature = ''; + temperature = ''; constructor({ host = '', @@ -34,14 +34,14 @@ export class OpenAIComp { apiKey = '', stream = false, use_v1 = true, - openai_comp_temperature = '', + temperature = '', } = {}) { this.host = (host || '').trim().replace(/\/+$/, ""); this.model = model; this.stream = stream; this.apiKey = apiKey; this.use_v1 = use_v1; - this.openai_comp_temperature = openai_comp_temperature; + this.temperature = temperature; } @@ -81,6 +81,7 @@ export class OpenAIComp { fetchResponse = async (messages, maxTokens = 0) => { try{ + const tempFloat = parseFloat(this.temperature); const curr_headers = { "Content-Type": "application/json", }; @@ -95,7 +96,7 @@ export class OpenAIComp { messages: messages, stream: this.stream, ...(maxTokens > 0 ? { 'max_tokens': parseInt(maxTokens) } : {}), - ...(parseFloat(this.openai_comp_temperature) != NaN ? { 'temperature': parseFloat(this.openai_comp_temperature) } : {}) + ...(this.temperature != '' && !Number.isNaN(tempFloat) ? { 'temperature': tempFloat } : {}) }), }); return response; diff --git a/js/api/openai_responses.js b/js/api/openai_responses.js index 4915fd27..174c4f4d 100644 --- a/js/api/openai_responses.js +++ b/js/api/openai_responses.js @@ -88,12 +88,14 @@ export class OpenAI { content: [{ type: "input_text", text: msg.content }] })); + const tempFloat = parseFloat(this.temperature); + let request_body = { model: this.model, input: input, stream: this.stream, store: this.store, - ...(parseFloat(this.temperature) != NaN ? { 'temperature': parseFloat(this.temperature) } : {}), + ...(this.temperature != '' && !Number.isNaN(tempFloat) ? { 'temperature': tempFloat } : {}), ...(maxTokens > 0 ? { 'max_output_tokens': parseInt(maxTokens) } : {}), ...(previous_response_id && this.store ? { 'previous_response_id': previous_response_id } : {}) }