9jini commited on
Commit
4f5d400
·
verified ·
1 Parent(s): 6484650

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +19 -1
app.py CHANGED
@@ -11,6 +11,24 @@ from langchain_community.tools.tavily_search import TavilySearchResults
11
  # --- Constants ---
12
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
13
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
14
  # --- Basic Agent Definition ---
15
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
16
  class BasicAgent:
@@ -21,7 +39,7 @@ class BasicAgent:
21
  )
22
  self.agent = CodeAgent(
23
  model=model,
24
- tools=[DuckDuckGoSearchTool(), WikipediaSearchTool(),VisitWebpageTool(),TavilySearchResults()],
25
  add_base_tools=True,
26
  )
27
  print("BasicAgent initialized.")
 
11
  # --- Constants ---
12
  DEFAULT_API_URL = "https://agents-course-unit4-scoring.hf.space"
13
 
14
+
15
+ @tool
16
+ def web_search(query: str) -> str:
17
+ """Search Tavily for a query and return maximum 3 results.
18
+
19
+ Args:
20
+ query: The search query."""
21
+ search_docs = TavilySearchResults(max_results=3).invoke(query=query)
22
+ formatted_search_docs = "\n\n---\n\n".join(
23
+ [
24
+ f'<Document source="{doc.metadata["source"]}" page="{doc.metadata.get("page", "")}"/>\n{doc.page_content}\n</Document>'
25
+ for doc in search_docs
26
+ ])
27
+ return {"web_results": formatted_search_docs}
28
+
29
+
30
+
31
+
32
  # --- Basic Agent Definition ---
33
  # ----- THIS IS WERE YOU CAN BUILD WHAT YOU WANT ------
34
  class BasicAgent:
 
39
  )
40
  self.agent = CodeAgent(
41
  model=model,
42
+ tools=[DuckDuckGoSearchTool(), WikipediaSearchTool(),VisitWebpageTool(),web_search()],
43
  add_base_tools=True,
44
  )
45
  print("BasicAgent initialized.")