temperature added to Ollama API. see #574

This commit is contained in:
mic 2025-12-28 21:12:08 +01:00
parent 78b691271f
commit 17a0aeb632
6 changed files with 36 additions and 27 deletions

View file

@ -1585,6 +1585,14 @@
"message": "What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic.", "message": "What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic.",
"description": "" "description": ""
}, },
"ollama_temperature": {
"message": "Temperature",
"description": ""
},
"ollama_temperature_Info": {
"message": "The temperature of the model. Increasing the temperature will make the model answer more creatively. The default value is 0.8. It is recommended to use values between 0 and 1.",
"description": ""
},
"prefs_ollama_think": { "prefs_ollama_think": {
"message": "Enable thinking", "message": "Enable thinking",
"description": "" "description": ""

View file

@ -170,6 +170,7 @@ switch (llm) {
ollama_host: prefs_default.ollama_host, ollama_host: prefs_default.ollama_host,
ollama_model: prefs_default.ollama_model, ollama_model: prefs_default.ollama_model,
ollama_num_ctx: prefs_default.ollama_num_ctx, ollama_num_ctx: prefs_default.ollama_num_ctx,
ollama_temperature: prefs_default.ollama_temperature,
ollama_think: prefs_default.ollama_think, ollama_think: prefs_default.ollama_think,
do_debug: prefs_default.do_debug, do_debug: prefs_default.do_debug,
}); });
@ -183,6 +184,7 @@ switch (llm) {
ollama_host: prefs_api.ollama_host, ollama_host: prefs_api.ollama_host,
ollama_model: prefs_api.ollama_model, ollama_model: prefs_api.ollama_model,
ollama_num_ctx: prefs_api.ollama_num_ctx, ollama_num_ctx: prefs_api.ollama_num_ctx,
ollama_temperature: prefs_api.ollama_temperature,
ollama_think: prefs_api.ollama_think, ollama_think: prefs_api.ollama_think,
do_debug: prefs_api.do_debug, do_debug: prefs_api.do_debug,
i18nStrings: i18nStrings i18nStrings: i18nStrings
@ -194,6 +196,9 @@ switch (llm) {
let additional_text_elements = []; let additional_text_elements = [];
additional_text_elements.push({label: browser.i18n.getMessage("prompt_string"), value: '[' + prompt_id + '] ' + decodeURIComponent(prompt_name)}); additional_text_elements.push({label: browser.i18n.getMessage("prompt_string"), value: '[' + prompt_id + '] ' + decodeURIComponent(prompt_name)});
additional_text_elements.push({label: browser.i18n.getMessage("prefs_ollama_think"), value: (prefs_api.ollama_think ? 'Yes' : 'No')}); additional_text_elements.push({label: browser.i18n.getMessage("prefs_ollama_think"), value: (prefs_api.ollama_think ? 'Yes' : 'No')});
if(prefs_api.ollama_temperature && prefs_api.ollama_temperature.length > 0){
additional_text_elements.push({label: browser.i18n.getMessage("prefs_ollama_temperature"), value: prefs_api.ollama_temperature});
}
if(prefs_api.ollama_num_ctx > 0){ if(prefs_api.ollama_num_ctx > 0){
additional_text_elements.push({label: browser.i18n.getMessage("prefs_ollama_num_ctx"), value: prefs_api.ollama_num_ctx}); additional_text_elements.push({label: browser.i18n.getMessage("prefs_ollama_num_ctx"), value: prefs_api.ollama_num_ctx});
} }

View file

@ -22,6 +22,7 @@ export class Ollama {
model = ''; model = '';
stream = false; stream = false;
num_ctx = 0; num_ctx = 0;
temperature = '';
think = false; think = false;
constructor({ constructor({
@ -29,12 +30,14 @@ export class Ollama {
model = '', model = '',
stream = false, stream = false,
num_ctx = 0, num_ctx = 0,
temperature = '',
think = false, think = false,
} = {}) { } = {}) {
this.host = (host || '').trim().replace(/\/+$/, ""); this.host = (host || '').trim().replace(/\/+$/, "");
this.model = model; this.model = model;
this.stream = stream; this.stream = stream;
this.num_ctx = num_ctx; this.num_ctx = num_ctx;
this.temperature = temperature;
this.think = think; this.think = think;
} }
@ -90,6 +93,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) } } : {}),
}), }),
}); });
return response; return response;
@ -103,30 +107,4 @@ export class Ollama {
} }
} }
// fetchResponse = async (messages) => {
// try {
// let sending = messages.join(' ');
// console.log(">>>>>>>>>> sending: " + sending);
// const response = await fetch(this.host + "/api/generate", {
// method: "POST",
// headers: {
// "Content-Type": "application/json",
// },
// body: JSON.stringify({
// model: this.model,
// prompt: sending,
// stream: this.stream,
// }),
// });
// return response;
// }catch (error) {
// console.error("[ThunderAI] Ollama API request failed: " + error);
// let output = {};
// output.is_exception = true;
// output.ok = false;
// output.error = "Ollama API request failed: " + error;
// return output;
// }
// }
} }

