jashp2323 commited on
Commit
0aac97c
·
1 Parent(s): 4d6cbba

fix(dialogue): make rating classification robust to phonetic transcribing errors and fix missing variable references

Browse files
Files changed (1) hide show
  1. app/dialogue_engine.py +46 -1
app/dialogue_engine.py CHANGED
@@ -191,14 +191,29 @@ class OrderConfirmationAgent:
191
  f"Will you be available on {session.delivery_date} to receive your delivery? A simple yes or no would help.")
192
 
193
  elif session.state == "feedback_request":
 
194
  if intent.startswith("rating:"):
195
  rating = int(intent.split(":")[1])
 
 
 
 
 
 
 
 
 
 
 
 
 
 
196
  session.save_rating(rating, extract_freeform_feedback(user_text))
197
  session.end()
198
  if rating >= 4:
199
  return f"Thank you so much for the {rating}-star rating! We appreciate your trust in {STORE_NAME}. Have a wonderful day! Goodbye."
200
  else:
201
- return f"Thank you for your honest feedback. We'll work hard to improve your experience. Have a good day! Goodbye."
202
  else:
203
  return self._retry(session, "feedback_request",
204
  "Could you please give us a rating between 1 and 5? Just say the number.")
@@ -229,6 +244,7 @@ class DeliveryVerificationAgent:
229
 
230
  def process_input(self, session: CallSession, user_text: str) -> str:
231
  intent = detect_intent(user_text)
 
232
  print(f"[Agent2] State={session.state} | Intent={intent} | Input='{user_text[:80]}'")
233
 
234
  if intent == "human":
@@ -312,8 +328,22 @@ class DeliveryVerificationAgent:
312
  return "Thank you for letting us know. Please rate your delivery experience from 1 to 5."
313
 
314
  elif session.state == "feedback_request":
 
315
  if intent.startswith("rating:"):
316
  rating = int(intent.split(":")[1])
 
 
 
 
 
 
 
 
 
 
 
 
 
317
  notes = []
318
  for key in ["condition_notes", "packaging_notes", "missing_notes"]:
319
  if key in session.collected_feedback:
@@ -355,6 +385,7 @@ class FeedbackFollowupAgent:
355
 
356
  def process_input(self, session: CallSession, user_text: str) -> str:
357
  intent = detect_intent(user_text)
 
358
  print(f"[Agent3] State={session.state} | Intent={intent} | Input='{user_text[:80]}'")
359
 
360
  if intent == "human":
@@ -415,8 +446,22 @@ class FeedbackFollowupAgent:
415
  "Lastly, could you please rate your overall experience from 1 to 5? 5 being excellent.")
416
 
417
  elif session.state == "rating":
 
418
  if intent.startswith("rating:"):
419
  rating = int(intent.split(":")[1])
 
 
 
 
 
 
 
 
 
 
 
 
 
420
  parts = []
421
  for key in ["overall_experience", "product_satisfaction", "detailed_feedback"]:
422
  if key in session.collected_feedback and session.collected_feedback[key]:
 
191
  f"Will you be available on {session.delivery_date} to receive your delivery? A simple yes or no would help.")
192
 
193
  elif session.state == "feedback_request":
194
+ rating = None
195
  if intent.startswith("rating:"):
196
  rating = int(intent.split(":")[1])
197
+ else:
198
+ lower = user_text.lower()
199
+ if any(w in lower for w in ["five", "5", "fine", "find"]):
200
+ rating = 5
201
+ elif any(w in lower for w in ["four", "4", "for"]):
202
+ rating = 4
203
+ elif any(w in lower for w in ["three", "3", "tree", "free"]):
204
+ rating = 3
205
+ elif any(w in lower for w in ["two", "2", "too", "to"]):
206
+ rating = 2
207
+ elif any(w in lower for w in ["one", "1", "won"]):
208
+ rating = 1
209
+
210
+ if rating is not None:
211
  session.save_rating(rating, extract_freeform_feedback(user_text))
212
  session.end()
213
  if rating >= 4:
214
  return f"Thank you so much for the {rating}-star rating! We appreciate your trust in {STORE_NAME}. Have a wonderful day! Goodbye."
215
  else:
216
+ return f"Thank you for the {rating}-star rating and your honest feedback. We'll work hard to improve your experience. Have a good day! Goodbye."
217
  else:
218
  return self._retry(session, "feedback_request",
219
  "Could you please give us a rating between 1 and 5? Just say the number.")
 
244
 
245
  def process_input(self, session: CallSession, user_text: str) -> str:
246
  intent = detect_intent(user_text)
247
+ lower = user_text.lower()
248
  print(f"[Agent2] State={session.state} | Intent={intent} | Input='{user_text[:80]}'")
249
 
250
  if intent == "human":
 
328
  return "Thank you for letting us know. Please rate your delivery experience from 1 to 5."
329
 
330
  elif session.state == "feedback_request":
331
+ rating = None
332
  if intent.startswith("rating:"):
333
  rating = int(intent.split(":")[1])
334
+ else:
335
+ if any(w in lower for w in ["five", "5", "fine", "find"]):
336
+ rating = 5
337
+ elif any(w in lower for w in ["four", "4", "for"]):
338
+ rating = 4
339
+ elif any(w in lower for w in ["three", "3", "tree", "free"]):
340
+ rating = 3
341
+ elif any(w in lower for w in ["two", "2", "too", "to"]):
342
+ rating = 2
343
+ elif any(w in lower for w in ["one", "1", "won"]):
344
+ rating = 1
345
+
346
+ if rating is not None:
347
  notes = []
348
  for key in ["condition_notes", "packaging_notes", "missing_notes"]:
349
  if key in session.collected_feedback:
 
385
 
386
  def process_input(self, session: CallSession, user_text: str) -> str:
387
  intent = detect_intent(user_text)
388
+ lower = user_text.lower()
389
  print(f"[Agent3] State={session.state} | Intent={intent} | Input='{user_text[:80]}'")
390
 
391
  if intent == "human":
 
446
  "Lastly, could you please rate your overall experience from 1 to 5? 5 being excellent.")
447
 
448
  elif session.state == "rating":
449
+ rating = None
450
  if intent.startswith("rating:"):
451
  rating = int(intent.split(":")[1])
452
+ else:
453
+ if any(w in lower for w in ["five", "5", "fine", "find"]):
454
+ rating = 5
455
+ elif any(w in lower for w in ["four", "4", "for"]):
456
+ rating = 4
457
+ elif any(w in lower for w in ["three", "3", "tree", "free"]):
458
+ rating = 3
459
+ elif any(w in lower for w in ["two", "2", "too", "to"]):
460
+ rating = 2
461
+ elif any(w in lower for w in ["one", "1", "won"]):
462
+ rating = 1
463
+
464
+ if rating is not None:
465
  parts = []
466
  for key in ["overall_experience", "product_satisfaction", "detailed_feedback"]:
467
  if key in session.collected_feedback and session.collected_feedback[key]: