ankush13r commited on
Commit
d0847ea
·
verified ·
1 Parent(s): 23cd067

Update tools.py

Browse files
Files changed (1) hide show
  1. tools.py +8 -35
tools.py CHANGED
@@ -203,11 +203,11 @@ class make_reservation(ToolBase):
203
  Creates a new reservation for the hotel by booking a room of the specified type for the desired dates, and associating the booking with a user.
204
  """
205
 
 
206
  room_type: str = Field(default=list(json_data["room_types"].keys()), description="The type of room being reserved.")
207
  check_in_date: str = Field(description="The starting date of the reservation (e.g., \"2025-04-01\")")
208
  check_out_date: str = Field(description="The ending date of the reservation (e.g., \"2025-04-05\").")
209
  guests: int = Field(description="The number of guests for the reservation.")
210
- user_id: int = Field(description="The identifier for the user making the reservation.")
211
 
212
  @classmethod
213
  def invoke(cls, input: Dict) -> str:
@@ -216,7 +216,7 @@ class make_reservation(ToolBase):
216
  check_in_date = input.get("check_in_date", None)
217
  check_out_date = input.get("check_out_date", None)
218
  guests = input.get("guests", None)
219
- user_id = input.get("user_id", None)
220
 
221
  missing = []
222
  if not room_type:
@@ -227,8 +227,8 @@ class make_reservation(ToolBase):
227
  missing.append("check_out_date")
228
  if not guests:
229
  missing.append("guests")
230
- if not user_id:
231
- missing.append("user_id")
232
 
233
  if len(missing):
234
  value = ", ".join(missing)
@@ -240,7 +240,7 @@ class make_reservation(ToolBase):
240
  check_in_date = instance.check_in_date
241
  check_out_date = instance.check_out_date
242
  guests = instance.guests
243
- user_id = instance.user_id
244
 
245
  rooms = [room for room in json_data["accomodations"]["rooms"] if room_type in room["type"]]
246
  if len(rooms) == 0:
@@ -265,7 +265,7 @@ class make_reservation(ToolBase):
265
  "check_out_date": check_out_date,
266
  "guests": guests,
267
  "reservation_id": rand,
268
- "user_id": user_id,
269
  }
270
 
271
  reservations[rand] = tmp_data
@@ -276,20 +276,16 @@ class make_reservation(ToolBase):
276
  class cancel_reservation(ToolBase):
277
  """Playing a specific playlist by its name."""
278
 
279
- user_id: int = Field(description="The identifier for the user requesting the cancellation.")
280
  reservation_id: int = Field(description="The unique identifier of the reservation to be canceled.")
281
 
282
  @classmethod
283
  def invoke(cls, input: Dict) -> str:
284
 
285
  reservation_id = input.get("reservation_id", None)
286
- user_id = input.get("user_id", None)
287
 
288
  missing = []
289
  if not reservation_id:
290
  missing.append("reservation_id")
291
- if not user_id:
292
- missing.append("user_id")
293
 
294
  if len(missing):
295
  value = ", ".join(missing)
@@ -297,16 +293,12 @@ class cancel_reservation(ToolBase):
297
 
298
  instance = cls(**input)
299
  reservation_id = instance.reservation_id
300
- user_id = instance.user_id
301
-
302
 
303
 
 
304
  if reservation_id not in reservations:
305
  return f"There is no reservations with the id: {reservation_id}"
306
 
307
- if reservations["reservation_id"]["user_id"] != user_id:
308
- return "The user id is wrong, please provide same user id that was used make to reservation."
309
-
310
  reservations.pop(reservation_id)
311
  return f"The reservation {reservation_id} is cancled correctly"
312
 
@@ -321,27 +313,22 @@ class modify_reservation(ToolBase):
321
  new_check_in_date: str = Field(default=None, description="New check out date in format DD/MM/YYYY")
322
  new_check_out_date: str = Field(default=None, description="New check out date in format DD/MM/YYYY")
323
  guests: int = Field(default=None, description="New number of guests for the reservation.")
324
- user_id: int = Field(description="The identifier for the user requesting the modification.")
325
  reservation_id: int = Field(description="The unique identifier of the reservation to be modified.")
326
 
327
  @classmethod
328
  def invoke(cls, input: Dict) -> str:
329
 
330
- user_id = input.get("user_id", None)
331
  reservation_id = input.get("reservation_id", None)
332
 
333
  missing = []
334
  if not reservation_id:
335
  missing.append("reservation_id")
336
- if not user_id:
337
- missing.append("user_id")
338
 
339
  instance = cls(**input)
340
  new_room_type = instance.new_room_type
341
  new_check_in_date = instance.new_check_in_date
342
  new_check_out_date = instance.new_check_out_date
343
  guests = instance.guests
344
- user_id = instance.user_id
345
  reservation_id = instance.reservation_id
346
 
347
  if len(missing):
@@ -355,9 +342,6 @@ class modify_reservation(ToolBase):
355
  if reservation_id not in reservations:
356
  return f"There is no reservations with the id: {reservation_id}"
357
 
358
- if reservations["reservation_id"]["user_id"] != user_id:
359
- return "The user id is wrong, please provide same user id that was used make to reservation."
360
-
361
  if new_room_type or guests:
362
  rooms = [room for room in json_data["restaurants"] if new_room_type in room["type"]]
363
  if len(rooms) == 0:
@@ -380,43 +364,32 @@ class modify_reservation(ToolBase):
380
  reservations["reservation_id"]["room_type"] = new_room_type if new_room_type else reservations["reservation_id"]["room_type"]
381
  reservations["reservation_id"]["room_number"] = room_number
382
 
383
- tmp_data = copy.deepcopy(reservations["reservation_id"])
384
- tmp_data.pop("user_id")
385
-
386
- return f"The reservation {reservation_id} is modified correctly: {json.dumps(tmp_data)}"
387
 
388
  @tool_register
389
  class reservation_details(ToolBase):
390
  """Playing a specific playlist by its name."""
391
 
392
- user_id: int = Field(description="Id of user, could be passport or national Identity number")
393
  reservation_id: int = Field(description="Id of the reservation")
394
 
395
  @classmethod
396
  def invoke(cls, input: Dict) -> str:
397
- user_id = input.get("user_id", None)
398
  reservation_id = input.get("reservation_id", None)
399
 
400
  missing = []
401
  if not reservation_id:
402
  missing.append("reservation_id")
403
- if not user_id:
404
- missing.append("user_id")
405
 
406
  if len(missing):
407
  value = ", ".join(missing)
408
  return f"Unable to get the details. The following required arguments are missing:{value}."
409
 
410
  instance = cls(**input)
411
- user_id = instance.user_id
412
  reservation_id = instance.reservation_id
413
 
414
  if reservation_id not in reservations:
415
  return f"There is no reservations with the id: {reservation_id}"
416
 
417
- if reservations["reservation_id"]["user_id"] != user_id:
418
- return "The user id is wrong, please provide same user id that was used make to reservation."
419
 
420
  tmp_data = copy.deepcopy(reservations["reservation_id"])
421
- tmp_data.pop("user_id")
422
  return json.dumps(tmp_data)
 
203
  Creates a new reservation for the hotel by booking a room of the specified type for the desired dates, and associating the booking with a user.
204
  """
