kenobi commited on
Commit
3d7df3d
·
verified ·
1 Parent(s): 26a2245

Update app.py

Browse files

updated debugging and weatherinfo

Files changed (1) hide show
  1. app.py +48 -16
app.py CHANGED
@@ -1,17 +1,16 @@
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(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
@@ -35,9 +34,14 @@ def get_current_time_in_timezone(timezone: str) -> str:
35
 
36
  @tool
37
  def get_weather(location: str) -> str:
38
- """A tool that fetches current weather information for a specified location.
 
 
39
  Args:
40
  location: A string representing a city name, coordinates, or location (e.g., 'London', 'New York, NY', '40.7128,-74.0060').
 
 
 
41
  """
42
  try:
43
  # Using wttr.in API which provides weather data in a simple format
@@ -83,29 +87,58 @@ Wind: {wind_speed_kmph} km/h ({wind_speed_mph} mph) {wind_dir}"""
83
  except Exception as e:
84
  return f"Error fetching weather for '{location}': {str(e)}"
85
 
 
 
 
 
 
 
 
 
 
 
 
 
 
86
 
87
  final_answer = FinalAnswerTool()
88
 
89
  # 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:
90
- # model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
91
-
92
  model = HfApiModel(
93
- max_tokens=2096,
94
- temperature=0.5,
95
- model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloaded
96
- custom_role_conversions=None,
97
  )
98
 
99
-
100
  # Import tool from Hub
101
  image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
102
 
103
  with open("prompts.yaml", 'r') as stream:
104
  prompt_templates = yaml.safe_load(stream)
105
-
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
106
  agent = CodeAgent(
107
  model=model,
108
- tools=[final_answer], ## add your tools here (don't remove final answer)
109
  max_steps=6,
110
  verbosity_level=1,
111
  grammar=None,
@@ -115,5 +148,4 @@ agent = CodeAgent(
115
  prompt_templates=prompt_templates
116
  )
117
 
118
-
119
  GradioUI(agent).launch()
 
1
+ from smolagents import CodeAgent, DuckDuckGoSearchTool, HfApiModel, load_tool, tool, Tool
2
  import datetime
3
  import requests
4
  import pytz
5
  import yaml
6
  from tools.final_answer import FinalAnswerTool
 
7
  from Gradio_UI import GradioUI
8
 
9
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
10
  @tool
11
+ def my_custom_tool(arg1: str, arg2: int) -> str: # it's import to specify the return type
12
+ # Keep this format for the description / args / args description but feel free to modify the tool
13
+ """A tool that does nothing yet
14
  Args:
15
  arg1: the first argument
16
  arg2: the second argument
 
34
 
35
  @tool
36
  def get_weather(location: str) -> str:
37
+ """
38
+ Get current weather conditions for any location. Use this tool when asked about weather, temperature, or climate conditions.
39
+
40
  Args:
41
  location: A string representing a city name, coordinates, or location (e.g., 'London', 'New York, NY', '40.7128,-74.0060').
42
+
43
+ Returns:
44
+ str: A formatted string containing the current weather information including temperature, conditions, humidity, and wind.
45
  """
46
  try:
47
  # Using wttr.in API which provides weather data in a simple format
 
87
  except Exception as e:
88
  return f"Error fetching weather for '{location}': {str(e)}"
89
 
90
+ # Alternative: Create a wrapper tool with a more explicit name
91
+ @tool
92
+ def check_current_weather(location: str) -> str:
93
+ """
94
+ Check the current weather for a location. This is the primary tool for weather information.
95
+
96
+ Args:
97
+ location: City name or location (e.g., 'Paris', 'Tokyo, Japan')
98
+
99
+ Returns:
100
+ str: Current weather conditions with temperature, humidity, and wind information
101
+ """
102
+ return get_weather(location)
103
 
104
  final_answer = FinalAnswerTool()
105
 
106
  # 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:
107
+ # model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
 
108
  model = HfApiModel(
109
+ max_tokens=2096,
110
+ temperature=0.5,
111
+ model_id='Qwen/Qwen2.5-Coder-32B-Instruct', # it is possible that this model may be overloaded
112
+ custom_role_conversions=None,
113
  )
114
 
 
115
  # Import tool from Hub
116
  image_generation_tool = load_tool("agents-course/text-to-image", trust_remote_code=True)
117
 
118
  with open("prompts.yaml", 'r') as stream:
119
  prompt_templates = yaml.safe_load(stream)
120
+
121
+ # Create tools list with all tools
122
+ tools_list = [
123
+ final_answer,
124
+ get_current_time_in_timezone,
125
+ get_weather,
126
+ check_current_weather, # Adding the alternative weather tool
127
+ my_custom_tool,
128
+ image_generation_tool
129
+ ]
130
+
131
+ # Debug: Print available tools
132
+ print("Available tools:")
133
+ for tool in tools_list:
134
+ if hasattr(tool, 'name'):
135
+ print(f" - {tool.name}: {tool.description if hasattr(tool, 'description') else 'No description'}")
136
+ else:
137
+ print(f" - {tool}")
138
+
139
  agent = CodeAgent(
140
  model=model,
141
+ tools=tools_list, # Use the tools list
142
  max_steps=6,
143
  verbosity_level=1,
144
  grammar=None,
 
148
  prompt_templates=prompt_templates
149
  )
150
 
 
151
  GradioUI(agent).launch()