Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -33,9 +33,30 @@ def get_current_time_in_timezone(timezone: str) -> str:
|
|
| 33 |
except Exception as e:
|
| 34 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 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'
|
| 41 |
|
|
@@ -56,7 +77,7 @@ with open("prompts.yaml", 'r') as stream:
|
|
| 56 |
|
| 57 |
agent = CodeAgent(
|
| 58 |
model=model,
|
| 59 |
-
tools=[final_answer, get_current_time_in_timezone], ## add your tools here (don't remove final answer)
|
| 60 |
max_steps=6,
|
| 61 |
verbosity_level=1,
|
| 62 |
grammar=None,
|
|
|
|
| 33 |
except Exception as e:
|
| 34 |
return f"Error fetching time for timezone '{timezone}': {str(e)}"
|
| 35 |
|
| 36 |
+
@tool
|
| 37 |
+
def exchange(base="GBP":str, target="EUR":str, amount:float)-> float: #it's import to specify the return type
|
| 38 |
+
#Keep this format for the description / args / args description but feel free to modify the tool
|
| 39 |
+
"""A tool that calculates currency exchange rates.
|
| 40 |
+
Args:
|
| 41 |
+
base: original currency, as found in yfinance. Examples: USD, EUR, GBP, CHF.
|
| 42 |
+
target: final currency, as found in yfinance. Examples: USD, EUR, GBP, CHF.
|
| 43 |
+
amount: amount of the original currency
|
| 44 |
+
"""
|
| 45 |
+
import yfinance as yf
|
| 46 |
+
|
| 47 |
+
ticker = f"{base}{target}=X"
|
| 48 |
+
data = yf.Ticker(ticker)
|
| 49 |
+
price = data.history(period="1d")["Close"]
|
| 50 |
+
|
| 51 |
+
if not price.empty:
|
| 52 |
+
rate = price.iloc[-1]
|
| 53 |
+
else:
|
| 54 |
+
raise ValueError("Exchange rate not found")
|
| 55 |
+
return rate * amount
|
| 56 |
|
| 57 |
final_answer = FinalAnswerTool()
|
| 58 |
|
| 59 |
+
|
| 60 |
# 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:
|
| 61 |
# model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
|
| 62 |
|
|
|
|
| 77 |
|
| 78 |
agent = CodeAgent(
|
| 79 |
model=model,
|
| 80 |
+
tools=[final_answer, get_current_time_in_timezone, exchange], ## add your tools here (don't remove final answer)
|
| 81 |
max_steps=6,
|
| 82 |
verbosity_level=1,
|
| 83 |
grammar=None,
|