Add API connection messages and refactor initialization logging

This commit is contained in:
mic 2025-05-21 21:49:33 +02:00
parent 9c8f844ac1
commit 95f6c0e40f
3 changed files with 57 additions and 28 deletions

View file

@ -451,10 +451,6 @@
"message": "Using model", "message": "Using model",
"description": "" "description": ""
}, },
"chagpt_api_connecting": {
"message": "Attempting to connect to OpenAI ChatGPT using the API key provided",
"description": ""
},
"Debug": { "Debug": {
"message": "Debug", "message": "Debug",
"description": "" "description": ""
@ -499,14 +495,6 @@
"message": "You've not choosen a model for the Ollama API. Please choose one in the options page.", "message": "You've not choosen a model for the Ollama API. Please choose one in the options page.",
"description": "" "description": ""
}, },
"ollama_api_connecting": {
"message": "Attempting to connect to the Ollama Local Server using the host",
"description": ""
},
"andModel": {
"message": "and model",
"description": ""
},
"error_connection_interrupted": { "error_connection_interrupted": {
"message": "The connection to the server was unexpectedly interrupted", "message": "The connection to the server was unexpectedly interrupted",
"description": "" "description": ""
@ -547,10 +535,6 @@
"message": "You've not choosen a model for the OpenAI Compatible API. Please choose one in the options page.", "message": "You've not choosen a model for the OpenAI Compatible API. Please choose one in the options page.",
"description": "" "description": ""
}, },
"OpenAIComp_api_connecting": {
"message": "Attempting to connect to the OpenAI Compatible API Local Server using the host",
"description": ""
},
"OpenAIComp_api_request_failed": { "OpenAIComp_api_request_failed": {
"message": "OpenAI Comp API request failed", "message": "OpenAI Comp API request failed",
"description": "" "description": ""
@ -955,10 +939,6 @@
"message": "Google Gemini API request failed", "message": "Google Gemini API request failed",
"description": "" "description": ""
}, },
"google_gemini_api_connecting": {
"message": "Attempting to connect to Google Gemini using the API key provided",
"description": ""
},
"google_gemini_empty_apikey": { "google_gemini_empty_apikey": {
"message": "You've not added an API Key for the Google Gemini API. Please insert one in the options page.", "message": "You've not added an API Key for the Google Gemini API. Please insert one in the options page.",
"description": "" "description": ""
@ -1491,8 +1471,40 @@
"message": "Anthropic API request failed", "message": "Anthropic API request failed",
"description": "" "description": ""
}, },
"anthropic_api_connecting": { "_api_connecting": {
"message": "Attempting to connect to Anthropic API using the API key provided", "message": "Attempting to connect to $api_string$ using the following configuration:",
"description": "" "description": "",
"placeholders": {
"api_string": {
"content": "$1"
}
}
},
"_api_connecting_model": {
"message": "Model: $model$",
"description": "",
"placeholders": {
"model": {
"content": "$1"
}
}
},
"_api_connecting_host": {
"message": "Host: $api_host$",
"description": "",
"placeholders": {
"api_host": {
"content": "$1"
}
}
},
"_api_connecting_version": {
"message": "Version: $api_version$",
"description": "",
"placeholders": {
"api_version": {
"content": "$1"
}
}
} }
} }

View file

@ -21,6 +21,7 @@
*/ */
import { placeholdersUtils } from '../js/mzta-placeholders.js'; import { placeholdersUtils } from '../js/mzta-placeholders.js';
import { getAPIsInitMessageString } from '../js/mzta-utils.js';
// Get the LLM to be used // Get the LLM to be used
const urlParams = new URLSearchParams(window.location.search); const urlParams = new URLSearchParams(window.location.search);
@ -79,7 +80,7 @@ switch (llm) {
messageInput.setModel(prefs_api.chatgpt_model); messageInput.setModel(prefs_api.chatgpt_model);
messagesArea.setLLMName("ChatGPT"); messagesArea.setLLMName("ChatGPT");
worker.postMessage({ type: 'init', chatgpt_api_key: prefs_api.chatgpt_api_key, chatgpt_model: prefs_api.chatgpt_model, chatgpt_developer_messages: prefs_api.chatgpt_developer_messages, do_debug: prefs_api.do_debug, i18nStrings: i18nStrings}); worker.postMessage({ type: 'init', chatgpt_api_key: prefs_api.chatgpt_api_key, chatgpt_model: prefs_api.chatgpt_model, chatgpt_developer_messages: prefs_api.chatgpt_developer_messages, do_debug: prefs_api.do_debug, i18nStrings: i18nStrings});
messagesArea.appendUserMessage(browser.i18n.getMessage("chagpt_api_connecting") + " " +browser.i18n.getMessage("AndModel") + " \"" + prefs_api.chatgpt_model + "\"...", "info"); messagesArea.appendUserMessage(getAPIsInitMessageString("ChatGPT API", prefs_api.chatgpt_model), "info");
browser.runtime.sendMessage({command: "openai_api_ready_" + call_id, window_id: (await browser.windows.getCurrent()).id}); browser.runtime.sendMessage({command: "openai_api_ready_" + call_id, window_id: (await browser.windows.getCurrent()).id});
break; break;
} }
@ -91,7 +92,7 @@ switch (llm) {
messageInput.setModel(prefs_api.google_gemini_model); messageInput.setModel(prefs_api.google_gemini_model);
messagesArea.setLLMName("Google Gemini"); messagesArea.setLLMName("Google Gemini");
worker.postMessage({ type: 'init', google_gemini_api_key: prefs_api.google_gemini_api_key, google_gemini_model: prefs_api.google_gemini_model, google_gemini_system_instruction: prefs_api.google_gemini_system_instruction, do_debug: prefs_api.do_debug, i18nStrings: i18nStrings}); worker.postMessage({ type: 'init', google_gemini_api_key: prefs_api.google_gemini_api_key, google_gemini_model: prefs_api.google_gemini_model, google_gemini_system_instruction: prefs_api.google_gemini_system_instruction, do_debug: prefs_api.do_debug, i18nStrings: i18nStrings});
messagesArea.appendUserMessage(browser.i18n.getMessage("google_gemini_api_connecting") + " " +browser.i18n.getMessage("AndModel") + " \"" + prefs_api.google_gemini_model + "\"...", "info"); messagesArea.appendUserMessage(getAPIsInitMessageString("Google Gemini API", prefs_api.google_gemini_model), "info");
browser.runtime.sendMessage({command: "google_gemini_api_ready_" + call_id, window_id: (await browser.windows.getCurrent()).id}); browser.runtime.sendMessage({command: "google_gemini_api_ready_" + call_id, window_id: (await browser.windows.getCurrent()).id});
break; break;
} }
@ -104,7 +105,7 @@ switch (llm) {
messagesArea.setLLMName("Ollama Local"); messagesArea.setLLMName("Ollama Local");
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}); 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}); 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"); messagesArea.appendUserMessage(getAPIsInitMessageString("Ollama API", prefs_api.ollama_model, prefs_api.ollama_host), "info");
break; break;
} }
case "openai_comp_api": { case "openai_comp_api": {
@ -115,7 +116,7 @@ switch (llm) {
messageInput.setModel(prefs_api.openai_comp_model); messageInput.setModel(prefs_api.openai_comp_model);
messagesArea.setLLMName(prefs_api.openai_comp_chat_name); messagesArea.setLLMName(prefs_api.openai_comp_chat_name);
worker.postMessage({ type: 'init', openai_comp_host: prefs_api.openai_comp_host, openai_comp_model: prefs_api.openai_comp_model, openai_comp_api_key: prefs_api.openai_comp_api_key, openai_comp_use_v1: prefs_api.openai_comp_use_v1, do_debug: prefs_api.do_debug, i18nStrings: i18nStrings}); worker.postMessage({ type: 'init', openai_comp_host: prefs_api.openai_comp_host, openai_comp_model: prefs_api.openai_comp_model, openai_comp_api_key: prefs_api.openai_comp_api_key, openai_comp_use_v1: prefs_api.openai_comp_use_v1, do_debug: prefs_api.do_debug, i18nStrings: i18nStrings});
messagesArea.appendUserMessage(browser.i18n.getMessage("OpenAIComp_api_connecting") + " \"" + prefs_api.openai_comp_host + "\" " +browser.i18n.getMessage("AndModel") + " \"" + prefs_api.openai_comp_model + "\"...", "info"); messagesArea.appendUserMessage(getAPIsInitMessageString("OpenAI Compatible API", prefs_api.openai_comp_model, prefs_api.openai_comp_host), "info");
browser.runtime.sendMessage({command: "openai_comp_api_ready_" + call_id, window_id: (await browser.windows.getCurrent()).id}); browser.runtime.sendMessage({command: "openai_comp_api_ready_" + call_id, window_id: (await browser.windows.getCurrent()).id});
break; break;
} }
@ -127,7 +128,7 @@ switch (llm) {
messageInput.setModel(prefs_api.anthropic_model); messageInput.setModel(prefs_api.anthropic_model);
messagesArea.setLLMName("Anthropic"); messagesArea.setLLMName("Anthropic");
worker.postMessage({ type: 'init', anthropic_api_key: prefs_api.anthropic_api_key, anthropic_model: prefs_api.anthropic_model, anthropic_version: prefs_api.anthropic_version, anthropic_max_tokens: prefs_api.anthropic_max_tokens, do_debug: prefs_api.do_debug, i18nStrings: i18nStrings}); worker.postMessage({ type: 'init', anthropic_api_key: prefs_api.anthropic_api_key, anthropic_model: prefs_api.anthropic_model, anthropic_version: prefs_api.anthropic_version, anthropic_max_tokens: prefs_api.anthropic_max_tokens, do_debug: prefs_api.do_debug, i18nStrings: i18nStrings});
messagesArea.appendUserMessage(browser.i18n.getMessage("anthropic_api_connecting") + " " +browser.i18n.getMessage("AndModel") + " \"" + prefs_api.anthropic_model + "\"...", "info"); messagesArea.appendUserMessage(getAPIsInitMessageString("Anthropic API", prefs_api.anthropic_model, '', prefs_api.anthropic_version), "info");
browser.runtime.sendMessage({command: "anthropic_api_ready_" + call_id, window_id: (await browser.windows.getCurrent()).id}); browser.runtime.sendMessage({command: "anthropic_api_ready_" + call_id, window_id: (await browser.windows.getCurrent()).id});
break; break;
} }

