NaN check fixed
This commit is contained in:
parent
7f4f3e6fe7
commit
ef940e40b5
5 changed files with 17 additions and 9 deletions
|
|
@ -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",
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
|
|
|||
|
|
@ -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 } : {})
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue