Commit
·
11beb43
1
Parent(s):
3cf70e0
fix: try with wikipedia
Browse files
app.py
CHANGED
@@ -86,32 +86,32 @@ class BasicAgent:
|
|
86 |
description="Searches the web and refines the result into a high-quality answer. Use when other tools don't seem suitable"
|
87 |
)
|
88 |
|
89 |
-
|
90 |
-
|
91 |
-
|
92 |
-
|
93 |
|
94 |
-
|
95 |
-
|
96 |
|
97 |
-
|
98 |
-
|
99 |
-
|
100 |
|
101 |
-
|
102 |
-
|
103 |
|
104 |
-
|
105 |
-
|
106 |
|
107 |
|
108 |
-
|
109 |
-
|
110 |
-
|
111 |
-
|
112 |
-
|
113 |
|
114 |
-
agent = AgentWorkflow.from_tools_or_functions([duckduckgo_search_tool, youtube_transcript_answer_tool], llm=self.llm)
|
115 |
async def run_agent():
|
116 |
return await agent.run(question)
|
117 |
|
|
|
86 |
description="Searches the web and refines the result into a high-quality answer. Use when other tools don't seem suitable"
|
87 |
)
|
88 |
|
89 |
+
def wikipedia_search(query: str) -> str:
|
90 |
+
try:
|
91 |
+
text = WikipediaToolSpec().search_data(query)
|
92 |
+
documents = [Document(text=text)]
|
93 |
|
94 |
+
splitter = SentenceSplitter(chunk_size=256)
|
95 |
+
nodes = splitter.get_nodes_from_documents(documents)
|
96 |
|
97 |
+
retriever = BM25Retriever(nodes=nodes, similarity_top_k=1)
|
98 |
+
synthesizer = get_response_synthesizer(response_mode="refine", llm=llm)
|
99 |
+
query_engine = RetrieverQueryEngine(retriever=retriever, response_synthesizer=synthesizer)
|
100 |
|
101 |
+
response = query_engine.query(query)
|
102 |
+
return response.response
|
103 |
|
104 |
+
except Exception as e:
|
105 |
+
return f"An error occurred: {e}"
|
106 |
|
107 |
|
108 |
+
wikipedia_search_tool = FunctionTool.from_defaults(
|
109 |
+
wikipedia_search,
|
110 |
+
name="wikipedia_search",
|
111 |
+
description="Searches wikipedia and converts results into a high quality answer."
|
112 |
+
)
|
113 |
|
114 |
+
agent = AgentWorkflow.from_tools_or_functions([duckduckgo_search_tool, youtube_transcript_answer_tool, wikipedia_search_tool], llm=self.llm)
|
115 |
async def run_agent():
|
116 |
return await agent.run(question)
|
117 |
|