View file

@ -41,12 +41,16 @@ self.onmessage = async function(event) {
ollama_host = event.data.ollama_host; ollama_host = event.data.ollama_host;
ollama_model = event.data.ollama_model; ollama_model = event.data.ollama_model;
ollama_num_ctx = event.data.ollama_num_ctx; ollama_num_ctx = event.data.ollama_num_ctx;
ollama_temperature = event.data.ollama_temperature;
ollama_think = event.data.ollama_think;
//console.log(">>>>>>>>>>> ollama_host: " + ollama_host); //console.log(">>>>>>>>>>> ollama_host: " + ollama_host);
ollama = new Ollama({ ollama = new Ollama({
host: ollama_host, host: ollama_host,
model: ollama_model, model: ollama_model,
stream: true, stream: true,
num_ctx: ollama_num_ctx num_ctx: ollama_num_ctx,
temperature: ollama_temperature,
think: ollama_think
}); });
do_debug = event.data.do_debug; do_debug = event.data.do_debug;
i18nStrings = event.data.i18nStrings; i18nStrings = event.data.i18nStrings;

View file

@ -37,6 +37,7 @@ export const prefs_default = {
ollama_host: '', ollama_host: '',
ollama_model: '', ollama_model: '',
ollama_num_ctx: 0, ollama_num_ctx: 0,
ollama_temperature: '',
ollama_think: false, ollama_think: false,
openai_comp_host: '', // For OpenAI Compatible API as LM-Studio openai_comp_host: '', // For OpenAI Compatible API as LM-Studio
openai_comp_model: '', openai_comp_model: '',

View file

@ -292,6 +292,19 @@ export async function injectConnectionUI({
<select id="${modelId_prefix ? `${modelId_prefix}` : ''}ollama_model" name="${modelId_prefix ? `${modelId_prefix}` : ''}ollama_model" class="option-input option-input-model"></select> <select id="${modelId_prefix ? `${modelId_prefix}` : ''}ollama_model" name="${modelId_prefix ? `${modelId_prefix}` : ''}ollama_model" class="option-input option-input-model"></select>
</label> </label>
</td> </td>
</tr>
<tr class="conntype_ollama_api${tr_class ? ` ${tr_class}` : ''}">
<td>
<label>
<span class="opt_title">__MSG_prefs_ollama_temperature__</span>
</label>
</td>
<td>
<label>
<input type="text" id="ollama_temperature" name="ollama_temperature" class="option-input" />
<br>__MSG_prefs_ollama_temperature_Info__
</label>
</td>
</tr> </tr>
<tr class="conntype_ollama_api${tr_class ? ` ${tr_class}` : ''}"> <tr class="conntype_ollama_api${tr_class ? ` ${tr_class}` : ''}">
<td><label> <td><label>