From e05d75a730889079e5f574f32b5572ece91561fe Mon Sep 17 00:00:00 2001 From: John Bollenbacher Date: Mon, 29 Jul 2024 02:14:28 -0400 Subject: [PATCH] Update knowledge_tool.py Fixed behavior when Perplexity key is absent. --- python/tools/knowledge_tool.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/python/tools/knowledge_tool.py b/python/tools/knowledge_tool.py index cc858e4f1..d274d7802 100644 --- a/python/tools/knowledge_tool.py +++ b/python/tools/knowledge_tool.py @@ -17,7 +17,7 @@ class Knowledge(Tool): with concurrent.futures.ThreadPoolExecutor() as executor: # Schedule the two functions to be run in parallel - # perplexity search, if API provided + # perplexity search, if API key provided if os.getenv("API_KEY_PERPLEXITY"): perplexity = executor.submit(perplexity_search.perplexity_search, question) else: perplexity = None @@ -29,14 +29,14 @@ class Knowledge(Tool): future_memory = executor.submit(memory_tool.search, self.agent, question) # Wait for both functions to complete - perplexity_result = (perplexity.result() if perplexity else "") or "" + perplexity_result = (perplexity.result() if perplexity else "") duckduckgo_result = duckduckgo.result() memory_result = future_memory.result() msg = files.read_file("prompts/tool.knowledge.response.md", - online_sources = perplexity_result + "\n\n" + str(duckduckgo_result), + online_sources = ((perplexity_result + "\n\n") if perplexity else "") + str(duckduckgo_result), memory = memory_result ) if self.agent.handle_intervention(msg): pass # wait for intervention and handle it, if paused - return Response(message=msg, break_loop=False) \ No newline at end of file + return Response(message=msg, break_loop=False)