Spaces:
Paused
Paused
Update knowledge_tool.py
Browse filesFixed behavior when Perplexity key is absent.
python/tools/knowledge_tool.py
CHANGED
|
@@ -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
|
| 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 "")
|
| 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),
|
| 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)
|
|
|
|
| 17 |
with concurrent.futures.ThreadPoolExecutor() as executor:
|
| 18 |
# Schedule the two functions to be run in parallel
|
| 19 |
|
| 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 |
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 "")
|
| 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") 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)
|