Skip to content

Commit

Permalink
v34.96; add Google searches into ChatGPT responses
Browse files Browse the repository at this point in the history
  • Loading branch information
eliranwong committed Sep 11, 2023
1 parent 2223468 commit 8a89040
Show file tree
Hide file tree
Showing 8 changed files with 78 additions and 25 deletions.
2 changes: 1 addition & 1 deletion UniqueBibleAppVersion.txt
Original file line number Diff line number Diff line change
@@ -1 +1 @@
34.95
34.96
3 changes: 3 additions & 0 deletions latest_changes.txt
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
Changes in 34.96:
* Add a plugin to integrate Google searches into ChatGPT responses.

Changes in 34.95:
Improved plugin "Bible Chat"
* added option to generate chat or not after a function is called
Expand Down
14 changes: 7 additions & 7 deletions patches.txt
Original file line number Diff line number Diff line change
Expand Up @@ -1367,7 +1367,6 @@
(34.89, "file", "marvelData/AGBTS_data.sqlite")
(34.91, "file", "db/ToolsSqlite.py")
(34.91, "file", "util/RemoteApiHandler.py")
(34.94, "file", "util/checkup.py")
(34.95, "file", "lang/language_de.py")
(34.95, "file", "lang/language_el.py")
(34.95, "file", "lang/language_en_GB.py")
Expand All @@ -1385,9 +1384,10 @@
(34.95, "file", "lang/language_zh_HANT.py")
(34.95, "file", "gui/MainWindow.py")
(34.95, "file", "gui/Worker.py")
(34.95, "file", "plugins/menu/Bible Chat.py")
(34.95, "file", "util/ConfigUtil.py")
(34.95, "file", "util/LocalCliHandler.py")
(34.95, "file", "latest_changes.txt")
(34.95, "file", "UniqueBibleAppVersion.txt")
(34.95, "file", "patches.txt")
(34.96, "file", "plugins/menu/Bible Chat.py")
(34.96, "file", "util/checkup.py")
(34.96, "file", "util/ConfigUtil.py")
(34.96, "file", "util/LocalCliHandler.py")
(34.96, "file", "latest_changes.txt")
(34.96, "file", "UniqueBibleAppVersion.txt")
(34.96, "file", "patches.txt")
35 changes: 35 additions & 0 deletions plugins/chatGPT/integrate google searches.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
import config, json, googlesearch

# Use google https://pypi.org/project/googlesearch-python/ to search internet for information, about which ChatGPT doesn't know.

def get_internet_info(function_args):
# retrieve argument values from a dictionary
#print(function_args)
keywords = function_args.get("keywords") # required

news = {}
for index, item in enumerate(googlesearch.search(keywords, advanced=True, num_results=config.chatGPTApiMaximumInternetSearchResults)):
news[f"result {index}"] = {
"title": item.title,
"url": item.url,
"description": item.description,
}
return json.dumps(news)

functionSignature = {
"name": "get_internet_info",
"description": "Search internet for keywords when ChatGPT does not have information",
"parameters": {
"type": "object",
"properties": {
"keywords": {
"type": "string",
"description": "keywords for searches, e.g. ChatGPT",
},
},
"required": ["keywords"],
},
}

