Update knowledge_tool.py

Fixed behavior when Perplexity key is absent.

John Bollenbacher committed Jul 29, 2024 at 02:14 UTC e05d75a730889079e5f574f32b5572ece91561fe
1 file changed +4 -4
python/tools/knowledge_tool.py
+4 -4
@@ -17,7 +17,7 @@ class Knowledge(Tool):
17 with concurrent.futures.ThreadPoolExecutor() as executor:
18 # Schedule the two functions to be run in parallel
19
20 - # perplexity search, if API provided
20 + # perplexity search, if API key provided
21 if os.getenv("API_KEY_PERPLEXITY"):
22 perplexity = executor.submit(perplexity_search.perplexity_search, question)
23 else: perplexity = None
@@ -29,14 +29,14 @@ class Knowledge(Tool):
29 future_memory = executor.submit(memory_tool.search, self.agent, question)
30
31 # Wait for both functions to complete
32 - perplexity_result = (perplexity.result() if perplexity else "") or ""
32 + perplexity_result = (perplexity.result() if perplexity else "")
33 duckduckgo_result = duckduckgo.result()
34 memory_result = future_memory.result()
35
36 msg = files.read_file("prompts/tool.knowledge.response.md",
37 - online_sources = perplexity_result + "\n\n" + str(duckduckgo_result),
37 + online_sources = ((perplexity_result + "\n\n") if perplexity else "") + str(duckduckgo_result),
38 memory = memory_result )
39
40 if self.agent.handle_intervention(msg): pass # wait for intervention and handle it, if paused
41
42 - return Response(message=msg, break_loop=False)
\ No newline at end of file
42 + return Response(message=msg, break_loop=False)