Spaces:
Runtime error
Runtime error
| from smolagents import tool | |
| import requests | |
| import pandas as pd | |
| # Below is an example of a tool that does nothing. Amaze us with your creativity ! | |
| # @tool | |
| # def my_custom_tool(arg1:str, arg2:int): str #it's important to specify the return type | |
| # #Keep this format for the description / args / args description but feel free to modify the tool | |
| # """A tool that does nothing yet | |
| # Args: | |
| # arg1: the first argument | |
| # arg2: the second argument | |
| # """ | |
| # # return | |
| # Function to get current prices of specified cryptocurrencies | |
| def get_crypto_prices(crypto_ids='tokens', currency='usd'): str | |
| """This is a tool to get current crypto token market prices in usd currency using the coingecko api. | |
| This is the crypto token prices tool | |
| args1 (str): Input for crypto_ids is a string | |
| args2: (str): Output for currency is an srting | |
| Returns: | |
| (str): You should return all valid requests with the crypto id, and its current price in usd denominations. | |
| """ | |
| url = "https://pro-api.coingecko.com/api/v3/simple/price?&x_cg_demo_api_key=CG-4TqTQv39JuPvRFmz3dz5Kcff" | |
| response = requests.get(url) | |
| if response.status_code == 200: | |
| data = response.json() | |
| print (pd.DataFrame(data).T) # Transpose for better readability | |
| else: | |
| print("Failed to retrieve data") | |
| # Specify the cryptocurrencies you want to check | |
| cryptos_ids = ['bitcoin&vs_currencies=usd&x_cg_pro_api_key=CG-4TqTQv39JuPvRFmz3dz5Kcff', | |
| 'ethereum&vs_currencies=usd&x_cg_pro_api_key=CG-4TqTQv39JuPvRFmz3dz5Kcff', | |
| 'ripple&vs_currencies=usd&x_cg_pro_api_key=CG-4TqTQv39JuPvRFmz3dz5Kcff'] | |
| # Get current prices | |
| prices = get_crypto_prices(cryptos_ids) | |
| print(prices) |