Skip to content

Commit

Permalink
v34.98; improved terminal mode
Browse files Browse the repository at this point in the history
  • Loading branch information
eliranwong committed Sep 13, 2023
1 parent 3aa2edd commit 14243e3
Show file tree
Hide file tree
Showing 7 changed files with 84 additions and 33 deletions.
2 changes: 1 addition & 1 deletion UniqueBibleAppVersion.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
34.97
34.98
5 changes: 1 addition & 4 deletions gui/Worker.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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:
Expand Down
4 changes: 4 additions & 0 deletions latest_changes.txt
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
14 changes: 7 additions & 7 deletions patches.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
4 changes: 3 additions & 1 deletion plugins/chatGPT/integrate google searches.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
45 changes: 26 additions & 19 deletions plugins/menu/Bible Chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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()
Expand Down Expand Up @@ -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

Expand Down Expand Up @@ -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()

Expand Down Expand Up @@ -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)
Expand All @@ -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()

Expand Down
43 changes: 42 additions & 1 deletion util/LocalCliHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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",
)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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,
Expand Down

0 comments on commit 14243e3

Please sign in to comment.