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,
|
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", {
|
const response = await fetch("https://api.anthropic.com/v1/messages", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
|
|
|
||||||
|
|
@ -110,8 +110,10 @@ export class GoogleGemini {
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
if(parseFloat(this.temperature) != NaN){
|
const tempFloat = parseFloat(this.temperature);
|
||||||
google_gemini_body.generationConfig.temperature = 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));
|
// console.log("[ThunderAI] Google Gemini API request: " + JSON.stringify(google_gemini_body));
|
||||||
|
|
|
||||||
|
|
@ -81,6 +81,7 @@ export class Ollama {
|
||||||
|
|
||||||
fetchResponse = async (messages) => {
|
fetchResponse = async (messages) => {
|
||||||
try {
|
try {
|
||||||
|
const tempFloat = parseFloat(this.temperature);
|
||||||
//console.log(">>>>>>>>>> messages: " +JSON.stringify(messages));
|
//console.log(">>>>>>>>>> messages: " +JSON.stringify(messages));
|
||||||
const response = await fetch(this.host + "/api/chat", {
|
const response = await fetch(this.host + "/api/chat", {
|
||||||
method: "POST",
|
method: "POST",
|
||||||
|
|
@ -93,7 +94,7 @@ export class Ollama {
|
||||||
stream: this.stream,
|
stream: this.stream,
|
||||||
think: this.think,
|
think: this.think,
|
||||||
...(this.num_ctx > 0 ? { options: { num_ctx: parseInt(this.num_ctx) } } : {}),
|
...(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;
|
return response;
|
||||||
|
|
|
||||||
|
|
@ -26,7 +26,7 @@ export class OpenAIComp {
|
||||||
apiKey = '';
|
apiKey = '';
|
||||||
use_v1 = true;
|
use_v1 = true;
|
||||||
stream = false;
|
stream = false;
|
||||||
openai_comp_temperature = '';
|
temperature = '';
|
||||||
|
|
||||||
constructor({
|
constructor({
|
||||||
host = '',
|
host = '',
|
||||||
|
|
@ -34,14 +34,14 @@ export class OpenAIComp {
|
||||||
apiKey = '',
|
apiKey = '',
|
||||||
stream = false,
|
stream = false,
|
||||||
use_v1 = true,
|
use_v1 = true,
|
||||||
openai_comp_temperature = '',
|
temperature = '',
|
||||||
} = {}) {
|
} = {}) {
|
||||||
this.host = (host || '').trim().replace(/\/+$/, "");
|
this.host = (host || '').trim().replace(/\/+$/, "");
|
||||||
this.model = model;
|
this.model = model;
|
||||||
this.stream = stream;
|
this.stream = stream;
|
||||||
this.apiKey = apiKey;
|
this.apiKey = apiKey;
|
||||||
this.use_v1 = use_v1;
|
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) => {
|
fetchResponse = async (messages, maxTokens = 0) => {
|
||||||
try{
|
try{
|
||||||
|
const tempFloat = parseFloat(this.temperature);
|
||||||
const curr_headers = {
|
const curr_headers = {
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
};
|
};
|
||||||
|
|
@ -95,7 +96,7 @@ export class OpenAIComp {
|
||||||
messages: messages,
|
messages: messages,
|
||||||
stream: this.stream,
|
stream: this.stream,
|
||||||
...(maxTokens > 0 ? { 'max_tokens': parseInt(maxTokens) } : {}),
|
...(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;
|
return response;
|
||||||
|
|
|
||||||
|
|
@ -88,12 +88,14 @@ export class OpenAI {
|
||||||
content: [{ type: "input_text", text: msg.content }]
|
content: [{ type: "input_text", text: msg.content }]
|
||||||
}));
|
}));
|
||||||
|
|
||||||
|
const tempFloat = parseFloat(this.temperature);
|
||||||
|
|
||||||
let request_body = {
|
let request_body = {
|
||||||
model: this.model,
|
model: this.model,
|
||||||
input: input,
|
input: input,
|
||||||
stream: this.stream,
|
stream: this.stream,
|
||||||
store: this.store,
|
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) } : {}),
|
...(maxTokens > 0 ? { 'max_output_tokens': parseInt(maxTokens) } : {}),
|
||||||
...(previous_response_id && this.store ? { 'previous_response_id': previous_response_id } : {})
|
...(previous_response_id && this.store ? { 'previous_response_id': previous_response_id } : {})
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue