From 84a18f873be1106a738f2ace83d39e97c5fcf081 Mon Sep 17 00:00:00 2001 From: mic Date: Sun, 28 Jul 2024 21:56:30 +0200 Subject: [PATCH] added test vars to check the page in a browser --- api_webchat/controller.js | 20 ++++++++++++++++++-- api_webchat/messagesArea.js | 21 +++++++++++++++++++++ api_webchat/model-worker.js | 15 ++++++++------- 3 files changed, 47 insertions(+), 9 deletions(-) diff --git a/api_webchat/controller.js b/api_webchat/controller.js index 5cc0d278..02008691 100644 --- a/api_webchat/controller.js +++ b/api_webchat/controller.js @@ -37,9 +37,25 @@ messageInput.setMessagesArea(messagesArea); // Data received from the user let promptData = null; +// ============================== TESTING +// let browser = { +// i18n: { +// getMessage: async function(key) { +// return key; +// } +// }, +// storage: { +// sync: { +// get: async function(key) { +// return 'apitest'; +// } +// } +// } +// } +// ============================== TESTING - END + const params = new URLSearchParams(window.location.search); -//let prefs_api_key = await browser.storage.sync.get({api_key_chatgpt: ''}); -let prefs_api_key = '' // only for testing +let prefs_api_key = await browser.storage.sync.get({api_key_chatgpt: ''}); // 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_key.api_key_chatgpt }); diff --git a/api_webchat/messagesArea.js b/api_webchat/messagesArea.js index 47029a60..3071a9ba 100644 --- a/api_webchat/messagesArea.js +++ b/api_webchat/messagesArea.js @@ -200,6 +200,27 @@ class MessagesArea extends HTMLElement { } addActionButtons(promptData = null) { + // ============================== TESTING + // promptData = { + // action: "1", + // tabId: 1, + // mailMessageId: 1 + // } + // let browser = { + // i18n: { + // getMessage: async function(key) { + // return key; + // } + // }, + // storage: { + // sync: { + // get: async function(key) { + // return 'apitest'; + // } + // } + // } + // } + // ============================== TESTING - END if(promptData == null) { return; } const actionButtons = document.createElement('div'); actionButtons.classList.add('action-buttons'); diff --git a/api_webchat/model-worker.js b/api_webchat/model-worker.js index b84cccd1..6b716096 100644 --- a/api_webchat/model-worker.js +++ b/api_webchat/model-worker.js @@ -48,21 +48,22 @@ let assistantResponseAccumulator = ''; self.onmessage = async function(event) { if (event.data.type === 'init') { api_key_chatgpt = event.data.api_key_chatgpt; + //console.log(">>>>>>>>>>> api_key_chatgpt: " + api_key_chatgpt); openai = new OpenAI(api_key_chatgpt, true); } else if (event.data.type === 'chatMessage') { conversationHistory.push({ role: 'user', content: event.data.message }); // ============================== TESTING - // Simulate sending the message to an HTTP endpoint - await mockDelay(1000); // Wait for 1 second + // // Simulate sending the message to an HTTP endpoint + // await mockDelay(1000); // Wait for 1 second - // Notify that the chat message was sent - postMessage({ type: 'messageSent' }); + // // Notify that the chat message was sent + // postMessage({ type: 'messageSent' }); - // Start processing tokens - await processMockTokens(); - return; + // // Start processing tokens + // await processMockTokens(); + // return; // ============================== TESTING - END