rezzie-rich commited on
Commit
f16b098
·
verified ·
1 Parent(s): cddfcf9

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +21 -15
app.py CHANGED
@@ -19,26 +19,32 @@ def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return
19
  return "What magic will you build ?"
20
 
21
  @tool
22
- def fetch_latest_info(query: str, max_results: int = 5) -> str:
23
- """Fetches the latest information using DuckDuckGo's search engine.
 
24
 
25
  Args:
26
  query: The search query string.
27
- max_results: The maximum number of search results to retrieve.
28
 
29
  Returns:
30
- A formatted string containing the titles and URLs of the top search results.
31
  """
32
- from duckduckgo_search import DDGS
33
-
34
- results = []
35
- with DDGS() as ddgs:
36
- for result in ddgs.text(query, max_results=max_results):
37
- title = result.get("title", "No title")
38
- href = result.get("href", "No URL")
39
- results.append(f"- {title}: {href}")
40
-
41
- return "\n".join(results)
 
 
 
 
 
42
 
43
  @tool
44
  def get_current_time_in_timezone(timezone: str) -> str:
@@ -77,7 +83,7 @@ with open("prompts.yaml", 'r') as stream:
77
 
78
  agent = CodeAgent(
79
  model=model,
80
- tools=[final_answer, fetch_latest_info], ## add your tools here (don't remove final answer)
81
  max_steps=6,
82
  verbosity_level=1,
83
  grammar=None,
 
19
  return "What magic will you build ?"
20
 
21
  @tool
22
+ def duckduck_tool(query: str, num_results: int = 5) -> str:
23
+ """
24
+ A tool that uses DuckDuckGo search to retrieve the latest information and webpage content for a given query.
25
 
26
  Args:
27
  query: The search query string.
28
+ num_results: The number of search results to return (default is 5).
29
 
30
  Returns:
31
+ A string summarizing the latest information and webpage content related to the query.
32
  """
33
+ # Perform a DuckDuckGo search using a hypothetical 'duckduckgosearch' function
34
+ search_results = duckduckgosearch(query, num_results)
35
+
36
+ # Initialize an empty string to collect webpage content
37
+ combined_content = ""
38
+
39
+ # Loop through each search result to fetch its webpage content using a hypothetical 'get_webpage_content' function
40
+ for result in search_results:
41
+ webpage_content = get_webpage_content(result.url)
42
+ combined_content += webpage_content + "\n"
43
+
44
+ # Generate a summary answer from the combined content using a hypothetical 'generate_summary' function
45
+ summary_answer = generate_summary(combined_content)
46
+
47
+ return summary_answer
48
 
49
  @tool
50
  def get_current_time_in_timezone(timezone: str) -> str:
 
83
 
84
  agent = CodeAgent(
85
  model=model,
86
+ tools=[final_answer, duckduck_tool], ## add your tools here (don't remove final answer)
87
  max_steps=6,
88
  verbosity_level=1,
89
  grammar=None,