abracu commited on
Commit
e6f7b31
·
verified ·
1 Parent(s): 901dc7f

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +28 -1
app.py CHANGED
@@ -38,6 +38,33 @@ def get_current_time_in_timezone(timezone: str) -> str:
38
  except Exception as e:
39
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
40
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
41
 
42
  # 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:
43
  # model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
@@ -63,7 +90,7 @@ with open("prompts.yaml", 'r') as stream:
63
 
64
  agent = CodeAgent(
65
  model=model,
66
- tools=[ddg, final_answer, add, image_generation_tool, get_current_time_in_timezone, ], ## add your tools here (don't remove final answer)
67
  max_steps=6,
68
  verbosity_level=1,
69
  grammar=None,
 
38
  except Exception as e:
39
  return f"Error fetching time for timezone '{timezone}': {str(e)}"
40
 
41
+ @tool
42
+ def get_exchange_rate(base_currency: str, target_currency: str) -> str:
43
+ """
44
+ A tool that fetches the exchange rate between two currencies using the public exchangerate.host API.
45
+
46
+ Args:
47
+ base_currency: The currency code to convert from (e.g., 'USD', 'EUR', 'COP').
48
+ target_currency: The currency code to convert to (e.g., 'EUR', 'MXN', 'JPY').
49
+
50
+ Returns:
51
+ A string with the formatted exchange rate or an error message.
52
+ """
53
+ url = f"https://api.exchangerate.host/latest?base={base_currency}&symbols={target_currency}"
54
+
55
+ try:
56
+ response = requests.get(url)
57
+ data = response.json()
58
+
59
+ if "rates" in data and target_currency in data["rates"]:
60
+ rate = data["rates"][target_currency]
61
+ return f"1 {base_currency} = {rate:.4f} {target_currency}"
62
+ else:
63
+ return f"Could not fetch the exchange rate {base_currency} -> {target_currency}"
64
+
65
+ except Exception as e:
66
+ return f"Error fetching exchange rate: {str(e)}"
67
+
68
 
69
  # 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:
70
  # model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud'
 
90
 
91
  agent = CodeAgent(
92
  model=model,
93
+ tools=[ddg, final_answer, add, image_generation_tool, get_current_time_in_timezone, get_exchange_rate ], ## add your tools here (don't remove final answer)
94
  max_steps=6,
95
  verbosity_level=1,
96
  grammar=None,