config.chatGPTApiFunctionSignatures.append(functionSignature)
config.chatGPTApiAvailableFunctions["get_internet_info"] = get_internet_info
31 changes: 19 additions & 12 deletions plugins/menu/Bible Chat.py
Original file line number Diff line number Diff line change
Expand Up @@ -83,12 +83,12 @@ def __init__(self, parent=None):
self.functionCallingBox.setCurrentIndex(initialIndex)
self.maxTokenEdit = QLineEdit(str(config.chatGPTApiMaxTokens))
self.maxTokenEdit.setToolTip("The maximum number of tokens to generate in the completion.\nThe token count of your prompt plus max_tokens cannot exceed the model's context length. Most models have a context length of 2048 tokens (except for the newest models, which support 4096).")
self.maxInternetSearchResults = QLineEdit(str(config.chatGPTApiMaximumDuckDuckGoSearchResults))
self.maxInternetSearchResults = QLineEdit(str(config.chatGPTApiMaximumInternetSearchResults))
self.maxInternetSearchResults.setToolTip("The maximum number of internet search response to be included.")
self.includeInternetSearches = QCheckBox(config.thisTranslation["include"])
self.includeInternetSearches.setToolTip("Include latest internet search results")
self.includeInternetSearches.setCheckState(Qt.Checked if config.chatGPTApiIncludeDuckDuckGoSearchResults else Qt.Unchecked)
self.includeDuckDuckGoSearchResults = config.chatGPTApiIncludeDuckDuckGoSearchResults
#self.includeInternetSearches = QCheckBox(config.thisTranslation["include"])
#self.includeInternetSearches.setToolTip("Include latest internet search results")
#self.includeInternetSearches.setCheckState(Qt.Checked if config.chatGPTApiIncludeDuckDuckGoSearchResults else Qt.Unchecked)
#self.includeDuckDuckGoSearchResults = config.chatGPTApiIncludeDuckDuckGoSearchResults
self.autoScrollingCheckBox = QCheckBox(config.thisTranslation["enable"])
self.autoScrollingCheckBox.setToolTip("Auto-scroll display as responses are received")
self.autoScrollingCheckBox.setCheckState(Qt.Checked if config.chatGPTApiAutoScrolling else Qt.Unchecked)
Expand Down Expand Up @@ -156,13 +156,13 @@ def __init__(self, parent=None):
layout.addRow(f"{predefinedContext} [{optional}]:", self.predefinedContextBox)
layout.addRow(f"{context} [{optional}]:", self.contextEdit)
layout.addRow(f"{applyContext} [{optional}]:", self.applyContextIn)
layout.addRow(f"{latestOnlineSearchResults} [{optional}]:", self.includeInternetSearches)
#layout.addRow(f"{latestOnlineSearchResults} [{optional}]:", self.includeInternetSearches)
layout.addRow(f"{maximumOnlineSearchResults} [{optional}]:", self.maxInternetSearchResults)
layout.addRow(f"{autoScroll} [{optional}]:", self.autoScrollingCheckBox)
layout.addRow(f"{runPythonScriptGlobally} [{optional}]:", self.runPythonScriptGloballyCheckBox)
#layout.addRow(f"{language} [{optional}]:", self.languageBox)
layout.addWidget(buttonBox)
self.includeInternetSearches.stateChanged.connect(self.toggleIncludeDuckDuckGoSearchResults)
#self.includeInternetSearches.stateChanged.connect(self.toggleIncludeDuckDuckGoSearchResults)
self.autoScrollingCheckBox.stateChanged.connect(self.toggleAutoScrollingCheckBox)
self.chatAfterFunctionCalledCheckBox.stateChanged.connect(self.toggleChatAfterFunctionCalled)
self.runPythonScriptGloballyCheckBox.stateChanged.connect(self.toggleRunPythonScriptGlobally)
Expand Down Expand Up @@ -195,11 +195,12 @@ def functionCalling(self):
def max_token(self):
return self.maxTokenEdit.text().strip()

"""
def include_internet_searches(self):
return self.includeDuckDuckGoSearchResults
def toggleIncludeDuckDuckGoSearchResults(self, state):
self.includeDuckDuckGoSearchResults = True if state else False
self.includeDuckDuckGoSearchResults = True if state else False"""

def enable_auto_scrolling(self):
return self.chatGPTApiAutoScrolling
Expand Down Expand Up @@ -636,12 +637,14 @@ def showApiDialog(self):
except:
pass
try:
config.chatGPTApiMaximumDuckDuckGoSearchResults = int(dialog.max_internet_search_results())
if config.chatGPTApiMaximumDuckDuckGoSearchResults <= 0:
config.chatGPTApiMaximumDuckDuckGoSearchResults = 1
config.chatGPTApiMaximumInternetSearchResults = int(dialog.max_internet_search_results())
if config.chatGPTApiMaximumInternetSearchResults <= 0:
config.chatGPTApiMaximumInternetSearchResults = 1
elif config.chatGPTApiMaximumInternetSearchResults > 100:
config.chatGPTApiMaximumInternetSearchResults = 100
except:
pass
config.chatGPTApiIncludeDuckDuckGoSearchResults = dialog.include_internet_searches()
#config.chatGPTApiIncludeDuckDuckGoSearchResults = dialog.include_internet_searches()
config.chatGPTApiAutoScrolling = dialog.enable_auto_scrolling()
config.runPythonScriptGlobally = dialog.enable_runPythonScriptGlobally()
config.chatAfterFunctionCalled = dialog.enable_chatAfterFunctionCalled()
Expand Down Expand Up @@ -964,6 +967,8 @@ 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 = ""
Expand All @@ -975,6 +980,8 @@ def getMessages(self, userInput):
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

