temperature added to Ollama API. see #574
This commit is contained in:
parent
78b691271f
commit
17a0aeb632
6 changed files with 36 additions and 27 deletions
|
|
@ -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.",
|
||||
"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": {
|
||||
"message": "Enable thinking",
|
||||
"description": ""
|
||||
|
|
|
|||
|
|
@ -170,6 +170,7 @@ switch (llm) {
|
|||
ollama_host: prefs_default.ollama_host,
|
||||
ollama_model: prefs_default.ollama_model,
|
||||
ollama_num_ctx: prefs_default.ollama_num_ctx,
|
||||
ollama_temperature: prefs_default.ollama_temperature,
|
||||
ollama_think: prefs_default.ollama_think,
|
||||
do_debug: prefs_default.do_debug,
|
||||
});
|
||||
|
|
@ -183,6 +184,7 @@ switch (llm) {
|
|||
ollama_host: prefs_api.ollama_host,
|
||||
ollama_model: prefs_api.ollama_model,
|
||||
ollama_num_ctx: prefs_api.ollama_num_ctx,
|
||||
ollama_temperature: prefs_api.ollama_temperature,
|
||||
ollama_think: prefs_api.ollama_think,
|
||||
do_debug: prefs_api.do_debug,
|
||||
i18nStrings: i18nStrings
|
||||
|
|
@ -194,6 +196,9 @@ switch (llm) {
|
|||
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("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){
|
||||
additional_text_elements.push({label: browser.i18n.getMessage("prefs_ollama_num_ctx"), value: prefs_api.ollama_num_ctx});
|
||||
}
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ export class Ollama {
|
|||
model = '';
|
||||
stream = false;
|
||||
num_ctx = 0;
|
||||
temperature = '';
|
||||
think = false;
|
||||
|
||||
constructor({
|
||||
|
|
@ -29,12 +30,14 @@ export class Ollama {
|
|||
model = '',
|
||||
stream = false,
|
||||
num_ctx = 0,
|
||||
temperature = '',
|
||||
think = false,
|
||||
} = {}) {
|
||||
this.host = (host || '').trim().replace(/\/+$/, "");
|
||||
this.model = model;
|
||||
this.stream = stream;
|
||||
this.num_ctx = num_ctx;
|
||||
this.temperature = temperature;
|
||||
this.think = think;
|
||||
}
|
||||
|
||||
|
|
@ -90,6 +93,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) } } : {}),
|
||||
}),
|
||||
});
|
||||
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;
|
||||
// }
|
||||
// }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,12 +41,16 @@ self.onmessage = async function(event) {
|
|||
ollama_host = event.data.ollama_host;
|
||||
ollama_model = event.data.ollama_model;
|
||||
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);
|
||||
ollama = new Ollama({
|
||||
host: ollama_host,
|
||||
model: ollama_model,
|
||||
stream: true,
|
||||
num_ctx: ollama_num_ctx
|
||||
num_ctx: ollama_num_ctx,
|
||||
temperature: ollama_temperature,
|
||||
think: ollama_think
|
||||
});
|
||||
do_debug = event.data.do_debug;
|
||||
i18nStrings = event.data.i18nStrings;
|
||||
|
|
|
|||
|
|
@ -37,6 +37,7 @@ export const prefs_default = {
|
|||
ollama_host: '',
|
||||
ollama_model: '',
|
||||
ollama_num_ctx: 0,
|
||||
ollama_temperature: '',
|
||||
ollama_think: false,
|
||||
openai_comp_host: '', // For OpenAI Compatible API as LM-Studio
|
||||
openai_comp_model: '',
|
||||
|
|
|
|||
|
|
@ -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>
|
||||
</label>
|
||||
</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 class="conntype_ollama_api${tr_class ? ` ${tr_class}` : ''}">
|
||||
<td><label>
|
||||
|
|
|
|||
Loading…
Reference in a new issue