jeipollack commited on
Commit
c6121ee
·
verified ·
1 Parent(s): cb0e2f8

Generalise the function and make some args optional

Browse files
Files changed (1) hide show
  1. app.py +25 -13
app.py CHANGED
@@ -11,28 +11,40 @@ from Gradio_UI import GradioUI
11
  search_tool = DuckDuckGoSearchTool()
12
 
13
  @tool
14
- def find_open_restaurants(location: str, cuisine: str, rating: float, timezone: str)-> str: # it's important to specify the return type
15
- # Keep this format for the tool description / args description but feel free to modify the tool
16
- """A tool that does nothing yet
 
 
 
17
  Args:
18
  location: A string representing the location area to search for open restaurants.
19
- cuisine: A string representing the cuisine type (e.g. Asian, Indian, Italian, breakfast, lunch, etc.)
20
- rating: A float representing the average customer rating of the restaurant from Google, TripAdvisor, or Yelp.
21
- timezone: A string representing a valid timezone (e.g., 'America/New_York').
22
  """
23
  try:
24
- # Get the current local time
25
- tz = pytz.timezone(timezone)
 
 
 
26
  local_time = datetime.datetime.now(tz).strftime("%H:%M")
27
 
28
- # Search for restaurants of the specified cuisine that are open now
29
- query = f"{cuisine} restaurants open now in {location} with rating equal to or greater than {rating}."
30
- search_results = search_tool(query) # Properly call the search tool
 
 
 
 
 
 
31
 
32
  if not search_results:
33
- return f"❌ No open {cuisine} restaurants found in {location} at {local_time}."
34
 
35
- return f"🍽️ Open {cuisine} restaurants in {location} at {local_time}:\n\n" + "\n".join(
36
  [result["title"] + " - " + result["url"] for result in search_results[:5]]
37
  )
38
 
 
11
  search_tool = DuckDuckGoSearchTool()
12
 
13
  @tool
14
+ def find_restaurants_by_location(location: str,
15
+ cuisine: str = None,
16
+ rating: float = None,
17
+ timezone: str = None
18
+ )-> str:
19
+ """A tool that searches for restaurants according to location, cuisine, rating and local time.
20
  Args:
21
  location: A string representing the location area to search for open restaurants.
22
+ cuisine: An optional string representing the cuisine type (e.g. Asian, Indian, Italian, breakfast, lunch, etc.)
23
+ rating: An optional float representing the average customer rating of the restaurant from Google, TripAdvisor, or Yelp.
24
+ timezone: An optional string representing a valid timezone (e.g., 'America/New_York').
25
  """
26
  try:
27
+ # If no timezone is provided, default to UTC
28
+ if timezone:
29
+ tz = pytz.timezone(timezone)
30
+ else:
31
+ tz = pytz.utc # Default timezone
32
  local_time = datetime.datetime.now(tz).strftime("%H:%M")
33
 
34
+ # Build query dynamically based on provided inputs
35
+ query_parts = [f"restaurants open now in {location}"]
36
+ if cuisine:
37
+ query_parts.append(f"serving {cuisine} cuisine")
38
+ if rating:
39
+ query_parts.append(f"with a rating of {rating} or higher")
40
+
41
+ query = " ".join(query_parts) # Construct final query
42
+ search_results = search_tool(query)
43
 
44
  if not search_results:
45
+ return f"❌ No matching restaurants found in {location} at {local_time}."
46
 
47
+ return f"🍽️ Open restaurants in {location} at {local_time}:\n\n" + "\n".join(
48
  [result["title"] + " - " + result["url"] for result in search_results[:5]]
49
  )
50