mhylle commited on
Commit
14fc3b6
·
verified ·
1 Parent(s): 44c34e1

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +13 -20
app.py CHANGED
@@ -1,24 +1,19 @@
1
- from smolagents import CodeAgent,DuckDuckGoSearchTool, HfApiModel,load_tool,tool
2
  import datetime
3
- import requests
4
  import pytz
5
  import yaml
6
- 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(topic:str)-> 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 searches the internet for information about a topic
15
  Args:
16
- topic: the topic that the user is interested in.
17
- arg2: the second argument
18
  """
19
  search_tool = DuckDuckGoSearchTool()
20
- search_results = search_tool.run(topic)
21
- return f"Search results for '{topic}':\n{search_results}"
22
 
23
  @tool
24
  def get_current_time_in_timezone(timezone: str) -> str:
@@ -38,22 +33,21 @@ def get_current_time_in_timezone(timezone: str) -> str:
38
 
39
  final_answer = FinalAnswerTool()
40
  model = HfApiModel(
41
- max_tokens=2096,
42
- temperature=0.5,
43
- model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloaded
44
- custom_role_conversions=None,
45
  )
46
 
47
-
48
  # Import tool from Hub
49
  image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
50
 
51
  with open("prompts.yaml", 'r') as stream:
52
  prompt_templates = yaml.safe_load(stream)
53
-
54
  agent = CodeAgent(
55
  model=model,
56
- tools=[final_answer, my_custom_tool], ## add your tools here (don't remove final answer)
57
  max_steps=6,
58
  verbosity_level=1,
59
  grammar=None,
@@ -63,5 +57,4 @@ agent = CodeAgent(
63
  prompt_templates=prompt_templates
64
  )
65
 
66
-
67
- GradioUI(agent).launch()
 
1
+ from smolagents import CodeAgent, HfApiModel, load_tool, tool, DuckDuckGoSearchTool, FinalAnswerTool
2
  import datetime
 
3
  import pytz
4
  import yaml
 
5
 
6
  from Gradio_UI import GradioUI
7
 
 
8
  @tool
9
+ def search(query: str) -> str:
10
+ """A tool that provides the final answer of the question about life, the universe, and everything.
 
11
  Args:
12
+ query: The query to search for
 
13
  """
14
  search_tool = DuckDuckGoSearchTool()
15
+ print(search_tool(query))
16
+ return f"Final Answer based on search: {search_tool(query)}"
17
 
18
  @tool
19
  def get_current_time_in_timezone(timezone: str) -> str:
 
33
 
34
  final_answer = FinalAnswerTool()
35
  model = HfApiModel(
36
+ max_tokens=2096,
37
+ temperature=0.5,
38
+ model_id='Qwen/Qwen2.5-Coder-32B-Instruct',
39
+ custom_role_conversions=None,
40
  )
41
 
 
42
  # Import tool from Hub
43
  image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
44
 
45
  with open("prompts.yaml", 'r') as stream:
46
  prompt_templates = yaml.safe_load(stream)
47
+
48
  agent = CodeAgent(
49
  model=model,
50
+ tools=[final_answer, get_current_time_in_timezone, search], # Updated tools list
51
  max_steps=6,
52
  verbosity_level=1,
53
  grammar=None,
 
57
  prompt_templates=prompt_templates
58
  )
59
 
60
+ GradioUI(agent).launch()