grevy commited on
Commit
397c945
·
1 Parent(s): 00dc8a5

Add tools.

Browse files
Files changed (1) hide show
  1. app.py +24 -19
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
@@ -8,17 +8,21 @@ import spaces
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
  @tool
13
- def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
14
- #Keep this format for the description / args / args description but feel free to modify the tool
15
- """A tool that does nothing yet
 
 
16
  Args:
17
  arg1: the first argument
18
  arg2: the second argument
19
  """
20
  return "What magic will you build ?"
21
 
 
22
  @tool
23
  def get_current_time_in_timezone(timezone: str) -> str:
24
  """A tool that fetches the current local time in a specified timezone.
@@ -38,36 +42,37 @@ def get_current_time_in_timezone(timezone: str) -> str:
38
  final_answer = FinalAnswerTool()
39
 
40
  # If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
41
- # model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
42
 
43
  model = HfApiModel(
44
- max_tokens=2096,
45
- temperature=0.5,
46
- model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloaded
47
- custom_role_conversions=None,
48
  )
49
- class ZeroGPUCodeAgent(CodeAgent):
50
- @spaces.GPU
51
- def run(self, *args, **kwargs):
52
- return super().run(*args, **kwargs)
53
 
54
  # Import tool from Hub
55
  image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
56
 
57
- with open("prompts.yaml", 'r') as stream:
58
  prompt_templates = yaml.safe_load(stream)
59
-
60
- agent = ZeroGPUCodeAgent(
61
  model=model,
62
- tools=[final_answer], ## add your tools here (don't remove final answer)
 
 
 
 
63
  max_steps=6,
64
  verbosity_level=1,
65
  grammar=None,
66
  planning_interval=None,
67
  name=None,
68
  description=None,
69
- prompt_templates=prompt_templates
70
  )
71
 
72
 
73
- GradioUI(agent).launch()
 
1
+ from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, load_tool, tool
2
  import datetime
3
  import requests
4
  import pytz
 
8
 
9
  from Gradio_UI import GradioUI
10
 
11
+
12
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
13
  @tool
14
+ def my_custom_tool(
15
+ arg1: str, arg2: int
16
+ ) -> str: # it's import to specify the return type
17
+ # Keep this format for the description / args / args description but feel free to modify the tool
18
+ """A tool that does nothing yet
19
  Args:
20
  arg1: the first argument
21
  arg2: the second argument
22
  """
23
  return "What magic will you build ?"
24
 
25
+
26
  @tool
27
  def get_current_time_in_timezone(timezone: str) -> str:
28
  """A tool that fetches the current local time in a specified timezone.
 
42
  final_answer = FinalAnswerTool()
43
 
44
  # If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
45
+ # model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
46
 
47
  model = HfApiModel(
48
+ max_tokens=2096,
49
+ temperature=0.5,
50
+ model_id="Qwen/Qwen2.5-Coder-32B-Instruct", # it is possible that this model may be overloaded
51
+ custom_role_conversions=None,
52
  )
53
+
 
 
 
54
 
55
  # Import tool from Hub
56
  image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
57
 
58
+ with open("prompts.yaml", "r") as stream:
59
  prompt_templates = yaml.safe_load(stream)
60
+
61
+ agent = CodeAgent(
62
  model=model,
63
+ tools=[
64
+ final_answer,
65
+ get_current_time_in_timezone,
66
+ image_generation_tool,
67
+ ], ## add your tools here (don't remove final answer)
68
  max_steps=6,
69
  verbosity_level=1,
70
  grammar=None,
71
  planning_interval=None,
72
  name=None,
73
  description=None,
74
+ prompt_templates=prompt_templates,
75
  )
76
 
77
 
78
+ GradioUI(agent).launch()