Commit
·
536eabf
1
Parent(s):
61f9a75
fix: try google search
Browse files
app.py
CHANGED
@@ -13,6 +13,7 @@ from llama_index.core.tools import FunctionTool
|
|
13 |
from llama_index.tools.duckduckgo import DuckDuckGoSearchToolSpec
|
14 |
from llama_index.core.agent.workflow import AgentWorkflow
|
15 |
from llama_index.llms.gemini import Gemini
|
|
|
16 |
from llama_index.retrievers.bm25 import BM25Retriever
|
17 |
from llama_index.core.query_engine import RetrieverQueryEngine
|
18 |
from llama_index.core.tools import QueryEngineTool
|
@@ -61,29 +62,28 @@ class BasicAgent:
|
|
61 |
description="Fetches transcript of the given youtube_link and returns matching answers based on query. To be called when video link is given.",
|
62 |
)
|
63 |
|
64 |
-
def web_page_reader(url: str, query: str) -> str:
|
65 |
-
|
66 |
-
|
67 |
-
|
68 |
-
|
69 |
-
|
70 |
-
|
71 |
-
|
72 |
-
|
73 |
-
|
74 |
-
|
75 |
-
|
76 |
-
web_page_reader_tool = FunctionTool.from_defaults(
|
77 |
-
|
78 |
-
|
79 |
-
|
80 |
-
)
|
81 |
|
82 |
def duck_duck_go_search_tool(query: str) -> str:
|
83 |
try:
|
84 |
-
raw_results =
|
85 |
-
|
86 |
-
full_text = "\n".join(texts)
|
87 |
return "Here's the responses from the search: " + full_text
|
88 |
|
89 |
except Exception as e:
|
@@ -115,7 +115,7 @@ class BasicAgent:
|
|
115 |
description="Searches wikipedia and converts results into a high quality answer."
|
116 |
)
|
117 |
|
118 |
-
self.agent = AgentWorkflow.from_tools_or_functions([duckduckgo_search_tool, youtube_transcript_answer_tool, wikipedia_search_tool
|
119 |
print("BasicAgent initialized.")
|
120 |
|
121 |
async def run_agent(self, question: str):
|
@@ -186,7 +186,7 @@ async def run_and_submit_all( profile: gr.OAuthProfile | None):
|
|
186 |
answers_payload = []
|
187 |
print(f"Running agent on {len(questions_data)} questions...")
|
188 |
for item in questions_data:
|
189 |
-
await asyncio.sleep(
|
190 |
task_id = item.get("task_id")
|
191 |
question_text = item.get("question")
|
192 |
if not task_id or question_text is None:
|
|
|
13 |
from llama_index.tools.duckduckgo import DuckDuckGoSearchToolSpec
|
14 |
from llama_index.core.agent.workflow import AgentWorkflow
|
15 |
from llama_index.llms.gemini import Gemini
|
16 |
+
from llama_index.tools.google import GoogleSearchToolSpec
|
17 |
from llama_index.retrievers.bm25 import BM25Retriever
|
18 |
from llama_index.core.query_engine import RetrieverQueryEngine
|
19 |
from llama_index.core.tools import QueryEngineTool
|
|
|
62 |
description="Fetches transcript of the given youtube_link and returns matching answers based on query. To be called when video link is given.",
|
63 |
)
|
64 |
|
65 |
+
# def web_page_reader(url: str, query: str) -> str:
|
66 |
+
# try:
|
67 |
+
# documents = SimpleWebPageReader(html_to_text=True).load_data(
|
68 |
+
# [url]
|
69 |
+
# )
|
70 |
+
# index = SummaryIndex.from_documents(documents)
|
71 |
+
# query_engine = index.as_query_engine()
|
72 |
+
# response = query_engine.query(query)
|
73 |
+
# return response.response
|
74 |
+
# except Exception as e:
|
75 |
+
# print("error in webpage", e)
|
76 |
+
|
77 |
+
# web_page_reader_tool = FunctionTool.from_defaults(
|
78 |
+
# web_page_reader,
|
79 |
+
# name="web_page_reader",
|
80 |
+
# description="Visits the wepage on given url and returns response on the passed query"
|
81 |
+
# )
|
82 |
|
83 |
def duck_duck_go_search_tool(query: str) -> str:
|
84 |
try:
|
85 |
+
raw_results = GoogleSearchToolSpec(key="AIzaSyBCp55z6a9hRqYoJZLluK-rku7uAST4qdk", engine="042d23e47f6584359").google_search(query=query)
|
86 |
+
full_text = raw_results[0].text
|
|
|
87 |
return "Here's the responses from the search: " + full_text
|
88 |
|
89 |
except Exception as e:
|
|
|
115 |
description="Searches wikipedia and converts results into a high quality answer."
|
116 |
)
|
117 |
|
118 |
+
self.agent = AgentWorkflow.from_tools_or_functions([duckduckgo_search_tool, youtube_transcript_answer_tool, wikipedia_search_tool], llm=self.llm)
|
119 |
print("BasicAgent initialized.")
|
120 |
|
121 |
async def run_agent(self, question: str):
|
|
|
186 |
answers_payload = []
|
187 |
print(f"Running agent on {len(questions_data)} questions...")
|
188 |
for item in questions_data:
|
189 |
+
await asyncio.sleep(10)
|
190 |
task_id = item.get("task_id")
|
191 |
question_text = item.get("question")
|
192 |
if not task_id or question_text is None:
|