File size: 1,435 Bytes
e4fe5a9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
40afc88
967c695
bf722a2
e4fe5a9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
import importlib

__all__ = ['WeatherApi']


class WeatherApi():
    dependencies = ["requests==2.32.3"]

    inputSchema = {
        "name": "WeatherApi",
        "description": "Returns weather information for a given location",
        "parameters": {
            "type": "object",
            "properties": {
                "location": {
                    "type": "string",
                    "description": "The location for which to get the weather information",
                },
            },
            "required": ["location"],
        },
        "invoke_resource_cost": 0.1,
    }

    def run(self, **kwargs):
        print("Running Weather API test tool")
        location = kwargs.get("location")
        print(f"Location: {location}")

        requests = importlib.import_module("requests")

        response = requests.get(
            f"http://api.openweathermap.org/data/2.5/weather?q={location}&appid=ea50e63a3bea67adaf50fbecbe5b3c1e")
        if response.status_code == 200:
            return {
                "status": "success",
                "message": "Weather API test tool executed successfully",
                "error": None,
                "output": response.json()
            }
        else:
            return {
                "status": "error",
                "message": "Weather API test tool failed",
                "error": response.text,
                "output": None
            }