removed chatgpt web fallback, added error messages. fixes #111
This commit is contained in:
parent
06b5e6e939
commit
19342cbced
2 changed files with 25 additions and 22 deletions
|
|
@ -86,16 +86,21 @@ worker.onmessage = function(event) {
|
|||
// handling commands from the backgound page
|
||||
browser.runtime.onMessage.addListener((message, sender, sendResponse) => {
|
||||
//console.log(">>>>>>>>>>>>> controller.js onMessage: " + JSON.stringify(message));
|
||||
if (message.command === "chatgpt_send") {
|
||||
//send the received prompt to the chatgpt api
|
||||
if(message.do_custom_text=="1") {
|
||||
let userInput = prompt(browser.i18n.getMessage("chatgpt_win_custom_text"));
|
||||
if(userInput !== null) {
|
||||
message.prompt += " " + userInput;
|
||||
switch (message.command) {
|
||||
case "chatgpt_send":
|
||||
//send the received prompt to the chatgpt api
|
||||
if(message.do_custom_text=="1") {
|
||||
let userInput = prompt(browser.i18n.getMessage("chatgpt_win_custom_text"));
|
||||
if(userInput !== null) {
|
||||
message.prompt += " " + userInput;
|
||||
}
|
||||
}
|
||||
}
|
||||
promptData = message;
|
||||
messageInput._setMessageInputValue(message.prompt);
|
||||
messageInput._handleNewChatMessage();
|
||||
promptData = message;
|
||||
messageInput._setMessageInputValue(message.prompt);
|
||||
messageInput._handleNewChatMessage();
|
||||
break;
|
||||
case "api_error":
|
||||
messagesArea.appendBotMessage(message.error,'error');
|
||||
break;
|
||||
}
|
||||
});
|
||||
|
|
@ -152,18 +152,6 @@ async function openChatGPT(promptText, action, curr_tabId, prompt_name = '', do_
|
|||
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){
|
||||
case 'chatgpt_web':
|
||||
// We are using the ChatGPT web interface
|
||||
|
|
@ -253,6 +241,16 @@ async function openChatGPT(promptText, action, curr_tabId, prompt_name = '', do_
|
|||
let mailMessageId = -1;
|
||||
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});
|
||||
break; // chatgpt_api
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue