sinakhat commited on
Commit
02d671c
·
verified ·
1 Parent(s): ae7a494

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +60 -2
app.py CHANGED
@@ -18,6 +18,58 @@ def my_custom_tool(arg1:str, arg2:int)-> str: #it's import to specify the return
18
  """
19
  return "What magic will you build ?"
20
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
21
  @tool
22
  def get_current_time_in_timezone(timezone: str) -> str:
23
  """A tool that fetches the current local time in a specified timezone.
@@ -42,7 +94,7 @@ final_answer = FinalAnswerTool()
42
  model = HfApiModel(
43
  max_tokens=2096,
44
  temperature=0.5,
45
- model_id='Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloaded
46
  custom_role_conversions=None,
47
  )
48
 
@@ -55,7 +107,13 @@ 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,
 
18
  """
19
  return "What magic will you build ?"
20
 
21
+ @tool
22
+ def weather_forecast(location: str, date: str) -> str:
23
+ """A tool to get the weather forecast for a specific location and date.
24
+ Args:
25
+ location: The location for which to get the weather forecast.
26
+ date: The date for the weather forecast in YYYY-MM-DD format.
27
+ """
28
+ # Example implementation using a weather API
29
+ response = requests.get(f"https://api.weatherapi.com/v1/forecast.json?key=YOUR_API_KEY&q={location}&dt={date}")
30
+ data = response.json()
31
+ forecast = data['forecast']['forecastday'][0]['day']
32
+ return f"Weather forecast for {location} on {date}: {forecast['condition']['text']}, Temperature: {forecast['avgtemp_c']}°C"
33
+
34
+ @tool
35
+ def time_zone_converter(time: str, from_tz: str, to_tz: str) -> str:
36
+ """A tool to convert time from one time zone to another.
37
+ Args:
38
+ time: The time to convert in HH:MM format.
39
+ from_tz: The time zone to convert from.
40
+ to_tz: The time zone to convert to.
41
+ """
42
+ from_zone = pytz.timezone(from_tz)
43
+ to_zone = pytz.timezone(to_tz)
44
+ from_time = datetime.datetime.strptime(time, '%H:%M')
45
+ from_time = from_zone.localize(from_time)
46
+ to_time = from_time.astimezone(to_zone)
47
+ return to_time.strftime('%H:%M %Z')
48
+
49
+ @tool
50
+ def currency_converter(amount: float, from_currency: str, to_currency: str) -> str:
51
+ """A tool to convert currency from one type to another.
52
+ Args:
53
+ amount: The amount of money to convert.
54
+ from_currency: The currency code to convert from.
55
+ to_currency: The currency code to convert to.
56
+ """
57
+ response = requests.get(f"https://api.exchangerate-api.com/v4/latest/{from_currency}")
58
+ data = response.json()
59
+ rate = data['rates'][to_currency]
60
+ converted_amount = amount * rate
61
+ return f"{amount} {from_currency} is equal to {converted_amount:.2f} {to_currency}"
62
+
63
+ @tool
64
+ def task_reminder(task: str, due_date: str) -> str:
65
+ """A tool to set a reminder for a task.
66
+ Args:
67
+ task: The task to be reminded of.
68
+ due_date: The due date for the task in YYYY-MM-DD format.
69
+ """
70
+ return f"Reminder set for task: '{task}' due on {due_date}"
71
+
72
+
73
  @tool
74
  def get_current_time_in_timezone(timezone: str) -> str:
75
  """A tool that fetches the current local time in a specified timezone.
 
94
  model = HfApiModel(
95
  max_tokens=2096,
96
  temperature=0.5,
97
+ model_id='https://pflgm2locj2t89co.us-east-1.aws.endpoints.huggingface.cloud' #'Qwen/Qwen2.5-Coder-32B-Instruct',# it is possible that this model may be overloaded
98
  custom_role_conversions=None,
99
  )
100
 
 
107
 
108
  agent = CodeAgent(
109
  model=model,
110
+ tools=[final_answer,
111
+ get_current_time_in_timezone,
112
+ task_reminder,
113
+ currency_converter,
114
+ time_zone_converter,
115
+ weather_forecast
116
+ ], ## add your tools here (don't remove final answer)
117
  max_steps=6,
118
  verbosity_level=1,
119
  grammar=None,