k0smes commited on
Commit
2d1c389
·
verified ·
1 Parent(s): 8b39655

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +4 -23
app.py CHANGED
@@ -1,36 +1,17 @@
1
- from smolagents import CodeAgent, HfApiModel, load_tool, tool
2
  import datetime
3
  import requests
4
  import pytz
5
  import yaml
6
  from tools.final_answer import FinalAnswerTool
7
- from ddgs import DDGS
8
 
9
  from Gradio_UI import GradioUI
10
 
11
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
12
- ddg_tool_instance = DDGS()
13
-
14
- @tool
15
- def web_search(query: str, max_results: int = 3) -> str:
16
- """
17
- Search the web for up-to-date information using DuckDuckGo via ddgs.
18
 
19
- Args:
20
- query: The search query
21
- max_results: Number of top results to return
22
 
23
- Returns:
24
- Top search results as a string with title + URL
25
- """
26
- try:
27
- results = ddg_tool_instance.text(query, max_results=max_results)
28
- if not results:
29
- return "No results found! Try a less restrictive query."
30
- top_results = results[:max_results]
31
- return "\n".join([f"{r['title']}: {r['href']}" for r in top_results])
32
- except Exception as e:
33
- return f"Error during web search: {str(e)}"
34
 
35
  @tool
36
  def get_current_time_in_timezone(timezone: str) -> str:
@@ -73,7 +54,7 @@ agent = CodeAgent(
73
  tools=[
74
  final_answer,
75
  get_current_time_in_timezone,
76
- web_search
77
  ], ## add your tools here (don't remove final answer)
78
  max_steps=6,
79
  verbosity_level=1,
 
1
+ from smolagents import CodeAgent, HfApiModel, DuckDuckGoSearchTool, load_tool, tool
2
  import datetime
3
  import requests
4
  import pytz
5
  import yaml
6
  from tools.final_answer import FinalAnswerTool
7
+
8
 
9
  from Gradio_UI import GradioUI
10
 
11
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
12
+ ddg_tool = DuckDuckGoSearchTool()
 
 
 
 
 
13
 
 
 
 
14
 
 
 
 
 
 
 
 
 
 
 
 
15
 
16
  @tool
17
  def get_current_time_in_timezone(timezone: str) -> str:
 
54
  tools=[
55
  final_answer,
56
  get_current_time_in_timezone,
57
+ ddg_tool
58
  ], ## add your tools here (don't remove final answer)
59
  max_steps=6,
60
  verbosity_level=1,