kevindiependaele commited on
Commit
324e81a
·
1 Parent(s): b5a53e1

json/dict output type

Browse files
Files changed (1) hide show
  1. tools/weather_api.py +4 -3
tools/weather_api.py CHANGED
@@ -1,4 +1,5 @@
1
  import os
 
2
 
3
  from smolagents.tools import Tool
4
 
@@ -6,13 +7,13 @@ class WeatherApiTool(Tool):
6
  name = "weather_api"
7
  description = "Fetches the weather for a given location and date."
8
  inputs = {'location': {'type': 'string', 'description': 'The location for which to fetch the weather.'}, 'date': {'type': 'string', 'description': 'The date for which to fetch the weather.'}}
9
- output_type = "string"
10
 
11
  def __init__(self, *args, **kwargs):
12
  super().__init__(*args, **kwargs)
13
  self.api_key = os.environ.get("OPEN_WEATHER_MAP_API_KEY")
14
 
15
- def forward(self, location: str, date: str) -> str:
16
  import requests
17
  import json
18
 
@@ -49,5 +50,5 @@ class WeatherApiTool(Tool):
49
  # temperature = day["temp"]["day"]
50
  # return f"The weather in {location} on {date} is {weather} with a temperature of {temperature}°C."
51
 
52
- return json.dumps(weather_data, indent=4)
53
 
 
1
  import os
2
+ from typing import Dict
3
 
4
  from smolagents.tools import Tool
5
 
 
7
  name = "weather_api"
8
  description = "Fetches the weather for a given location and date."
9
  inputs = {'location': {'type': 'string', 'description': 'The location for which to fetch the weather.'}, 'date': {'type': 'string', 'description': 'The date for which to fetch the weather.'}}
10
+ output_type = "json"
11
 
12
  def __init__(self, *args, **kwargs):
13
  super().__init__(*args, **kwargs)
14
  self.api_key = os.environ.get("OPEN_WEATHER_MAP_API_KEY")
15
 
16
+ def forward(self, location: str, date: str) -> Dict:
17
  import requests
18
  import json
19
 
 
50
  # temperature = day["temp"]["day"]
51
  # return f"The weather in {location} on {date} is {weather} with a temperature of {temperature}°C."
52
 
53
+ return weather_data
54