Improved the AI web chat init message

This commit is contained in:
Mic 2025-06-19 21:36:28 +02:00
parent 8608501da0
commit 647f23a50b
4 changed files with 27 additions and 33 deletions

View file

@ -1472,7 +1472,7 @@
"description": ""
},
"_api_connecting": {
"message": "Attempting to connect to $api_string$ using the following configuration:",
"message": "Attempting to connect to $api_string$ using the following configuration...",
"description": "",
"placeholders": {
"api_string": {
@ -1481,31 +1481,16 @@
}
},
"_api_connecting_model": {
"message": "Model: $model$",
"description": "",
"placeholders": {
"model": {
"content": "$1"
}
}
"message": "Model",
"description": ""
},
"_api_connecting_host": {
"message": "Host: $api_host$",
"description": "",
"placeholders": {
"api_host": {
"content": "$1"
}
}
"message": "Host",
"description": ""
},
"_api_connecting_version": {
"message": "Version: $api_version$",
"description": "",
"placeholders": {
"api_version": {
"content": "$1"
}
}
"message": "Version",
"description": ""
},
"prefs_OpenAIComp_AvailableServices": {
"message": "Available Services",

View file

@ -80,11 +80,12 @@ switch (llm) {
messageInput.setModel(prefs_api.chatgpt_model);
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, chatgpt_api_store: prefs_api.chatgpt_api_store, do_debug: prefs_api.do_debug, i18nStrings: i18nStrings});
let additional_text = 'OpenAI Store: ' + (prefs_api.chatgpt_api_store ? 'Yes' : 'No');
let additional_text_elements = [];
additional_text_elements.push({label: 'OpenAI Store', value: (prefs_api.chatgpt_api_store ? 'Yes' : 'No')});
if(prefs_api.chatgpt_developer_messages && prefs_api.chatgpt_developer_messages.length > 0) {
additional_text += "\n" + browser.i18n.getMessage("ChatGPT_Developer_Messages") + ": " + prefs_api.chatgpt_developer_messages;
additional_text_elements.push({label: browser.i18n.getMessage("ChatGPT_Developer_Messages"), value: prefs_api.chatgpt_developer_messages});
}
messagesArea.appendUserMessage(getAPIsInitMessageString("ChatGPT API", prefs_api.chatgpt_model, '', '', additional_text), "info");
messagesArea.appendUserMessage(getAPIsInitMessageString("ChatGPT API", prefs_api.chatgpt_model, '', '', additional_text_elements), "info");
browser.runtime.sendMessage({command: "openai_api_ready_" + call_id, window_id: (await browser.windows.getCurrent()).id});
break;
}
@ -95,12 +96,12 @@ switch (llm) {
i18nStrings["error_connection_interrupted"] = browser.i18n.getMessage('error_connection_interrupted');
messageInput.setModel(prefs_api.google_gemini_model);
messagesArea.setLLMName("Google Gemini");
let additional_text = '';
let additional_text_elements = [];
if(prefs_api.google_gemini_system_instruction && prefs_api.google_gemini_system_instruction.length > 0) {
additional_text += browser.i18n.getMessage("GoogleGemini_SystemInstruction") + ": " + prefs_api.google_gemini_system_instruction;
additional_text_elements.push({label: browser.i18n.getMessage("GoogleGemini_SystemInstruction"), value: prefs_api.google_gemini_system_instruction});
}
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(getAPIsInitMessageString("Google Gemini API", prefs_api.google_gemini_model, '', '', additional_text), "info");
messagesArea.appendUserMessage(getAPIsInitMessageString("Google Gemini API", prefs_api.google_gemini_model, '', '', additional_text_elements), "info");
browser.runtime.sendMessage({command: "google_gemini_api_ready_" + call_id, window_id: (await browser.windows.getCurrent()).id});
break;
}

View file

@ -103,6 +103,10 @@ messagesAreaStyle.textContent = `
background: lightblue;
color: navy;
margin-bottom: var(--margin);
font-size: 0.8em;
}
.info_obj{
color:rgb(0, 71, 36);
}
.sel_info{
font-size: 0.7rem;

View file

@ -454,16 +454,20 @@ export async function transformTagsLabels(labels, tags_list) {
return output;
}
export function getAPIsInitMessageString(api_string, model_string = '', host_string = '', version_string = '', additional_message = '') {
let output = browser.i18n.getMessage("_api_connecting", api_string);
export function getAPIsInitMessageString(api_string, model_string = '', host_string = '', version_string = '', additional_messages = []) {
let output = "<i class='info_obj'>" + browser.i18n.getMessage("_api_connecting", api_string) + "</i>";
if (model_string !== '') {
output += "\n" + browser.i18n.getMessage("_api_connecting_model", model_string);
output += "\n<span class='info_obj'>" + browser.i18n.getMessage("_api_connecting_model") + ":</span> " + model_string;
}
if (host_string !== '') {
output += "\n" + browser.i18n.getMessage("_api_connecting_host", host_string);
output += "\n<span class='info_obj'>" + browser.i18n.getMessage("_api_connecting_host") + ":</span> " + host_string;
}
if (version_string !== '') {
output += "\n" + browser.i18n.getMessage("_api_connecting_version", version_string);
output += "\n<span class='info_obj'>" + browser.i18n.getMessage("_api_connecting_version") + ":</span> " + version_string;
}
let additional_message = '';
if (additional_messages.length > 0) {
additional_message = additional_messages.map(msg => "<span class='info_obj'>" + msg.label + ":</span> " + msg.value).join("\n");
}
if (additional_message !== '') {
output += "\n" + additional_message;