diff --git a/api_webchat/controller.js b/api_webchat/controller.js index e4ac25ed..61e71e05 100644 --- a/api_webchat/controller.js +++ b/api_webchat/controller.js @@ -55,10 +55,10 @@ let promptData = null; // ============================== TESTING - END const params = new URLSearchParams(window.location.search); -let prefs_api = await browser.storage.sync.get({api_key_chatgpt: '', model_chatgpt: ''}); +let prefs_api = await browser.storage.sync.get({chatgpt_api_key: '', chatgpt_model: ''}); // const openaiApiKey = params.get('openapi-key'); -//console.log(">>>>>>>>>>> api_key_chatgpt: " + prefs_api_key.api_key_chatgpt); -worker.postMessage({ type: 'init', api_key_chatgpt: prefs_api.api_key_chatgpt, model_chatgpt: prefs_api.model_chatgpt}); +//console.log(">>>>>>>>>>> chatgpt_api_key: " + prefs_api_key.chatgpt_api_key); +worker.postMessage({ type: 'init', chatgpt_api_key: prefs_api.chatgpt_api_key, chatgpt_model: prefs_api.chatgpt_model}); messagesArea.appendUserMessage(browser.i18n.getMessage("chagtp_api_connecting"), "info"); // Event listeners for worker messages diff --git a/api_webchat/messageInput.js b/api_webchat/messageInput.js index 4533ac43..194634d5 100644 --- a/api_webchat/messageInput.js +++ b/api_webchat/messageInput.js @@ -107,8 +107,8 @@ class MessageInput extends HTMLElement { async init(worker) { this.worker = worker; - let prefs_api = await browser.storage.sync.get({model_chatgpt: ''}); - this._sendButton.title = await browser.i18n.getMessage("chagtp_api_send_button") + ": " + prefs_api.model_chatgpt; + let prefs_api = await browser.storage.sync.get({chatgpt_model: ''}); + this._sendButton.title = await browser.i18n.getMessage("chagtp_api_send_button") + ": " + prefs_api.chatgpt_model; } setMessagesArea(messagesAreaComponent) { diff --git a/api_webchat/model-worker.js b/api_webchat/model-worker.js index 23e570aa..6858bd5b 100644 --- a/api_webchat/model-worker.js +++ b/api_webchat/model-worker.js @@ -39,8 +39,8 @@ import { OpenAI } from '../js/api/openai.js'; //========================== for testing - END -let api_key_chatgpt = null; -let model_chatgpt = ''; +let chatgpt_api_key = null; +let chatgpt_model = ''; let openai = null; let conversationHistory = []; @@ -48,10 +48,10 @@ let assistantResponseAccumulator = ''; self.onmessage = async function(event) { if (event.data.type === 'init') { - api_key_chatgpt = event.data.api_key_chatgpt; - model_chatgpt = event.data.model_chatgpt; - //console.log(">>>>>>>>>>> api_key_chatgpt: " + api_key_chatgpt); - openai = new OpenAI(api_key_chatgpt, model_chatgpt, true); + chatgpt_api_key = event.data.chatgpt_api_key; + chatgpt_model = event.data.chatgpt_model; + //console.log(">>>>>>>>>>> chatgpt_api_key: " + chatgpt_api_key); + openai = new OpenAI(chatgpt_api_key, chatgpt_model, true); } else if (event.data.type === 'chatMessage') { conversationHistory.push({ role: 'user', content: event.data.message }); diff --git a/mzta-background.js b/mzta-background.js index c090dd2b..569901db 100644 --- a/mzta-background.js +++ b/mzta-background.js @@ -148,11 +148,11 @@ async function openChatGPT(promptText, action, curr_tabId, prompt_name = '', do_ } // check if the API is present, otherwise open the web interface - if (prefs.api_key_chatgpt == '') { + if (prefs.chatgpt_api_key == '') { showNotification(browser.i18n.getMessage('error'),browser.i18n.getMessage('chatgpt_empty_apikey')); prefs.connection_type = 'chatgpt_web'; } - if (prefs.model_chatgpt == '') { + if (prefs.chatgpt_model == '') { showNotification(browser.i18n.getMessage('error'),browser.i18n.getMessage('chatgpt_empty_model')); prefs.connection_type = 'chatgpt_web'; } diff --git a/options/mzta-options-default.js b/options/mzta-options-default.js index a3443ce1..000546ff 100644 --- a/options/mzta-options-default.js +++ b/options/mzta-options-default.js @@ -23,6 +23,6 @@ export const prefs_default = { chatgpt_keep_formatting: false, default_chatgpt_lang: '', connection_type: 'chatgpt_web', //Other values: 'chatgpt_api' - api_key_chatgpt: '', - model_chatgpt: '', + chatgpt_api_key: '', + chatgpt_model: '', } \ No newline at end of file diff --git a/options/mzta-options.html b/options/mzta-options.html index 250543a7..8b8588d8 100644 --- a/options/mzta-options.html +++ b/options/mzta-options.html @@ -103,7 +103,7 @@ @@ -117,7 +117,7 @@ __MSG_ChatGPT_Models_Loading__
diff --git a/options/mzta-options.js b/options/mzta-options.js index 3992eed2..3b2e02d7 100644 --- a/options/mzta-options.js +++ b/options/mzta-options.js @@ -111,9 +111,9 @@ function showConnectionOptions() { } function warnAPIKeyEmpty() { - let apiKeyInput = document.getElementById('api_key_chatgpt'); + let apiKeyInput = document.getElementById('chatgpt_api_key'); let btnFetchModels = document.getElementById('btnUpdateChatGPTModels'); - let modelChatGPT = document.getElementById('model_chatgpt'); + let modelChatGPT = document.getElementById('chatgpt_model'); if(apiKeyInput.value === ''){ apiKeyInput.style.border = '2px solid red'; btnFetchModels.disabled = true; @@ -157,16 +157,16 @@ document.addEventListener('DOMContentLoaded', async () => { let conntype_select = document.getElementById("connection_type"); conntype_select.addEventListener("change", showConnectionOptions); conntype_select.addEventListener("change", warnAPIKeyEmpty); - document.getElementById("api_key_chatgpt").addEventListener("change", warnAPIKeyEmpty); + document.getElementById("chatgpt_api_key").addEventListener("change", warnAPIKeyEmpty); - let prefs = await browser.storage.sync.get({api_key_chatgpt: '', model_chatgpt: ''}); - let openai = new OpenAI(prefs.api_key_chatgpt, true); - let select_model_chatgpt = document.getElementById('model_chatgpt'); + let prefs = await browser.storage.sync.get({chatgpt_api_key: '', chatgpt_model: ''}); + let openai = new OpenAI(prefs.chatgpt_api_key, true); + let select_chatgpt_model = document.getElementById('chatgpt_model'); const option = document.createElement('option'); - option.value = prefs.model_chatgpt; - option.text = prefs.model_chatgpt; - select_model_chatgpt.appendChild(option); + option.value = prefs.chatgpt_model; + option.text = prefs.chatgpt_model; + select_chatgpt_model.appendChild(option); document.getElementById('btnUpdateChatGPTModels').addEventListener('click', () => { document.getElementById('model_fetch_loading').style.display = 'inline'; @@ -179,11 +179,11 @@ document.addEventListener('DOMContentLoaded', async () => { } console.log(">>>>>>>>> ChatGPT models: " + JSON.stringify(data)); data.forEach(model => { - if (!Array.from(select_model_chatgpt.options).some(option => option.value === model.id)) { + if (!Array.from(select_chatgpt_model.options).some(option => option.value === model.id)) { const option = document.createElement('option'); option.value = model.id; option.text = model.id; - select_model_chatgpt.appendChild(option); + select_chatgpt_model.appendChild(option); } }); document.getElementById('model_fetch_loading').style.display = 'none';