ritog commited on
Commit
1125b73
·
verified ·
1 Parent(s): ae7a494

adding dog facts tool

Browse files

added a tool that fetches a cool dog fact using: https://dogapi.dog/docs/api-v2

Files changed (1) hide show
  1. app.py +24 -0
app.py CHANGED
@@ -18,6 +18,30 @@ def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return
18
  """
19
  return "What magic will you build ?"
20
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
  @tool
22
  def get_current_time_in_timezone(timezone: str) -> str:
23
  """A tool that fetches the current local time in a specified timezone.
 
18
  """
19
  return "What magic will you build ?"
20
 
21
+ @tool
22
+ def get_amazing_dog_fact()-> str:
23
+ """A tool that tells you an amazing fact about dogs using a public API.
24
+ Args: None
25
+ """
26
+ # URL for the public API
27
+ url = "https://dogapi.dog/api/v2/facts?limit=1"
28
+
29
+ # case when there is a response from the API
30
+ try:
31
+ #
32
+ response = requests.get(url)
33
+ if response.status_code == 200: # excpected, okay status code
34
+ # parsing status code
35
+ cool_dog_fact = response.json()['data'][0]['attributes']['body']
36
+ return cool_dog_fact
37
+ else:
38
+ # in case of an unfavorable status code
39
+ return "A dog fact could not be fetched."
40
+ except requests.exceptions.RequestException as e:
41
+ return "A dog fact could not be fetched."
42
+
43
+
44
+
45
  @tool
46
  def get_current_time_in_timezone(timezone: str) -> str:
47
  """A tool that fetches the current local time in a specified timezone.