From e517c6ef4fc249d19d49403e493aae0ade7c6f5f Mon Sep 17 00:00:00 2001 From: Jesse Date: Thu, 11 Apr 2024 01:48:20 +0200 Subject: [PATCH] - add gpt-4-turbo support --- background.js | 2 +- manifest.json | 2 +- popup/popup.html | 7 ++++--- popup/popup.js | 54 +++++++++++++++++++++++++++--------------------- 4 files changed, 36 insertions(+), 29 deletions(-) diff --git a/background.js b/background.js index 006d0fa..a306077 100644 --- a/background.js +++ b/background.js @@ -4,7 +4,7 @@ let chatHistory; // Listen for when the extension is installed chrome.runtime.onInstalled.addListener(function () { // Set default API model - let defaultModel = "gpt-3.5-turbo-1106"; + let defaultModel = "gpt-4-turbo"; chrome.storage.local.set({ apiModel: defaultModel }); // Set empty chat history diff --git a/manifest.json b/manifest.json index 68f36cc..621f322 100644 --- a/manifest.json +++ b/manifest.json @@ -1,6 +1,6 @@ { "name": "OpenAI ChatGPT Chrome Extension", - "version": "2.1.0", + "version": "2.1.1", "description": "Have a seamless ChatGPT experience or generate stunning images, all without ever having to leave your favorite website.", "default_locale": "en", "icons": { diff --git a/popup/popup.html b/popup/popup.html index 980264f..325ca5b 100644 --- a/popup/popup.html +++ b/popup/popup.html @@ -14,9 +14,10 @@
- GPT-3.5-Turbo (fastest) - GPT-4 (cleverest) - DALL-E 3 (images) + GPT-3.5-Turbo + GPT-4 + GPT-4-Turbo + DALL-E 3
diff --git a/popup/popup.js b/popup/popup.js index 07bfbc1..242ed7c 100644 --- a/popup/popup.js +++ b/popup/popup.js @@ -76,9 +76,9 @@ document.addEventListener('DOMContentLoaded', function () { // Listen for messages from the background script chrome.runtime.onMessage.addListener(function (message, sender, sendResponse) { - if (message.answer) { + if (message.answer || message.imageUrl) { // Display the assistant's response - displayMessage('assistant', message.answer); + displayMessage('assistant', message.answer || message.imageUrl); } else if (message.error) { // Display the error message displayMessage('system', message.error); @@ -163,28 +163,11 @@ document.addEventListener('DOMContentLoaded', function () { } } else { // if it's not an image, it's a text message - // Check if the message contains code blocks - content = content.replace(/```(\w+)([\s\S]*?)```/g, function (match, lang, code) { - // Create a code element - var codeElement = document.createElement('code'); - // remove the first line break from the code - code = code.replace(/^\n/, ''); - // - codeElement.innerText = code; - - // Create a container for the code element - var codeContainer = document.createElement('div'); - codeContainer.appendChild(codeElement); - - // Set the class of the container based on the language (optional) - codeContainer.className = 'code-block'; - - // Return the HTML content with the replaced code - return codeContainer.outerHTML; - }); + // format the message content + content = formatMessageContent(content); - // Append the replaced content to the message container - messageElement.innerText = content; + // add the message content to the message element + messageElement.innerHTML = content; // add a copy button to the message if it's from the assistant if (role === 'assistant') { @@ -234,6 +217,28 @@ document.addEventListener('DOMContentLoaded', function () { messageElement.scrollIntoView(); } + function formatMessageContent(text) { + return text.replace(/```(\w+)([\s\S]*?)```/g, function (match, lang, code) { + // Create a code element + var codeElement = document.createElement('code'); + // remove the first line break from the code + code = code.replace(/^\n/, ''); + + // Add the code to the code element + codeElement.innerText = code; + + // Create a container for the code element + var codeContainer = document.createElement('div'); + codeContainer.appendChild(codeElement); + + // Set the class of the container based on the language (optional) + codeContainer.className = 'code-block'; + + // Return the HTML content with the replaced code + return codeContainer.outerHTML; + }); + } + // Function to display an array of messages function displayMessages(messages) { for (const message of messages) { @@ -316,6 +321,7 @@ document.addEventListener('DOMContentLoaded', function () { }); }); + // Function to set the active model in the dropdown function setActiveModel(model) { // add active class to the button and remove it from the other buttons dropdownButtons.forEach(function (button) { @@ -333,4 +339,4 @@ document.addEventListener('DOMContentLoaded', function () { setActiveModel(result.apiModel); } }); -}); +}); \ No newline at end of file