def print(self, text):
Expand Down
7 changes: 2 additions & 5 deletions util/ConfigUtil.py
Original file line number Diff line number Diff line change
Expand Up @@ -559,11 +559,8 @@ def getCurrentVenvDir():
setConfig("chatGPTApiContextInAllInputs", """
# ChatGP API - predefined context in all inputs.""",
False)
setConfig("chatGPTApiIncludeDuckDuckGoSearchResults", """
# ChatGPT API - include DuckDuckGo search results.""",
False)
setConfig("chatGPTApiMaximumDuckDuckGoSearchResults", """
# ChatGPT API - maximum number of DuckDuckGo search results to be included.""",
setConfig("chatGPTApiMaximumInternetSearchResults", """
# ChatGPT API - maximum number of internet search results to be integrated.""",
5)
setConfig("chatGPTApiAutoScrolling", """
# Auto-scroll display as response is received""",
Expand Down
2 changes: 2 additions & 0 deletions util/LocalCliHandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -2259,6 +2259,7 @@ def fineTuneUserInput(userInput, conversationStarted):
#messages.append({"role": "assistant", "content": context})
userInput = f"{context}\n{userInput}"
# user input
"""
if config.chatGPTApiIncludeDuckDuckGoSearchResults:
results = ddg(userInput, time='y', max_results=config.chatGPTApiMaximumDuckDuckGoSearchResults)
news = ""
Expand All @@ -2268,6 +2269,7 @@ def fineTuneUserInput(userInput, conversationStarted):
body = r["body"]
news += f"{title}. {body} "
userInput = f"{userInput}. Include the following information that you don't know in your response to my input: {news}"
"""
return userInput
# required
openai.api_key = os.environ["OPENAI_API_KEY"] = config.openaiApiKey
Expand Down
9 changes: 9 additions & 0 deletions util/checkup.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,13 @@ def isTabulateInstalled():
except:
return False

def isGoogleSearchPythonInstalled():
try:
import googlesearch
return True
except:
return False

def isDuckduckgoSearchInstalled():
try:
from duckduckgo_search import ddg
Expand Down Expand Up @@ -748,6 +755,7 @@ def runTerminalMode():
("SpeechRecognition", "Library for performing speech recognition", isSpeechRecognitionInstalled),
("pocketsphinx", "Python bindings for PocketSphinx", isPocketSphinxInstalled),
("duckduckgo-search", "DuckDuckGo.com search", isDuckduckgoSearchInstalled),
("googlesearch-python", "A Python library for scraping the Google search engine", isGoogleSearchPythonInstalled),
("guidance", "A guidance language for controlling large language models", isGuidanceInstalled),
("tiktoken", "tokeniser for use with OpenAI's models.", isTiktokenInstalled),
] if config.noQt else [
Expand Down Expand Up @@ -800,6 +808,7 @@ def runTerminalMode():
("SpeechRecognition", "Library for performing speech recognition", isSpeechRecognitionInstalled),
("pocketsphinx", "Python bindings for PocketSphinx", isPocketSphinxInstalled),
("duckduckgo-search", "DuckDuckGo.com search", isDuckduckgoSearchInstalled),
("googlesearch-python", "A Python library for scraping the Google search engine", isGoogleSearchPythonInstalled),
("guidance", "A guidance language for controlling large language models", isGuidanceInstalled),
("tiktoken", "tokeniser for use with OpenAI's models.", isTiktokenInstalled),
]
Expand Down

0 comments on commit 8a89040

Please sign in to comment.