View file

@ -401,6 +401,21 @@ export async function transformTagsLabels(labels, tags_list) {
return output; return output;
} }
export function getAPIsInitMessageString(api_string, model_string = '', host_string = '', version_string = '') {
let output = browser.i18n.getMessage("_api_connecting", api_string);
if (model_string !== '') {
output += "\n" + browser.i18n.getMessage("_api_connecting_model", model_string);
}
if (host_string !== '') {
output += "\n" + browser.i18n.getMessage("_api_connecting_host", host_string);
}
if (version_string !== '') {
output += "\n" + browser.i18n.getMessage("_api_connecting_version", version_string);
}
return output;
}
export function getActiveSpecialPromptsIDs(args = {}) { export function getActiveSpecialPromptsIDs(args = {}) {
const { addtags = false, get_calendar_event = false, get_task = false, is_chatgpt_web = false } = args; const { addtags = false, get_calendar_event = false, get_task = false, is_chatgpt_web = false } = args;
let output = []; let output = [];
@ -475,6 +490,7 @@ export function validateCustomData_ChatGPTWeb(event) {
document.getElementById(event.target.id + '_info').style.color = is_valid ? '' : 'red'; document.getElementById(event.target.id + '_info').style.color = is_valid ? '' : 'red';
} }
// The following methods are a modified version derived from https://github.com/ali-raheem/Aify/blob/13ff87583bc520fb80f555ab90a90c5c9df797a7/plugin/content_scripts/compose.js // The following methods are a modified version derived from https://github.com/ali-raheem/Aify/blob/13ff87583bc520fb80f555ab90a90c5c9df797a7/plugin/content_scripts/compose.js
const insertHtml = function (replyHtml, fullBody_string) { const insertHtml = function (replyHtml, fullBody_string) {