Spaces:
Sleeping
Sleeping
Add arg number_of_options with default value to app.py
Browse files
app.py
CHANGED
|
@@ -14,7 +14,8 @@ search_tool = DuckDuckGoSearchTool()
|
|
| 14 |
def find_open_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:
|
|
@@ -22,6 +23,7 @@ def find_open_restaurants_by_location(location: str,
|
|
| 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
|
|
@@ -32,7 +34,8 @@ def find_open_restaurants_by_location(location: str,
|
|
| 32 |
local_time = datetime.datetime.now(tz).strftime("%H:%M")
|
| 33 |
|
| 34 |
# Build query dynamically based on provided inputs
|
| 35 |
-
query_parts = [f
|
|
|
|
| 36 |
if cuisine:
|
| 37 |
query_parts.append(f"serving {cuisine} cuisine")
|
| 38 |
if rating:
|
|
@@ -42,12 +45,12 @@ def find_open_restaurants_by_location(location: str,
|
|
| 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 |
# Ensure search_results is a list before iterating
|
| 48 |
if isinstance(search_results, list) and len(search_results) > 0:
|
| 49 |
results_str = "\n".join(
|
| 50 |
-
[f"{result.get('title', 'Unknown')} - {result.get('url', 'No URL')}" for result in search_results]
|
| 51 |
)
|
| 52 |
else:
|
| 53 |
results_str = str(search_results) # Convert to string if it's not a list
|
|
|
|
| 14 |
def find_open_restaurants_by_location(location: str,
|
| 15 |
cuisine: str = None,
|
| 16 |
rating: float = None,
|
| 17 |
+
timezone: str = None,
|
| 18 |
+
number_of_options: int = 5
|
| 19 |
)-> str:
|
| 20 |
"""A tool that searches for restaurants according to location, cuisine, rating and local time.
|
| 21 |
Args:
|
|
|
|
| 23 |
cuisine: An optional string representing the cuisine type (e.g. Asian, Indian, Italian, breakfast, lunch, etc.)
|
| 24 |
rating: An optional float representing the average customer rating of the restaurant from Google, TripAdvisor, or Yelp.
|
| 25 |
timezone: An optional string representing a valid timezone (e.g., 'America/New_York').
|
| 26 |
+
number_of_options: An integer representing the number of return options, default set to 5.
|
| 27 |
"""
|
| 28 |
try:
|
| 29 |
# If no timezone is provided, default to UTC
|
|
|
|
| 34 |
local_time = datetime.datetime.now(tz).strftime("%H:%M")
|
| 35 |
|
| 36 |
# Build query dynamically based on provided inputs
|
| 37 |
+
query_parts = [f"restaurants open in {location}"]
|
| 38 |
+
|
| 39 |
if cuisine:
|
| 40 |
query_parts.append(f"serving {cuisine} cuisine")
|
| 41 |
if rating:
|
|
|
|
| 45 |
search_results = search_tool(query)
|
| 46 |
|
| 47 |
if not search_results:
|
| 48 |
+
return f"❌ No matching restaurants found in {location} at {local_time} fulfilling desired requests."
|
| 49 |
|
| 50 |
# Ensure search_results is a list before iterating
|
| 51 |
if isinstance(search_results, list) and len(search_results) > 0:
|
| 52 |
results_str = "\n".join(
|
| 53 |
+
[f"{result.get('title', 'Unknown')} - {result.get('url', 'No URL')}" for result in search_results[:number_of_options]]
|
| 54 |
)
|
| 55 |
else:
|
| 56 |
results_str = str(search_results) # Convert to string if it's not a list
|