205
 
206
+ user_name: int = Field(description="The name of user who is doing reservation.")
207
  room_type: str = Field(default=list(json_data["room_types"].keys()), description="The type of room being reserved.")
208
  check_in_date: str = Field(description="The starting date of the reservation (e.g., \"2025-04-01\")")
209
  check_out_date: str = Field(description="The ending date of the reservation (e.g., \"2025-04-05\").")
210
  guests: int = Field(description="The number of guests for the reservation.")
 
211
 
212
  @classmethod
213
  def invoke(cls, input: Dict) -> str:
 
216
  check_in_date = input.get("check_in_date", None)
217
  check_out_date = input.get("check_out_date", None)
218
  guests = input.get("guests", None)
219
+ user_name = input.get("user_name", None)
220
 
221
  missing = []
222
  if not room_type:
 
227
  missing.append("check_out_date")
228
  if not guests:
229
  missing.append("guests")
230
+ if not user_name:
231
+ missing.append("user_name")
232
 
233
  if len(missing):
234
  value = ", ".join(missing)
 
240
  check_in_date = instance.check_in_date
241
  check_out_date = instance.check_out_date
242
  guests = instance.guests
243
+ user_name = instance.user_name.lower()
244
 
245
  rooms = [room for room in json_data["accomodations"]["rooms"] if room_type in room["type"]]
