diff --git a/CHANGELOG.md b/CHANGELOG.md index abc12f4e..4dbd3aa3 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,8 @@
"/, '
').replace(/"<\/p>$/, '
'); // strip quotation marks //console.log(">>>>>>>>>>>> fullTextHTMLAtAssignment: " + fullTextHTMLAtAssignment); - let reply_type_pref = await browser.storage.sync.get({reply_type: 'reply_all'}); + let reply_type_pref = await browser.storage.sync.get({ reply_type: prefs_default.reply_type }); if((promptData.action == "1") && (promptData.mailMessageId != -1)) { const actionButton_line2 = document.createElement('span'); actionButton_line2.classList.add('action_btn_info'); @@ -613,4 +614,4 @@ function removeAloneBRs(htmlString) { }); return doc.body.innerHTML; -} \ No newline at end of file +} diff --git a/images/autotags.png b/images/autotags.png new file mode 100644 index 00000000..7490e48e Binary files /dev/null and b/images/autotags.png differ diff --git a/images/spamfilter.png b/images/spamfilter.png new file mode 100644 index 00000000..a068ef4e Binary files /dev/null and b/images/spamfilter.png differ diff --git a/js/api/anthropic.js b/js/api/anthropic.js index 662b45df..724a092b 100644 --- a/js/api/anthropic.js +++ b/js/api/anthropic.js @@ -27,7 +27,13 @@ export class Anthropic { max_tokens = 4096; stream = false; - constructor(apiKey, version, model, max_tokens = 4096, stream = false) { + constructor({ + apiKey = '', + version = '', + model = '', + max_tokens = 4096, + stream = false, + } = {}) { this.apiKey = apiKey; this.version = version; this.model = model; @@ -104,4 +110,4 @@ export class Anthropic { } } -} \ No newline at end of file +} diff --git a/js/api/google_gemini.js b/js/api/google_gemini.js index d0d8a055..f2e2eb67 100644 --- a/js/api/google_gemini.js +++ b/js/api/google_gemini.js @@ -24,12 +24,26 @@ export class GoogleGemini { model = ''; system_instruction = ''; stream = false; + thinking_budget = ''; // Model default - constructor(apiKey, model, system_instruction, stream) { + constructor({ + apiKey = '', + model = '', + system_instruction = '', + stream = false, + thinking_budget = '', + } = {}) { this.apiKey = apiKey; this.model = model; this.system_instruction = system_instruction; this.stream = stream; + this.thinking_budget = String(thinking_budget ?? '').trim(); + /* Info from: https://ai.google.dev/gemini-api/docs/thinking?#set-budget + # Turn on thinking with a specific token limit: "thinking_budget": 1024 + # Thinking off: "thinking_budget": 0 + # Turn on dynamic thinking: "thinking_budget": -1 + # Keep model default thinking: "thinking_budget": "" + */ } @@ -83,7 +97,15 @@ export class GoogleGemini { parts:{ text: this.system_instruction } - } + }; + } + + if(this.thinking_budget !== '') { + google_gemini_body.generationConfig = { + thinkingConfig: { + thinking_budget: this.thinking_budget, + } + }; } // console.log("[ThunderAI] Google Gemini API request: " + JSON.stringify(google_gemini_body)); diff --git a/js/api/ollama.js b/js/api/ollama.js index 5c10763a..9a4be836 100644 --- a/js/api/ollama.js +++ b/js/api/ollama.js @@ -24,8 +24,14 @@ export class Ollama { num_ctx = 0; think = false; - constructor(host, model, stream = false, num_ctx = 0, think = false) { - this.host = host.trim().replace(/\/+$/, ""); + constructor({ + host = '', + model = '', + stream = false, + num_ctx = 0, + think = false, + } = {}) { + this.host = (host || '').trim().replace(/\/+$/, ""); this.model = model; this.stream = stream; this.num_ctx = num_ctx; @@ -123,4 +129,4 @@ export class Ollama { // return output; // } // } -} \ No newline at end of file +} diff --git a/js/api/openai.js b/js/api/openai.js index 11884e7e..6d589c4c 100644 --- a/js/api/openai.js +++ b/js/api/openai.js @@ -27,7 +27,13 @@ export class OpenAI { stream = false; store = false; - constructor(apiKey, model, developer_messages, stream, store) { + constructor({ + apiKey = '', + model = '', + developer_messages = '', + stream = false, + store = false + } = {}) { this.apiKey = apiKey; this.model = model; this.developer_messages = developer_messages; @@ -120,4 +126,4 @@ export class OpenAI { return data.token_count; } -} \ No newline at end of file +} diff --git a/js/api/openai_comp.js b/js/api/openai_comp.js index a0ba14ec..3e975b62 100644 --- a/js/api/openai_comp.js +++ b/js/api/openai_comp.js @@ -27,8 +27,14 @@ export class OpenAIComp { use_v1 = true; stream = false; - constructor(host, model, apiKey = '', stream = false, use_v1 = true) { - this.host = host.trim().replace(/\/+$/, ""); + constructor({ + host = '', + model = '', + apiKey = '', + stream = false, + use_v1 = true, + } = {}) { + this.host = (host || '').trim().replace(/\/+$/, ""); this.model = model; this.stream = stream; this.apiKey = apiKey; @@ -107,4 +113,4 @@ export class OpenAIComp { } } -} \ No newline at end of file +} diff --git a/js/mzta-menus.js b/js/mzta-menus.js index c836acde..0ecec436 100644 --- a/js/mzta-menus.js +++ b/js/mzta-menus.js @@ -19,7 +19,20 @@ // Some original methods are derived from https://github.com/ali-raheem/Aify/blob/cfadf52f576b7be3720b5b73af7c8d3129c054da/plugin/html/actions.js import { getPrompts } from './mzta-prompts.js'; -import { getLanguageDisplayName, getMenuContextCompose, getMenuContextDisplay, i18nConditionalGet, getMailSubject, getTagsList, extractJsonObject, convertNewlinesToBr, cleanupNewlines, checkIfTagLabelExists } from './mzta-utils.js' +import { prefs_default } from '../options/mzta-options-default.js'; +import { + getLanguageDisplayName, + getMenuContextCompose, + getMenuContextDisplay, + i18nConditionalGet, + getMailSubject, + getTagsList, + extractJsonObject, + convertNewlinesToBr, + cleanupNewlines, + checkIfTagLabelExists, + getConnectionType, + } from './mzta-utils.js' import { taPromptUtils } from './mzta-utils-prompt.js'; import { taLogger } from './mzta-logger.js'; import { placeholdersUtils } from './mzta-placeholders.js'; @@ -182,9 +195,17 @@ export class mzta_Menus { case 'prompt_add_tags': { // Add tags to the email let tags_current_email = []; let tags_current_email_final = []; - let prefs_at = await browser.storage.sync.get({add_tags_maxnum: 3, connection_type: '', add_tags_force_lang: true, add_tags_auto_force_existing: false, default_chatgpt_lang: '', do_debug: false}); - if((prefs_at.connection_type === '')||(prefs_at.connection_type === null)||(prefs_at.connection_type === undefined)||(prefs_at.connection_type === 'chatgpt_web')){ - console.error("[ThunderAI | AddTags] Invalid connection type: " + prefs_at.connection_type); + let prefs_at = await browser.storage.sync.get({ + add_tags_maxnum: prefs_default.add_tags_maxnum, + connection_type: prefs_default.connection_type, + add_tags_force_lang: prefs_default.add_tags_force_lang, + add_tags_auto_force_existing: prefs_default.add_tags_auto_force_existing, + default_chatgpt_lang: prefs_default.default_chatgpt_lang, + do_debug: prefs_default.do_debug, + }); + let def_conntype = getConnectionType(prefs_at.connection_type, curr_prompt); + if((def_conntype === '')||(def_conntype === null)||(def_conntype === undefined)||(def_conntype === 'chatgpt_web')){ + console.error("[ThunderAI | AddTags] Invalid connection type: " + def_conntype); taWorkingStatus.stopWorking(); return {ok:'0'}; } @@ -192,10 +213,17 @@ export class mzta_Menus { this.logger.log("fullPrompt: " + fullPrompt); let create_new_tags = !prefs_at.add_tags_auto_force_existing; let all_tags_list = tags_full_list[1]; - // TODO: use the current API, abort if using chatgpt web // COMMENTED TO DO TESTS // tags_current_email = "recipients, TEST, home, work, CAR, light"; - let cmd_addTags = new mzta_specialCommand(fullPrompt,prefs_at.connection_type,prefs_at.do_debug); + console.log(">>>>>>>>>>>>> curr_prompt: " + JSON.stringify(curr_prompt)); + console.log(">>>>>>>>>>>>>> prefs_at.connection_type: " + JSON.stringify(prefs_at.connection_type)); + console.log(">>>>>>>>>>>>>> def_conntype: " + JSON.stringify(def_conntype)); + let cmd_addTags = new mzta_specialCommand({ + prompt: fullPrompt, + llm: def_conntype, + custom_model: curr_prompt.model ? curr_prompt.model : '', + do_debug: prefs_at.do_debug + }); await cmd_addTags.initWorker(); try{ tags_current_email = taPromptUtils.getTagsFromResponse(await cmd_addTags.sendPrompt()); @@ -226,7 +254,11 @@ export class mzta_Menus { } case 'prompt_get_calendar_event': { // Get a calendar event info let calendar_event_data = ''; - let prefs_at = await browser.storage.sync.get({connection_type: '', calendar_enforce_timezone: false, calendar_timezone: '',}); + let prefs_at = await browser.storage.sync.get({ + connection_type: prefs_default.connection_type, + calendar_enforce_timezone: prefs_default.calendar_enforce_timezone, + calendar_timezone: prefs_default.calendar_timezone, + }); if((prefs_at.connection_type === '')||(prefs_at.connection_type === null)||(prefs_at.connection_type === undefined)||(prefs_at.connection_type === 'chatgpt_web')){ console.error("[ThunderAI | GetCalendarEvent] Invalid connection type: " + prefs_at.connection_type); taWorkingStatus.stopWorking(); @@ -243,7 +275,11 @@ export class mzta_Menus { */ fullPrompt = taPromptUtils.finalizePrompt_get_calendar_event(fullPrompt); this.logger.log("fullPrompt: " + fullPrompt); - let cmd_GetCalendarEvent = new mzta_specialCommand(fullPrompt,prefs_at.connection_type,true); + let cmd_GetCalendarEvent = new mzta_specialCommand({ + prompt: fullPrompt, + llm: prefs_at.connection_type, + do_debug: true + }); await cmd_GetCalendarEvent.initWorker(); try{ calendar_event_data = await cmd_GetCalendarEvent.sendPrompt(); @@ -311,7 +347,11 @@ export class mzta_Menus { * } */ this.logger.log("fullPrompt: " + fullPrompt); - let cmd_GetTask = new mzta_specialCommand(fullPrompt,prefs_at.connection_type,true); + let cmd_GetTask = new mzta_specialCommand({ + prompt: fullPrompt, + llm: prefs_at.connection_type, + do_debug: true + }); await cmd_GetTask.initWorker(); try{ task_data = await cmd_GetTask.sendPrompt(); @@ -377,6 +417,7 @@ export class mzta_Menus { } }else{ // Classic prompts for the API webchat this.logger.log("fullPrompt: " + fullPrompt); + this.logger.log("curr_prompt: " + JSON.stringify(curr_prompt)); this.openChatGPT(fullPrompt, curr_prompt.action, tabs[0].id, curr_prompt.name, curr_prompt.need_custom_text, curr_prompt); taWorkingStatus.stopWorking(); return {ok:'1'}; @@ -500,4 +541,4 @@ export class mzta_Menus { return false; } -} \ No newline at end of file +} diff --git a/js/mzta-placeholders.js b/js/mzta-placeholders.js index fb08a387..0eb6f926 100644 --- a/js/mzta-placeholders.js +++ b/js/mzta-placeholders.js @@ -16,6 +16,8 @@ * along with this program. If not, see| __MSG_prefs_OptionText_use_specific_integration__ + | ++ + | +|
| __MSG_prefs_OptionText_add_tags_maxnum__ | +__MSG_prefs_OptionText_add_tags_maxnum__ | |
| __MSG_prefs_OptionText_add_tags_exclusions_exact_match__ | +__MSG_prefs_OptionText_add_tags_exclusions_exact_match__ | |
| __MSG_prefs_OptionText_add_tags_hide_exclusions__ | +__MSG_prefs_OptionText_add_tags_hide_exclusions__ | |
| __MSG_prefs_OptionText_add_tags_first_uppercase__ | +__MSG_prefs_OptionText_add_tags_first_uppercase__ | |
| __MSG_prefs_OptionText_add_tags_force_lang__ | +__MSG_prefs_OptionText_add_tags_force_lang__ | |
| __MSG_prefs_OptionText_add_tags_auto__ + | __MSG_prefs_OptionText_add_tags_auto__ | |
| __MSG_prefs_OptionText_add_tags_auto_only_inbox__ | +__MSG_prefs_OptionText_add_tags_auto_only_inbox__ | |
| __MSG_prefs_OptionText_add_tags_auto_uselist__ | +__MSG_prefs_OptionText_add_tags_auto_uselist__ | |
| __MSG_prefs_OptionText_add_tags_context_menu__ | +__MSG_prefs_OptionText_add_tags_context_menu__ | |
| __MSG_prefs_OptionText_add_tags_auto_force_existing__ | +__MSG_prefs_OptionText_add_tags_auto_force_existing__ | |