Merge branch 'main' into issue_350

This commit is contained in:
Mic 2025-04-22 21:08:23 +02:00 committed by GitHub
commit 1907739f8b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 46 additions and 8 deletions

View file

@ -6,8 +6,9 @@
<h2>Version 3.3.5 - 17/04/2025</h2>
<ul>
<li>Using a prompt from the compose window with a "Do reply" action is changed in "Substitute Text" [<a href="https://github.com/micz/ThunderAI/issues/353">#353</a>].</li>
<li>Using a prompt from the compose window with a "Do reply" action is changed in "Substitute Text", asking also to insert text if none is selected [<a href="https://github.com/micz/ThunderAI/issues/353">#353</a>].</li>
<li>Added an option when composing in plain text to remove the extra empty lines [<a href="https://github.com/micz/ThunderAI/issues/350">#350</a>].</li>
<li><i>[Ollama API]</i> It's now possibile to define the default context length (the <i>num_ctx</i> parameter) in the options page [<a href="https://github.com/micz/ThunderAI/issues/351">#351</a>].</li>
<li><i>[ChatGPT Web]</i> Updated the list of available models in the option page.</li>
<li><i>[ChatGPT Web]</i> Opening the ChatGPT webpage from the options now enforce the selected model, if any.</li>
<li><i>[All APIs]</i> Fix: Really correctly getting the message body even in multilevel subpart messages when processing incoming messages for tags or spam [<a href="https://github.com/micz/ThunderAI/issues/335">#335</a>].</li>

View file

@ -1279,4 +1279,16 @@
"message": "Check this option if you're composing the emails in plain text format.",
"description": ""
}
"Replace_No_Selected_Text": {
"message": "No text selected, would you like to insert the AI's response at the beginning of the email?",
"description": ""
},
"prefs_ollama_num_ctx": {
"message": "Number of context tokens",
"description": ""
},
"prefs_ollama_num_ctx_Info": {
"message": "The number of context tokens to use for the Ollama API. Set to 0 if you don't want to pass it as a parameter to the server.",
"description": ""
}
}

View file

@ -90,13 +90,13 @@ switch (llm) {
break;
}
case "ollama_api": {
let prefs_api = await browser.storage.sync.get({ollama_host: '', ollama_model: '', do_debug: false});
let prefs_api = await browser.storage.sync.get({ollama_host: '', ollama_model: '', ollama_num_ctx: 0, do_debug: false});
let i18nStrings = {};
i18nStrings["ollama_api_request_failed"] = browser.i18n.getMessage('ollama_api_request_failed');
i18nStrings["error_connection_interrupted"] = browser.i18n.getMessage('error_connection_interrupted');
messageInput.setModel(prefs_api.ollama_model);
messagesArea.setLLMName("Ollama Local");
worker.postMessage({ type: 'init', ollama_host: prefs_api.ollama_host, ollama_model: prefs_api.ollama_model, do_debug: prefs_api.do_debug, i18nStrings: i18nStrings});
worker.postMessage({ type: 'init', ollama_host: prefs_api.ollama_host, ollama_model: prefs_api.ollama_model, ollama_num_ctx: prefs_api.ollama_num_ctx, do_debug: prefs_api.do_debug, i18nStrings: i18nStrings});
browser.runtime.sendMessage({command: "ollama_api_ready_" + call_id, window_id: (await browser.windows.getCurrent()).id});
messagesArea.appendUserMessage(browser.i18n.getMessage("ollama_api_connecting") + " \"" + prefs_api.ollama_host + "\" " +browser.i18n.getMessage("AndModel") + " \"" + prefs_api.ollama_model + "\"...", "info");
break;

View file

@ -21,11 +21,13 @@ export class Ollama {
host = '';
model = '';
stream = false;
num_ctx = 0;
constructor(host, model, stream = false) {
constructor(host, model, stream = false, num_ctx = 0) {
this.host = host.trim().replace(/\/+$/, "");
this.model = model;
this.stream = stream;
this.num_ctx = num_ctx;
}
fetchModels = async () => {
@ -78,6 +80,7 @@ export class Ollama {
model: this.model,
messages: messages,
stream: this.stream,
...(this.num_ctx > 0 ? { num_ctx: parseInt(this.num_ctx) } : {})
}),
});
return response;

View file

@ -24,13 +24,20 @@ switch (message.command) {
case "replaceSelectedText": {
const selectedText = window.getSelection().toString();
let force_insert = false;
if (selectedText === '') {
if(!confirm(browser.i18n.getMessage("Replace_No_Selected_Text"))) {
return Promise.resolve(false);
}else{
force_insert = true;
}
}
const sel = window.getSelection();
if (!sel || sel.type !== "Range" || !sel.rangeCount) {
if(!force_insert) {
return Promise.resolve(false);
}
}
const r = sel.getRangeAt(0);
r.deleteContents();
const parser = new DOMParser();

View file

@ -25,6 +25,7 @@ import { taLogger } from '../mzta-logger.js';
let ollama_host = null;
let ollama_model = '';
let ollama_num_ctx = 0;
let ollama = null;
let stopStreaming = false;
let i18nStrings = null;
@ -39,8 +40,9 @@ self.onmessage = async function(event) {
case 'init':
ollama_host = event.data.ollama_host;
ollama_model = event.data.ollama_model;
ollama_num_ctx = event.data.ollama_num_ctx;
//console.log(">>>>>>>>>>> ollama_host: " + ollama_host);
ollama = new Ollama(ollama_host, ollama_model, true);
ollama = new Ollama(ollama_host, ollama_model, true, ollama_num_ctx);
do_debug = event.data.do_debug;
i18nStrings = event.data.i18nStrings;
taLog = new taLogger('model-worker-ollama', do_debug);

View file

@ -31,6 +31,7 @@ export const prefs_default = {
chatgpt_developer_messages: '',
ollama_host: '',
ollama_model: '',
ollama_num_ctx: 0,
openai_comp_host: '', // For OpenAI Compatible API as LM-Studio
openai_comp_model: '',
openai_comp_api_key: '',

View file

@ -261,6 +261,17 @@
<br><br><button id="btnGiveAllUrlsPermission_ollama_api">__MSG_CORS_give_allurls_perm__</button>
</td>
</tr>
<tr class="conntype_ollama_api">
<td><label>
<span>__MSG_prefs_ollama_num_ctx__</span>
</label></td>
<td>
<label>
<input type="number" id="ollama_num_ctx" name="ollama_num_ctx" class="option-input"/>
<br>__MSG_prefs_ollama_num_ctx_Info__
</label>
</td>
</tr>
<tr class="conntype_ollama_api">
<td>
<label>

View file

@ -9,8 +9,9 @@
<div id="miczRelNotes"><h1>ThunderAI Release Notes</h1>
<h2>Version 3.3.5 - 17/04/2025</h2>
<ul>
<li>Using a prompt from the compose window with a "Do reply" action is changed in "Substitute Text" [<a href="https://github.com/micz/ThunderAI/issues/353">#353</a>].</li>
<li>Using a prompt from the compose window with a "Do reply" action is changed in "Substitute Text", asking also to insert text if none is selected [<a href="https://github.com/micz/ThunderAI/issues/353">#353</a>].</li>
<li>Added an option when composing in plain text to remove the extra empty lines [<a href="https://github.com/micz/ThunderAI/issues/350">#350</a>].</li>
<li><i>[Ollama API]</i> It's now possibile to define the default context length (the <i>num_ctx</i> parameter) in the options page [<a href="https://github.com/micz/ThunderAI/issues/351">#351</a>].</li>
<li><i>[ChatGPT Web]</i> Updated the list of available models in the option page.</li>
<li><i>[ChatGPT Web]</i> Opening the ChatGPT webpage from the options now enforce the selected model, if any.</li>
<li><i>[All APIs]</i> Fix: Really correctly getting the message body even in multilevel subpart messages when processing incoming messages for tags or spam [<a href="https://github.com/micz/ThunderAI/issues/335">#335</a>].</li>