246
  if len(rooms) == 0:
 
265
  "check_out_date": check_out_date,
266
  "guests": guests,
267
  "reservation_id": rand,
268
+ "user_name": user_name,
269
  }
270
 
271
  reservations[rand] = tmp_data
 
276
  class cancel_reservation(ToolBase):
277
  """Playing a specific playlist by its name."""
278
 
 
279
  reservation_id: int = Field(description="The unique identifier of the reservation to be canceled.")
280
 
281
  @classmethod
282
  def invoke(cls, input: Dict) -> str:
283
 
284
  reservation_id = input.get("reservation_id", None)
 
285
 
286
  missing = []
287
  if not reservation_id:
288
  missing.append("reservation_id")
 
 
289
 
290
  if len(missing):
291
  value = ", ".join(missing)
 
293
 
294
  instance = cls(**input)
295
  reservation_id = instance.reservation_id
 
 
296
 
297
 
298
+
299
  if reservation_id not in reservations:
300
  return f"There is no reservations with the id: {reservation_id}"
301
 
 
 
 
302
  reservations.pop(reservation_id)
303
  return f"The reservation {reservation_id} is cancled correctly"
304
 
 
313
  new_check_in_date: str = Field(default=None, description="New check out date in format DD/MM/YYYY")
314
  new_check_out_date: str = Field(default=None, description="New check out date in format DD/MM/YYYY")
315
  guests: int = Field(default=None, description="New number of guests for the reservation.")
 
316
  reservation_id: int = Field(description="The unique identifier of the reservation to be modified.")
317
 
318
  @classmethod
319
  def invoke(cls, input: Dict) -> str:
320
 
 
321
  reservation_id = input.get("reservation_id", None)
322
 
323
  missing = []
324
  if not reservation_id:
325
  missing.append("reservation_id")
 
 
326
 
327
  instance = cls(**input)
328
  new_room_type = instance.new_room_type
329
  new_check_in_date = instance.new_check_in_date
330
  new_check_out_date = instance.new_check_out_date
331
  guests = instance.guests
 
332
  reservation_id = instance.reservation_id
333
 
334
  if len(missing):
 
342
  if reservation_id not in reservations:
343
  return f"There is no reservations with the id: {reservation_id}"
344
 
 
 
 
345
  if new_room_type or guests:
346
  rooms = [room for room in json_data["restaurants"] if new_room_type in room["type"]]
347
  if len(rooms) == 0:
 
364
  reservations["reservation_id"]["room_type"] = new_room_type if new_room_type else reservations["reservation_id"]["room_type"]
365
  reservations["reservation_id"]["room_number"] = room_number
366
 
367
+ return f"The reservation {reservation_id} is modified correctly: {json.dumps(reservations["reservation_id"])}"
 
 
 
368
 
369
  @tool_register
370
  class reservation_details(ToolBase):
371
  """Playing a specific playlist by its name."""
372
 
 
373
  reservation_id: int = Field(description="Id of the reservation")
374
 
375
  @classmethod
376
  def invoke(cls, input: Dict) -> str:
 
377
  reservation_id = input.get("reservation_id", None)
378
 
379
  missing = []
380
  if not reservation_id:
381
  missing.append("reservation_id")
 
 
382
 
383
  if len(missing):
384
  value = ", ".join(missing)
385
  return f"Unable to get the details. The following required arguments are missing:{value}."
386
 
387
  instance = cls(**input)
 
388
  reservation_id = instance.reservation_id
389
 
390
  if reservation_id not in reservations:
391
  return f"There is no reservations with the id: {reservation_id}"
392
 
 
 
393
 
394
  tmp_data = copy.deepcopy(reservations["reservation_id"])
 
395
  return json.dumps(tmp_data)