wphoenix commited on
Commit
5a0472b
·
verified ·
1 Parent(s): d5beefa

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -1
app.py CHANGED
@@ -4,6 +4,9 @@ import requests
4
  import pytz
5
  import yaml
6
  from tools.final_answer import FinalAnswerTool
 
 
 
7
 
8
  from Gradio_UI import GradioUI
9
 
@@ -22,6 +25,33 @@ def my_custom_tool(arg1:str, arg2:int)-> str: #it's important to specify the ret
22
  """
23
  return "What magic will you build ?"
24
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
25
  @tool
26
  def get_current_time_in_timezone(timezone: str) -> str:
27
  """A tool that fetches the current local time in a specified timezone.
@@ -115,7 +145,7 @@ with open("prompts.yaml", 'r') as stream:
115
 
116
  agent = CodeAgent(
117
  model=model,
118
- tools=[final_answer, image_generation_tool, get_current_time_in_timezone], ## add your tools here (don't remove final answer)
119
  max_steps=6,
120
  verbosity_level=1,
121
  grammar=None,
 
4
  import pytz
5
  import yaml
6
  from tools.final_answer import FinalAnswerTool
7
+ #from requests import Request, Session
8
+ from requests.exceptions import ConnectionError, Timeout, TooManyRedirects
9
+ import json
10
 
11
  from Gradio_UI import GradioUI
12
 
 
25
  """
26
  return "What magic will you build ?"
27
 
28
+ @tool
29
+ def fetch_active_crypto()-> str: #it's important to specify the return type
30
+ #Keep this format for the description / args / args description but feel free to modify the tool
31
+ """A tool that fetches all active crypto by market cap in USD
32
+ """
33
+ url = 'https://sandbox-api.coinmarketcap.com/v1/cryptocurrency/listings/latest'
34
+ parameters = {
35
+ 'start':'1',
36
+ 'limit':'5000',
37
+ 'convert':'USD'
38
+ }
39
+ headers = {
40
+ 'Accepts': 'application/json',
41
+ 'X-CMC_PRO_API_KEY': 'b54bcf4d-1bca-4e8e-9a24-22ff2c3d462c',
42
+ }
43
+
44
+ session = Session()
45
+ session.headers.update(headers)
46
+
47
+ try:
48
+ response = session.get(url, params=parameters)
49
+ data = json.loads(response.text)
50
+ return data
51
+ except (ConnectionError, Timeout, TooManyRedirects) as e:
52
+ return e
53
+
54
+
55
  @tool
56
  def get_current_time_in_timezone(timezone: str) -> str:
57
  """A tool that fetches the current local time in a specified timezone.
 
145
 
146
  agent = CodeAgent(
147
  model=model,
148
+ tools=[final_answer, image_generation_tool, get_current_time_in_timezone, fetch_active_crypto], ## add your tools here (don't remove final answer)
149
  max_steps=6,
150
  verbosity_level=1,
151
  grammar=None,