antoniomtz commited on
Commit
6008cf2
·
verified ·
1 Parent(s): 9f39c86

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +24 -1
app.py CHANGED
@@ -7,6 +7,29 @@ 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
@@ -55,7 +78,7 @@ with open("prompts.yaml", 'r') as stream:
55
 
56
  agent = CodeAgent(
57
  model=model,
58
- tools=[final_answer], ## add your tools here (don't remove final answer)
59
  max_steps=6,
60
  verbosity_level=1,
61
  grammar=None,
 
7
 
8
  from Gradio_UI import GradioUI
9
 
10
+ @tool
11
+ def get_crypto_price(crypto: str, currency: str = "usd") -> str:
12
+ """Fetches the real-time price of a cryptocurrency using CoinGecko.
13
+ Args:
14
+ crypto: The name of the cryptocurrency (e.g., 'bitcoin').
15
+ currency: The fiat currency to convert the price into (default: 'usd').
16
+ Returns:
17
+ A string with the real-time price.
18
+ """
19
+ try:
20
+ url = f"https://api.coingecko.com/api/v3/simple/price?ids={crypto.lower()}&vs_currencies={currency.lower()}"
21
+ response = requests.get(url)
22
+ data = response.json()
23
+
24
+ if crypto.lower() not in data:
25
+ return f"⚠️ Cryptocurrency '{crypto}' not found."
26
+
27
+ price = data[crypto.lower()][currency.lower()]
28
+ return f"💰 Current price of {crypto.capitalize()}: {price} {currency.upper()}"
29
+
30
+ except Exception as e:
31
+ return f"❌ Error fetching price: {str(e)}"
32
+
33
  # Below is an example of a tool that does nothing. Amaze us with your creativity !
34
  @tool
35
  def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return type
 
78
 
79
  agent = CodeAgent(
80
  model=model,
81
+ tools=[final_answer,get_crypto_price], ## add your tools here (don't remove final answer)
82
  max_steps=6,
83
  verbosity_level=1,
84
  grammar=None,