Spaces:
Sleeping
Sleeping
fix booking issues
Browse files
app.py
CHANGED
|
@@ -8,7 +8,14 @@ from openai.types.responses import ResponseTextDeltaEvent
|
|
| 8 |
|
| 9 |
|
| 10 |
|
|
|
|
|
|
|
|
|
|
| 11 |
|
|
|
|
|
|
|
|
|
|
|
|
|
| 12 |
|
| 13 |
CSV_PATH = "availablity.csv"
|
| 14 |
|
|
@@ -47,18 +54,18 @@ def get_availability(date: str) -> str:
|
|
| 47 |
|
| 48 |
# Book a room if available
|
| 49 |
@function_tool
|
| 50 |
-
def book_room(date: str, room_type: str, guests: int) -> str:
|
| 51 |
"""
|
| 52 |
-
Attempts to book a
|
| 53 |
|
| 54 |
-
Args:
|
| 55 |
-
|
| 56 |
-
|
| 57 |
-
|
|
|
|
| 58 |
|
| 59 |
-
Returns:
|
| 60 |
-
|
| 61 |
-
or an error message if the room is unavailable or does not exist.
|
| 62 |
"""
|
| 63 |
df = load_data()
|
| 64 |
match = (df['date'] == date) & (df['room_type'].str.lower() == room_type.lower())
|
|
@@ -68,14 +75,12 @@ Returns:
|
|
| 68 |
return f"No {room_type} room available on {date}."
|
| 69 |
|
| 70 |
idx = room_row.index[0]
|
| 71 |
-
if df.at[idx, 'available'] >
|
| 72 |
-
df.at[idx, 'available'] -=
|
| 73 |
save_data(df)
|
| 74 |
-
return f"✅ Booked
|
| 75 |
else:
|
| 76 |
-
return f"❌
|
| 77 |
-
|
| 78 |
-
|
| 79 |
|
| 80 |
load_dotenv(find_dotenv())
|
| 81 |
api_key = os.getenv('OpenAI_api_key')
|
|
|
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
+
# @cl.on_message
|
| 12 |
+
# async def main(message: cl.Message):
|
| 13 |
+
# # Your custom logic goes here...
|
| 14 |
|
| 15 |
+
# # Send a response back to the user
|
| 16 |
+
# await cl.Message(
|
| 17 |
+
# content=f"Received: {message.content}",
|
| 18 |
+
# ).send()
|
| 19 |
|
| 20 |
CSV_PATH = "availablity.csv"
|
| 21 |
|
|
|
|
| 54 |
|
| 55 |
# Book a room if available
|
| 56 |
@function_tool
|
| 57 |
+
def book_room(date: str, room_type: str, guests: int, num_rooms: int = 1) -> str:
|
| 58 |
"""
|
| 59 |
+
Attempts to book a specified number of rooms of the given type on a date.
|
| 60 |
|
| 61 |
+
Args:
|
| 62 |
+
date (str): The booking date (format: YYYY-MM-DD).
|
| 63 |
+
room_type (str): The type of room to book (e.g., 'single', 'double', 'suite').
|
| 64 |
+
guests (int): Number of guests for the booking.
|
| 65 |
+
num_rooms (int, optional): Number of rooms to book. Defaults to 1.
|
| 66 |
|
| 67 |
+
Returns:
|
| 68 |
+
str: A confirmation message if booking is successful, or an error message.
|
|
|
|
| 69 |
"""
|
| 70 |
df = load_data()
|
| 71 |
match = (df['date'] == date) & (df['room_type'].str.lower() == room_type.lower())
|
|
|
|
| 75 |
return f"No {room_type} room available on {date}."
|
| 76 |
|
| 77 |
idx = room_row.index[0]
|
| 78 |
+
if df.at[idx, 'available'] >= num_rooms:
|
| 79 |
+
df.at[idx, 'available'] -= num_rooms
|
| 80 |
save_data(df)
|
| 81 |
+
return f"✅ Booked {num_rooms} {room_type.title()} room(s) for {guests} guest(s) on {date}."
|
| 82 |
else:
|
| 83 |
+
return f"❌ Only {df.at[idx, 'available']} {room_type.title()} rooms left on {date}."
|
|
|
|
|
|
|
| 84 |
|
| 85 |
load_dotenv(find_dotenv())
|
| 86 |
api_key = os.getenv('OpenAI_api_key')
|