removed chatgpt web fallback, added error messages. fixes #111

This commit is contained in:
mic 2024-08-20 15:00:55 +02:00
parent 06b5e6e939
commit 19342cbced
2 changed files with 25 additions and 22 deletions

View file

@ -86,7 +86,8 @@ worker.onmessage = function(event) {
// handling commands from the backgound page // handling commands from the backgound page
browser.runtime.onMessage.addListener((message, sender, sendResponse) => { browser.runtime.onMessage.addListener((message, sender, sendResponse) => {
//console.log(">>>>>>>>>>>>> controller.js onMessage: " + JSON.stringify(message)); //console.log(">>>>>>>>>>>>> controller.js onMessage: " + JSON.stringify(message));
if (message.command === "chatgpt_send") { switch (message.command) {
case "chatgpt_send":
//send the received prompt to the chatgpt api //send the received prompt to the chatgpt api
if(message.do_custom_text=="1") { if(message.do_custom_text=="1") {
let userInput = prompt(browser.i18n.getMessage("chatgpt_win_custom_text")); let userInput = prompt(browser.i18n.getMessage("chatgpt_win_custom_text"));
@ -97,5 +98,9 @@ browser.runtime.onMessage.addListener((message, sender, sendResponse) => {
promptData = message; promptData = message;
messageInput._setMessageInputValue(message.prompt); messageInput._setMessageInputValue(message.prompt);
messageInput._handleNewChatMessage(); messageInput._handleNewChatMessage();
break;
case "api_error":
messagesArea.appendBotMessage(message.error,'error');
break;
} }
}); });

View file

@ -152,18 +152,6 @@ async function openChatGPT(promptText, action, curr_tabId, prompt_name = '', do_
return; return;
} }
if(prefs.connection_type === 'chatgpt_api'){
// check if the API is present, otherwise open the web interface
if (prefs.chatgpt_api_key == '') {
showNotification(browser.i18n.getMessage('error'),browser.i18n.getMessage('chatgpt_empty_apikey'));
prefs.connection_type = 'chatgpt_web';
}
if (prefs.chatgpt_model == '') {
showNotification(browser.i18n.getMessage('error'),browser.i18n.getMessage('chatgpt_empty_model'));
prefs.connection_type = 'chatgpt_web';
}
}
switch(prefs.connection_type){ switch(prefs.connection_type){
case 'chatgpt_web': case 'chatgpt_web':
// We are using the ChatGPT web interface // We are using the ChatGPT web interface
@ -253,6 +241,16 @@ async function openChatGPT(promptText, action, curr_tabId, prompt_name = '', do_
let mailMessageId = -1; let mailMessageId = -1;
if(mailMessage) mailMessageId = mailMessage.id; if(mailMessage) mailMessageId = mailMessage.id;
// check if the config is present, or give a message error
if (prefs.chatgpt_api_key == '') {
browser.tabs.sendMessage(createdTab2.id, { command: "api_error", error: browser.i18n.getMessage('chatgpt_empty_apikey')});
return;
}
if (prefs.chatgpt_model == '') {
browser.tabs.sendMessage(createdTab2.id, { command: "api_error", error: browser.i18n.getMessage('chatgpt_empty_model')});
return;
}
browser.tabs.sendMessage(createdTab2.id, { command: "chatgpt_send", prompt: promptText, action: action, tabId: curr_tabId, mailMessageId: mailMessageId, do_custom_text: do_custom_text}); browser.tabs.sendMessage(createdTab2.id, { command: "chatgpt_send", prompt: promptText, action: action, tabId: curr_tabId, mailMessageId: mailMessageId, do_custom_text: do_custom_text});
break; // chatgpt_api break; // chatgpt_api
} }