Fred808 commited on
Commit
262e8ce
·
verified ·
1 Parent(s): f0f1142

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +12 -9
app.py CHANGED
@@ -364,6 +364,13 @@ async def chatbot_response(request: Request, background_tasks: BackgroundTasks):
364
  elif sentiment_score > 0.3:
365
  sentiment_modifier = "Great to hear from you! "
366
 
 
 
 
 
 
 
 
367
  # Check for specialized commands:
368
  if "menu" in user_message.lower():
369
  # Return menu with images and options for selection
@@ -389,10 +396,11 @@ async def chatbot_response(request: Request, background_tasks: BackgroundTasks):
389
  background_tasks.add_task(log_chat_to_db, user_id, "outbound", str(response_payload))
390
  return JSONResponse(content=response_payload)
391
 
 
 
392
  # Handle dish selection for ordering
393
- if any(item["name"].lower() in user_message.lower() for item in menu_items) or \
394
- any(str(index) == user_message.strip() for index, item in enumerate(menu_items, start=1)):
395
- # Extract the selected dish
396
  selected_dish = None
397
  if user_message.strip().isdigit():
398
  # User selected by number
@@ -428,12 +436,7 @@ async def chatbot_response(request: Request, background_tasks: BackgroundTasks):
428
  background_tasks.add_task(log_chat_to_db, user_id, "outbound", response_text)
429
  return JSONResponse(content={"response": sentiment_modifier + response_text})
430
 
431
- # Check if this is an order flow request
432
- order_response = process_order_flow(user_id, user_message)
433
- if order_response:
434
- background_tasks.add_task(log_chat_to_db, user_id, "outbound", order_response)
435
- return JSONResponse(content={"response": sentiment_modifier + order_response})
436
-
437
  # For context-aware conversation: store conversation context
438
  conversation_context.setdefault(user_id, []).append({"timestamp": datetime.utcnow().isoformat(), "message": user_message})
439
 
 
364
  elif sentiment_score > 0.3:
365
  sentiment_modifier = "Great to hear from you! "
366
 
367
+ # Check if this is an order flow request
368
+ order_response = process_order_flow(user_id, user_message)
369
+ if order_response:
370
+ background_tasks.add_task(log_chat_to_db, user_id, "outbound", order_response)
371
+ return JSONResponse(content={"response": sentiment_modifier + order_response})
372
+
373
+
374
  # Check for specialized commands:
375
  if "menu" in user_message.lower():
376
  # Return menu with images and options for selection
 
396
  background_tasks.add_task(log_chat_to_db, user_id, "outbound", str(response_payload))
397
  return JSONResponse(content=response_payload)
398
 
399
+
400
+
401
  # Handle dish selection for ordering
402
+ if any(item["name"].lower() in user_message.lower() for item in menu_items) or \
403
+ any(str(index) == user_message.strip() for index, item in enumerate(menu_items, start=1)): # Extract the selected dish
 
404
  selected_dish = None
405
  if user_message.strip().isdigit():
406
  # User selected by number
 
436
  background_tasks.add_task(log_chat_to_db, user_id, "outbound", response_text)
437
  return JSONResponse(content={"response": sentiment_modifier + response_text})
438
 
439
+
 
 
 
 
 
440
  # For context-aware conversation: store conversation context
441
  conversation_context.setdefault(user_id, []).append({"timestamp": datetime.utcnow().isoformat(), "message": user_message})
442