specific integration settings are now saved at prompt level. see #102
This commit is contained in:
parent
9429395030
commit
e3d927ab29
7 changed files with 109 additions and 37 deletions
|
|
@ -19,7 +19,10 @@
|
|||
// 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 { prefs_default } from '../options/mzta-options-default.js';
|
||||
import {
|
||||
prefs_default,
|
||||
getDynamicSettingsDefaults
|
||||
} from '../options/mzta-options-default.js';
|
||||
import {
|
||||
getLanguageDisplayName,
|
||||
getMenuContextCompose,
|
||||
|
|
@ -222,7 +225,8 @@ export class mzta_Menus {
|
|||
prompt: fullPrompt,
|
||||
llm: def_conntype,
|
||||
custom_model: curr_prompt.model ? curr_prompt.model : '',
|
||||
do_debug: prefs_at.do_debug
|
||||
do_debug: prefs_at.do_debug,
|
||||
config: curr_prompt
|
||||
});
|
||||
await cmd_addTags.initWorker();
|
||||
try{
|
||||
|
|
@ -258,9 +262,11 @@ export class mzta_Menus {
|
|||
connection_type: prefs_default.connection_type,
|
||||
calendar_enforce_timezone: prefs_default.calendar_enforce_timezone,
|
||||
calendar_timezone: prefs_default.calendar_timezone,
|
||||
...getDynamicSettingsDefaults(['use_specific_integration', 'connection_type'])
|
||||
});
|
||||
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);
|
||||
let def_conntype = getConnectionType(prefs_at, curr_prompt, 'get_calendar_event');
|
||||
if((def_conntype === '')||(def_conntype === null)||(def_conntype === undefined)||(def_conntype === 'chatgpt_web')){
|
||||
console.error("[ThunderAI | GetCalendarEvent] Invalid connection type: " + def_conntype);
|
||||
taWorkingStatus.stopWorking();
|
||||
return {ok:'0'};
|
||||
}
|
||||
|
|
@ -277,8 +283,9 @@ export class mzta_Menus {
|
|||
this.logger.log("fullPrompt: " + fullPrompt);
|
||||
let cmd_GetCalendarEvent = new mzta_specialCommand({
|
||||
prompt: fullPrompt,
|
||||
llm: prefs_at.connection_type,
|
||||
do_debug: true
|
||||
llm: def_conntype,
|
||||
do_debug: true,
|
||||
config: curr_prompt
|
||||
});
|
||||
await cmd_GetCalendarEvent.initWorker();
|
||||
try{
|
||||
|
|
@ -333,9 +340,14 @@ export class mzta_Menus {
|
|||
}
|
||||
case 'prompt_get_task': { // Get a task info
|
||||
let task_data = '';
|
||||
let prefs_at = await browser.storage.sync.get({connection_type: '', calendar_enforce_timezone: false, 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 | GetTask] Invalid connection type: " + prefs_at.connection_type);
|
||||
let prefs_at = await browser.storage.sync.get({
|
||||
connection_type: '',
|
||||
calendar_enforce_timezone: false,
|
||||
calendar_timezone: '',
|
||||
...getDynamicSettingsDefaults(['use_specific_integration', 'connection_type'])});
|
||||
let def_conntype = getConnectionType(prefs_at, curr_prompt, 'get_task');
|
||||
if((def_conntype === '')||(def_conntype === null)||(def_conntype === undefined)||(def_conntype === 'chatgpt_web')){
|
||||
console.error("[ThunderAI | GetTask] Invalid connection type: " + def_conntype);
|
||||
taWorkingStatus.stopWorking();
|
||||
return {ok:'0'};
|
||||
}
|
||||
|
|
@ -349,8 +361,9 @@ export class mzta_Menus {
|
|||
this.logger.log("fullPrompt: " + fullPrompt);
|
||||
let cmd_GetTask = new mzta_specialCommand({
|
||||
prompt: fullPrompt,
|
||||
llm: prefs_at.connection_type,
|
||||
do_debug: true
|
||||
llm: def_conntype,
|
||||
do_debug: true,
|
||||
config: curr_prompt
|
||||
});
|
||||
await cmd_GetTask.initWorker();
|
||||
try{
|
||||
|
|
|
|||
|
|
@ -29,17 +29,20 @@
|
|||
full_message = "";
|
||||
logger = null;
|
||||
do_debug = false;
|
||||
config = {};
|
||||
|
||||
constructor(args = {}) {
|
||||
let {
|
||||
prompt = '',
|
||||
llm = '',
|
||||
custom_model = '',
|
||||
do_debug = false
|
||||
do_debug = false,
|
||||
config = {}
|
||||
} = args;
|
||||
this.prompt = prompt;
|
||||
this.llm = llm;
|
||||
this.custom_model = custom_model;
|
||||
this.config = config;
|
||||
this.logger = new taLogger('mzta_specialCommand', do_debug);
|
||||
this.do_debug = do_debug;
|
||||
switch (this.llm) {
|
||||
|
|
@ -73,6 +76,11 @@
|
|||
chatgpt_model: prefs_default.chatgpt_model,
|
||||
chatgpt_developer_messages: prefs_default.chatgpt_developer_messages,
|
||||
});
|
||||
|
||||
if (this.config.chatgpt_api_key) prefs_api.chatgpt_api_key = this.config.chatgpt_api_key;
|
||||
if (this.config.chatgpt_model) prefs_api.chatgpt_model = this.config.chatgpt_model;
|
||||
if (this.config.chatgpt_developer_messages) prefs_api.chatgpt_developer_messages = this.config.chatgpt_developer_messages;
|
||||
|
||||
this.worker.postMessage({
|
||||
type: 'init',
|
||||
chatgpt_api_key: prefs_api.chatgpt_api_key,
|
||||
|
|
@ -90,6 +98,12 @@
|
|||
google_gemini_system_instruction: prefs_default.google_gemini_system_instruction,
|
||||
google_gemini_thinking_budget: prefs_default.google_gemini_thinking_budget,
|
||||
});
|
||||
|
||||
if (this.config.google_gemini_api_key) prefs_api.google_gemini_api_key = this.config.google_gemini_api_key;
|
||||
if (this.config.google_gemini_model) prefs_api.google_gemini_model = this.config.google_gemini_model;
|
||||
if (this.config.google_gemini_system_instruction) prefs_api.google_gemini_system_instruction = this.config.google_gemini_system_instruction;
|
||||
if (this.config.google_gemini_thinking_budget) prefs_api.google_gemini_thinking_budget = this.config.google_gemini_thinking_budget;
|
||||
|
||||
this.worker.postMessage({
|
||||
type: 'init',
|
||||
google_gemini_api_key: prefs_api.google_gemini_api_key,
|
||||
|
|
@ -106,6 +120,10 @@
|
|||
ollama_host: prefs_default.ollama_host,
|
||||
ollama_model: prefs_default.ollama_model,
|
||||
});
|
||||
|
||||
if (this.config.ollama_host) prefs_api.ollama_host = this.config.ollama_host;
|
||||
if (this.config.ollama_model) prefs_api.ollama_model = this.config.ollama_model;
|
||||
|
||||
this.worker.postMessage({
|
||||
type: 'init',
|
||||
ollama_host: prefs_api.ollama_host,
|
||||
|
|
@ -124,6 +142,13 @@
|
|||
openai_comp_chat_name: prefs_default.openai_comp_chat_name,
|
||||
do_debug: prefs_default.do_debug,
|
||||
});
|
||||
|
||||
if (this.config.openai_comp_host) prefs_api.openai_comp_host = this.config.openai_comp_host;
|
||||
if (this.config.openai_comp_model) prefs_api.openai_comp_model = this.config.openai_comp_model;
|
||||
if (this.config.openai_comp_api_key) prefs_api.openai_comp_api_key = this.config.openai_comp_api_key;
|
||||
if (this.config.openai_comp_use_v1 !== undefined) prefs_api.openai_comp_use_v1 = this.config.openai_comp_use_v1;
|
||||
if (this.config.openai_comp_chat_name) prefs_api.openai_comp_chat_name = this.config.openai_comp_chat_name;
|
||||
|
||||
this.worker.postMessage({
|
||||
type: 'init',
|
||||
openai_comp_host: prefs_api.openai_comp_host,
|
||||
|
|
@ -142,6 +167,12 @@
|
|||
anthropic_version: prefs_default.anthropic_version,
|
||||
anthropic_max_tokens: prefs_default.anthropic_max_tokens,
|
||||
});
|
||||
|
||||
if (this.config.anthropic_api_key) prefs_api.anthropic_api_key = this.config.anthropic_api_key;
|
||||
if (this.config.anthropic_model) prefs_api.anthropic_model = this.config.anthropic_model;
|
||||
if (this.config.anthropic_version) prefs_api.anthropic_version = this.config.anthropic_version;
|
||||
if (this.config.anthropic_max_tokens) prefs_api.anthropic_max_tokens = this.config.anthropic_max_tokens;
|
||||
|
||||
this.worker.postMessage({
|
||||
type: 'init',
|
||||
anthropic_api_key: prefs_api.anthropic_api_key,
|
||||
|
|
|
|||
|
|
@ -1084,7 +1084,8 @@ async function processEmails(messages, addTagsAuto, spamFilter) {
|
|||
prompt: specialFullPrompt_add_tags,
|
||||
llm: getConnectionType(prefs_aats, curr_prompt_add_tags, 'add_tags'),
|
||||
custom_model: curr_prompt_add_tags.model ? curr_prompt_add_tags.model : '',
|
||||
do_debug: prefs_aats.do_debug
|
||||
do_debug: prefs_aats.do_debug,
|
||||
config: curr_prompt_add_tags
|
||||
});
|
||||
await cmd_addTags.initWorker();
|
||||
let tags_current_email = [];
|
||||
|
|
@ -1123,7 +1124,8 @@ async function processEmails(messages, addTagsAuto, spamFilter) {
|
|||
prompt: specialFullPrompt_spamfilter,
|
||||
llm: getConnectionType(prefs_aats, curr_prompt_spamfilter, 'spamfilter'),
|
||||
custom_model: curr_prompt_spamfilter.model ? curr_prompt_spamfilter.model : '',
|
||||
do_debug: prefs_aats.do_debug
|
||||
do_debug: prefs_aats.do_debug,
|
||||
config: curr_prompt_spamfilter
|
||||
});
|
||||
await cmd_spamfilter.initWorker();
|
||||
let spamfilter_result = '';
|
||||
|
|
|
|||
|
|
@ -63,9 +63,11 @@ const integration_settings_template = {
|
|||
connection_type: 'chatgpt_api',
|
||||
};
|
||||
|
||||
const global_integration_settings = { ...integration_settings_template };
|
||||
|
||||
for (const [integration, options] of Object.entries(integration_options_config)) {
|
||||
for (const [key, value] of Object.entries(options)) {
|
||||
integration_settings_template[`${integration}_${key}`] = value;
|
||||
global_integration_settings[`${integration}_${key}`] = value;
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -93,7 +95,7 @@ export function getDynamicSettingValue(prefs, prefix, settingName) {
|
|||
}
|
||||
|
||||
export const prefs_default = {
|
||||
...integration_settings_template,
|
||||
...global_integration_settings,
|
||||
do_debug: false,
|
||||
chatgpt_win_height: 800,
|
||||
chatgpt_win_width: 700,
|
||||
|
|
|
|||
|
|
@ -16,7 +16,10 @@
|
|||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
import { prefs_default, integration_options_config } from '../../options/mzta-options-default.js';
|
||||
import {
|
||||
prefs_default,
|
||||
integration_options_config
|
||||
} from '../../options/mzta-options-default.js';
|
||||
import { OpenAI } from '../../js/api/openai_responses.js';
|
||||
import { Ollama } from '../../js/api/ollama.js';
|
||||
import { OpenAIComp } from '../../js/api/openai_comp.js'
|
||||
|
|
@ -1002,19 +1005,19 @@ export async function initializeSpecificIntegrationUI({
|
|||
// Helper to update prompt
|
||||
const _updatePrompt = async () => {
|
||||
let conntype = conntype_el.value;
|
||||
let integration = conntype.replace('_api', '');
|
||||
|
||||
let prompt = await loadPrompt(promptId);
|
||||
if(!prompt) return;
|
||||
|
||||
prompt.api = conntype;
|
||||
|
||||
if (integration_options_config[integration]) {
|
||||
for (const key of Object.keys(integration_options_config[integration])) {
|
||||
let elementId = `${model_prefix}${integration}_${key}`;
|
||||
for (const [integration, options] of Object.entries(integration_options_config)) {
|
||||
for (const key of Object.keys(options)) {
|
||||
let propName = `${integration}_${key}`;
|
||||
let elementId = `${model_prefix}${propName}`;
|
||||
let element = document.getElementById(elementId);
|
||||
if (element) {
|
||||
prompt[key] = (element.type === 'checkbox') ? element.checked : element.value;
|
||||
prompt[propName] = (element.type === 'checkbox') ? element.checked : element.value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -339,5 +339,23 @@ async function restoreOptions() {
|
|||
}
|
||||
|
||||
let getting = await browser.storage.sync.get(prefs_default);
|
||||
|
||||
let specialPrompts = await getSpecialPrompts();
|
||||
let addtags_prompt = specialPrompts.find(prompt => prompt.id === 'prompt_add_tags');
|
||||
|
||||
if (addtags_prompt) {
|
||||
if (addtags_prompt.api && addtags_prompt.api !== '') {
|
||||
getting['add_tags_connection_type'] = addtags_prompt.api;
|
||||
}
|
||||
for (const [integration, options] of Object.entries(integration_options_config)) {
|
||||
for (const key of Object.keys(options)) {
|
||||
const propName = `${integration}_${key}`;
|
||||
if (addtags_prompt[propName] !== undefined) {
|
||||
getting[`add_tags_${propName}`] = addtags_prompt[propName];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setCurrentChoice(getting);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,21 +42,6 @@ document.addEventListener('DOMContentLoaded', async () => {
|
|||
let specialPrompts = await getSpecialPrompts();
|
||||
let spamfilter_prompt = specialPrompts.find(prompt => prompt.id === 'prompt_spamfilter');
|
||||
|
||||
if (spamfilter_prompt && spamfilter_prompt.api && spamfilter_prompt.api !== '') {
|
||||
let update_prefs = {};
|
||||
update_prefs['spamfilter_connection_type'] = spamfilter_prompt.api;
|
||||
|
||||
let integration = spamfilter_prompt.api.replace('_api', '');
|
||||
if (integration_options_config && integration_options_config[integration]) {
|
||||
for (const key of Object.keys(integration_options_config[integration])) {
|
||||
if (spamfilter_prompt[key] !== undefined) {
|
||||
update_prefs[`spamfilter_${integration}_${key}`] = spamfilter_prompt[key];
|
||||
}
|
||||
}
|
||||
}
|
||||
await browser.storage.sync.set(update_prefs);
|
||||
}
|
||||
|
||||
await initializeSpecificIntegrationUI({
|
||||
prefix: 'spamfilter',
|
||||
promptId: 'prompt_spamfilter',
|
||||
|
|
@ -323,5 +308,23 @@ async function restoreOptions() {
|
|||
}
|
||||
|
||||
let getting = await browser.storage.sync.get(prefs_default);
|
||||
|
||||
let specialPrompts = await getSpecialPrompts();
|
||||
let spamfilter_prompt = specialPrompts.find(prompt => prompt.id === 'prompt_spamfilter');
|
||||
|
||||
if (spamfilter_prompt) {
|
||||
if (spamfilter_prompt.api && spamfilter_prompt.api !== '') {
|
||||
getting['spamfilter_connection_type'] = spamfilter_prompt.api;
|
||||
}
|
||||
for (const [integration, options] of Object.entries(integration_options_config)) {
|
||||
for (const key of Object.keys(options)) {
|
||||
const propName = `${integration}_${key}`;
|
||||
if (spamfilter_prompt[propName] !== undefined) {
|
||||
getting[`spamfilter_${propName}`] = spamfilter_prompt[propName];
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
setCurrentChoice(getting);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue