Fred808 commited on
Commit
7f62c94
·
verified ·
1 Parent(s): ae58f93

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +18 -17
app.py CHANGED
@@ -254,12 +254,13 @@ async def log_order_tracking(order_id: str, status: str, message: str = None):
254
 
255
  from fuzzywuzzy import fuzz
256
 
257
- def match_dish(user_input: str, threshold: int = 80) -> str:
 
258
  best_match = None
259
  best_score = 0
260
  for item in menu_items:
261
  dish_name = item["name"]
262
- score = fuzz.ratio(user_input.lower(), dish_name.lower())
263
  if score > best_score:
264
  best_score = score
265
  best_match = dish_name
@@ -397,21 +398,21 @@ async def process_order_flow(user_id: str, message: str) -> str:
397
  return "Sure! What dish would you like to order?"
398
 
399
  # If no state exists or not in order flow, try to detect a dish using fuzzy matching.
400
- if not state or state.flow != "order":
401
- found_dish = match_dish(message)
402
- if found_dish:
403
- state = ConversationState()
404
- state.flow = "order"
405
- state.data["dish"] = found_dish
406
- state.update_last_active()
407
- user_state[user_id] = state
408
- numbers = re.findall(r'\d+', message)
409
- if numbers:
410
- quantity = int(numbers[0])
411
- if quantity <= 0:
412
- return "Please enter a valid quantity (e.g., 1, 2, 3)."
413
- state.data["quantity"] = quantity
414
- state.step = 3
415
  phone_pattern = r'(\+?\d{10,15})'
416
  phone_match = re.search(phone_pattern, message)
417
  address = None
 
254
 
255
  from fuzzywuzzy import fuzz
256
 
257
+
258
+ def match_dish(user_input: str, threshold: int = 70) -> str:
259
  best_match = None
260
  best_score = 0
261
  for item in menu_items:
262
  dish_name = item["name"]
263
+ score = fuzz.token_sort_ratio(user_input.lower(), dish_name.lower())
264
  if score > best_score:
265
  best_score = score
266
  best_match = dish_name
 
398
  return "Sure! What dish would you like to order?"
399
 
400
  # If no state exists or not in order flow, try to detect a dish using fuzzy matching.
401
+ if not state or state.flow != "order":
402
+ found_dish = match_dish(message)
403
+ if found_dish:
404
+ state = ConversationState()
405
+ state.flow = "order"
406
+ state.data["dish"] = found_dish
407
+ state.update_last_active()
408
+ user_state[user_id] = state
409
+ numbers = re.findall(r'\d+', message)
410
+ if numbers:
411
+ quantity = int(numbers[0])
412
+ if quantity <= 0:
413
+ return "Please enter a valid quantity (e.g., 1, 2, 3)."
414
+ state.data["quantity"] = quantity
415
+ state.step = 3
416
  phone_pattern = r'(\+?\d{10,15})'
417
  phone_match = re.search(phone_pattern, message)
418
  address = None