Spaces:
Sleeping
Sleeping
Update app.py
Browse filesAdded get_bitcoin_price() tool that gets the current price of bitcoin.
app.py
CHANGED
|
@@ -9,14 +9,22 @@ 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
|
| 13 |
-
|
| 14 |
-
|
| 15 |
-
|
| 16 |
-
arg1: the first argument
|
| 17 |
-
arg2: the second argument
|
| 18 |
"""
|
| 19 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 20 |
|
| 21 |
@tool
|
| 22 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
@@ -35,6 +43,7 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
| 35 |
|
| 36 |
|
| 37 |
final_answer = FinalAnswerTool()
|
|
|
|
| 38 |
|
| 39 |
# If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
|
| 40 |
# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
|
|
@@ -55,7 +64,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,
|
|
|
|
| 9 |
|
| 10 |
# Below is an example of a tool that does nothing. Amaze us with your creativity !
|
| 11 |
@tool
|
| 12 |
+
def get_bitcoin_price() -> str:
|
| 13 |
+
"""A tool that fetches the current price of Bitcoin in USD.
|
| 14 |
+
|
| 15 |
+
Returns the current Bitcoin price from the CoinGecko API.
|
|
|
|
|
|
|
| 16 |
"""
|
| 17 |
+
try:
|
| 18 |
+
url = "https://api.coingecko.com/api/v3/simple/price?ids=bitcoin&vs_currencies=usd"
|
| 19 |
+
response = requests.get(url, timeout=10)
|
| 20 |
+
response.raise_for_status()
|
| 21 |
+
|
| 22 |
+
data = response.json()
|
| 23 |
+
price = data['bitcoin']['usd']
|
| 24 |
+
|
| 25 |
+
return f"The current price of Bitcoin is: ${price:,.2f} USD"
|
| 26 |
+
except Exception as e:
|
| 27 |
+
return f"Error fetching Bitcoin price: {str(e)}"
|
| 28 |
|
| 29 |
@tool
|
| 30 |
def get_current_time_in_timezone(timezone: str) -> str:
|
|
|
|
| 43 |
|
| 44 |
|
| 45 |
final_answer = FinalAnswerTool()
|
| 46 |
+
bitcoin_price = get_bitcoin_price()
|
| 47 |
|
| 48 |
# If the agent does not answer, the model is overloaded, please use another model or the following Hugging Face Endpoint that also contains qwen2.5 coder:
|
| 49 |
# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
|
|
|
|
| 64 |
|
| 65 |
agent = CodeAgent(
|
| 66 |
model=model,
|
| 67 |
+
tools=[final_answer],[bitcoin_price] ## add your tools here (don't remove final answer)
|
| 68 |
max_steps=6,
|
| 69 |
verbosity_level=1,
|
| 70 |
grammar=None,
|