Maximofn commited on
Commit
632e37d
·
verified ·
1 Parent(s): ae7a494

First commit web search agent

Browse files
Files changed (1) hide show
  1. app.py +23 -10
app.py CHANGED
@@ -1,4 +1,4 @@
1
- from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
2
  import datetime
3
  import requests
4
  import pytz
@@ -7,16 +7,29 @@ from tools.final_answer import FinalAnswerTool
7
 
8
  from Gradio_UI import GradioUI
9
 
10
- # Below is an example of a tool that does nothing. Amaze us with your creativity !
11
  @tool
12
- def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
13
- #Keep this format for the description / args / args description but feel free to modify the tool
14
- """A tool that does nothing yet
15
  Args:
16
- arg1: the first argument
17
- arg2: the second argument
18
  """
19
- return "What magic will you build ?"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
20
 
21
  @tool
22
  def get_current_time_in_timezone(timezone: str) -> str:
@@ -42,7 +55,7 @@ final_answer = FinalAnswerTool()
42
  model = HfApiModel(
43
  max_tokens=2096,
44
  temperature=0.5,
45
- model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloaded
46
  custom_role_conversions=None,
47
  )
48
 
@@ -55,7 +68,7 @@ with open("prompts.yaml", 'r') as stream:
55
 
56
  agent = CodeAgent(
57
  model=model,
58
- tools=[final_answer], ## add your tools here (don't remove final answer)
59
  max_steps=6,
60
  verbosity_level=1,
61
  grammar=None,
 
1
+ from smolagents import CodeAgent, DuckDuckGoSearchTool, VisitWebpageTool, HfApiModel, load_tool, tool
2
  import datetime
3
  import requests
4
  import pytz
 
7
 
8
  from Gradio_UI import GradioUI
9
 
 
10
  @tool
11
+ def web_search(query:str)-> str:
12
+ """A tool that can search on the internet
 
13
  Args:
14
+ query: A string with the text to be searched for
 
15
  """
16
+ try:
17
+ result = DuckDuckGoSearchTool(query)
18
+ return result
19
+ excep Exception as e:
20
+ return f"Error searching on internet the query '{query}': {str(e)}"
21
+
22
+ @tool
23
+ def visit_web(url:str)-> str:
24
+ """A tool that obtains the content of a website in markdown form.
25
+ Args:
26
+ url: A string with the URL of the website
27
+ """
28
+ try:
29
+ content = VisitWebpageTool(url)
30
+ return content
31
+ excep Exception as e:
32
+ return f"Error fetching page '{url}' content: {str(e)}"
33
 
34
  @tool
35
  def get_current_time_in_timezone(timezone: str) -> str:
 
55
  model = HfApiModel(
56
  max_tokens=2096,
57
  temperature=0.5,
58
+ model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
59
  custom_role_conversions=None,
60
  )
61
 
 
68
 
69
  agent = CodeAgent(
70
  model=model,
71
+ tools=[final_answer, web_search, visit_web],
72
  max_steps=6,
73
  verbosity_level=1,
74
  grammar=None,