diff --git a/UniqueBibleAppVersion.txt b/UniqueBibleAppVersion.txt index da2b9df6b7..9f9af530de 100755 --- a/UniqueBibleAppVersion.txt +++ b/UniqueBibleAppVersion.txt @@ -1 +1 @@ -34.97 +34.98 diff --git a/gui/Worker.py b/gui/Worker.py index 3c87ada25e..6fa3629501 100644 --- a/gui/Worker.py +++ b/gui/Worker.py @@ -87,14 +87,12 @@ def __init__(self, parent): super().__init__() self.parent = parent self.threadpool = QThreadPool() - self.forceLoadingInternetSearches = True def getResponse(self, messages, progress_callback): responses = "" - if config.chatGPTApiLoadingInternetSearches == "always" and self.forceLoadingInternetSearches: + if config.chatGPTApiLoadingInternetSearches == "always": #print("loading internet searches ...") try: - self.forceLoadingInternetSearches = False completion = openai.ChatCompletion.create( model=config.chatGPTApiModel, messages=messages, @@ -117,7 +115,6 @@ def getResponse(self, messages, progress_callback): "content": function_response, } ) - return self.getResponse(messages, progress_callback) except: print("Unable to load internet resources.") try: diff --git a/latest_changes.txt b/latest_changes.txt index a9e2497c2d..5b32698a7d 100755 --- a/latest_changes.txt +++ b/latest_changes.txt @@ -1,3 +1,7 @@ +Changes in 34.98: +Improved terminal mode +* added options to integrate internet searches into ChatGPT responses: "always", "auto", "none" + Changes in 34.97: Improved plugin "Bible Chat" * added options to integrate internet searches: "always", "auto", "none" diff --git a/patches.txt b/patches.txt index 61af2cca7d..9fdd531096 100755 --- a/patches.txt +++ b/patches.txt @@ -1384,11 +1384,11 @@ (34.95, "file", "lang/language_zh_HANT.py") (34.96, "file", "util/checkup.py") (34.97, "file", "gui/MainWindow.py") -(34.97, "file", "gui/Worker.py") -(34.97, "file", "plugins/menu/Bible Chat.py") (34.97, "file", "util/ConfigUtil.py") -(34.97, "file", "util/LocalCliHandler.py") -(34.97, "file", "plugins/chatGPT/integrate google searches.py") -(34.97, "file", "latest_changes.txt") -(34.97, "file", "UniqueBibleAppVersion.txt") -(34.97, "file", "patches.txt") +(34.98, "file", "gui/Worker.py") +(34.98, "file", "plugins/chatGPT/integrate google searches.py") +(34.98, "file", "plugins/menu/Bible Chat.py") +(34.98, "file", "util/LocalCliHandler.py") +(34.98, "file", "latest_changes.txt") +(34.98, "file", "UniqueBibleAppVersion.txt") +(34.98, "file", "patches.txt") diff --git a/plugins/chatGPT/integrate google searches.py b/plugins/chatGPT/integrate google searches.py index 096d77c2d5..74aba40734 100644 --- a/plugins/chatGPT/integrate google searches.py +++ b/plugins/chatGPT/integrate google searches.py @@ -7,9 +7,11 @@ def integrate_google_searches(function_args): #print(function_args) keywords = function_args.get("keywords") # required + print("loading internet searches ...") + info = {} for index, item in enumerate(googlesearch.search(keywords, advanced=True, num_results=config.chatGPTApiMaximumInternetSearchResults)): - info[f"result {index}"] = { + info[f"information {index}"] = { "title": item.title, "url": item.url, "description": item.description, diff --git a/plugins/menu/Bible Chat.py b/plugins/menu/Bible Chat.py index f01c881092..dc13857b1f 100644 --- a/plugins/menu/Bible Chat.py +++ b/plugins/menu/Bible Chat.py @@ -2,7 +2,6 @@ import subprocess, traceback, sys import urllib.parse from io import StringIO -from duckduckgo_search import ddg from functools import partial from gtts import gTTS if "Pocketsphinx" in config.enabled: @@ -665,6 +664,14 @@ def showApiDialog(self): config.chatGPTApiModel = dialog.apiModel() config.chatGPTApiFunctionCall = dialog.functionCalling() config.chatGPTApiLoadingInternetSearches = dialog.loadingInternetSearches() + internetSeraches = "integrate google searches" + if config.chatGPTApiLoadingInternetSearches == "auto" and internetSeraches in config.chatGPTPluginExcludeList: + config.chatGPTPluginExcludeList.remove(internetSeraches) + self.parent.reloadMenubar() + elif config.chatGPTApiLoadingInternetSearches == "none" and not internetSeraches in config.chatGPTPluginExcludeList: + config.chatGPTPluginExcludeList.append(internetSeraches) + self.parent.reloadMenubar() + config.mainWindow.runBibleChatPlugins() config.chatGPTApiPredefinedContext = dialog.predefinedContext() config.chatGPTApiContextInAllInputs = dialog.contextInAllInputs() config.chatGPTApiContext = dialog.context() @@ -984,20 +991,6 @@ def getMessages(self, userInput): #messages.append({"role": "assistant", "content": context}) userInput = f"{context}\n{userInput}" # user input - """ - # old way to integrate internet searches; now replaced by plugin 'integrate google searches' - if config.chatGPTApiIncludeDuckDuckGoSearchResults: - results = ddg(userInput, time='y', max_results=config.chatGPTApiMaximumDuckDuckGoSearchResults) - news = "" - for r in results: - if "title" in r and "body" in r: - title = r["title"] - body = r["body"] - news += f"{title}. {body} " - messages.append({"role": "user", "content": f"{userInput}. Include the following information that you don't know in your response to my input: {news}"}) - else: - messages.append({"role": "user", "content": userInput}) - """ messages.append({"role": "user", "content": userInput}) return messages @@ -1124,11 +1117,11 @@ def __init__(self, parent): super().__init__(parent) self.initUI() - def initUI(self): - # Set a central widget - self.chatGPT = ChatGPTAPI(self) - self.setCentralWidget(self.chatGPT) + def reloadMenubar(self): + self.menuBar().clear() + self.createMenubar() + def createMenubar(self): # Create a menu bar menubar = self.menuBar() @@ -1273,6 +1266,14 @@ def initUI(self): new_action.triggered.connect(lambda: webbrowser.open("https://www.paypal.com/paypalme/MarvelBible")) about_menu.addAction(new_action) + def initUI(self): + # Set a central widget + self.chatGPT = ChatGPTAPI(self) + self.setCentralWidget(self.chatGPT) + + # create menu bar + self.createMenubar() + # set initial window size #self.setWindowTitle("Bible Chat") self.resize(QGuiApplication.primaryScreen().availableSize() * 3 / 4) @@ -1284,6 +1285,12 @@ def updateExcludePluginList(self, plugin): config.chatGPTPluginExcludeList.remove(plugin) else: config.chatGPTPluginExcludeList.append(plugin) + internetSeraches = "integrate google searches" + if internetSeraches in config.chatGPTPluginExcludeList and config.chatGPTApiLoadingInternetSearches == "auto": + config.chatGPTApiLoadingInternetSearches = "none" + elif not internetSeraches in config.chatGPTPluginExcludeList and config.chatGPTApiLoadingInternetSearches == "none": + config.chatGPTApiLoadingInternetSearches = "auto" + config.chatGPTApiFunctionCall = "auto" # reload plugins config.mainWindow.runBibleChatPlugins() diff --git a/util/LocalCliHandler.py b/util/LocalCliHandler.py index ace1c27b0c..2c4873c912 100644 --- a/util/LocalCliHandler.py +++ b/util/LocalCliHandler.py @@ -2279,10 +2279,16 @@ def fineTuneUserInput(userInput, conversationStarted): messages = resetMessages() if openai.api_key: pluginFolder = os.path.join(os.getcwd(), "plugins", "chatGPT") + # always run 'integrate google searches' + internetSeraches = "integrate google searches" + script = os.path.join(pluginFolder, "{0}.py".format(internetSeraches)) + self.execPythonFile(script) for plugin in FileUtil.fileNamesWithoutExtension(pluginFolder, "py"): if not plugin in config.chatGPTPluginExcludeList: script = os.path.join(pluginFolder, "{0}.py".format(plugin)) self.execPythonFile(script) + if internetSeraches in config.chatGPTPluginExcludeList: + del config.chatGPTApiFunctionSignatures[0] try: started = False def startChat(): @@ -2330,7 +2336,8 @@ def startChat(): "change chat context", "apply context in first input ONLY", "apply context in ALL inputs", - "include latest online search result", + "integrate latest online search result", + "integrate latest online search result when needed", "exclude latest online search result", "share content" if config.terminalEnableTermuxAPI else "save content", ) @@ -2372,9 +2379,14 @@ def startChat(): self.print("Latest online search results always enabled!") elif feature == ".autolatestSearches": config.chatGPTApiLoadingInternetSearches = "auto" + config.chatGPTApiFunctionCall = "auto" + if "integrate google searches" in config.chatGPTPluginExcludeList: + config.chatGPTPluginExcludeList.remove("integrate google searches") self.print("Latest online search results enabled, if necessary!") elif feature == ".noLatestSearches": config.chatGPTApiLoadingInternetSearches = "none" + if not "integrate google searches" in config.chatGPTPluginExcludeList: + config.chatGPTPluginExcludeList.append("integrate google searches") self.print("Latest online search results disabled!") elif feature == ".contextInFirstInputOnly": config.chatGPTApiContextInAllInputs = False @@ -2432,6 +2444,35 @@ def startChat(): # get responses fineTunedUserInput = fineTuneUserInput(userInput, started) messages.append({"role": "user", "content": fineTunedUserInput}) + + # force loading internet searches + if config.chatGPTApiLoadingInternetSearches == "always": + try: + completion = openai.ChatCompletion.create( + model=config.chatGPTApiModel, + messages=messages, + max_tokens=config.chatGPTApiMaxTokens, + temperature=config.chatGPTApiTemperature, + n=1, + functions=config.integrate_google_searches_signature, + function_call={"name": "integrate_google_searches"}, + ) + response_message = completion["choices"][0]["message"] + if response_message.get("function_call"): + function_args = json.loads(response_message["function_call"]["arguments"]) + fuction_to_call = config.chatGPTApiAvailableFunctions.get("integrate_google_searches") + function_response = fuction_to_call(function_args) + messages.append(response_message) # extend conversation with assistant's reply + messages.append( + { + "role": "function", + "name": "integrate_google_searches", + "content": function_response, + } + ) + except: + print("Unable to load internet resources.") + if config.chatGPTApiNoOfChoices == 1 and (config.chatGPTApiFunctionCall == "none" or not config.chatGPTApiFunctionSignatures): completion = openai.ChatCompletion.create( model=config.chatGPTApiModel,