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: str, currency='usd'): | |
| """This is a tool to get current crypto token market prices in usd currency using the coingecko api. | |
| Args: | |
| args1: crypto_ids= Input for crypto_ids is a string | |
| args2: currency= Output for currency is an integer | |
| Responses: | |
| You should return all valid requests with the crypto id, and its current price in usd denominations. | |
| """ | |
| url = f"https://api.coingecko.com/api/v3/simple/price?ids={','.join(crypto_ids)}&vs_currencies={currency}" | |
| response = requests.get(url) | |
| if response.status_code == 200: | |
| data = response.json() | |
| return pd.DataFrame(data).T # Transpose for better readability | |
| else: | |
| print("Failed to retrieve data") | |
| return None | |
| # Specify the cryptocurrencies you want to check | |
| cryptos = ['bitcoin', 'ethereum', 'ripple'] | |
| # Get current prices | |
| prices = get_crypto_prices(cryptos) | |
| print(prices) |