srilakshu012456 commited on
Commit
dd5e496
·
verified ·
1 Parent(s): 036b7e4

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +25 -3
main.py CHANGED
@@ -699,6 +699,23 @@ async def chat_with_ai(input_data: ChatInput):
699
  if detected_intent == "neutral" and any(h in sec_title for h in PREREQ_HEADINGS):
700
  detected_intent = "prereqs"
701
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
702
  # --- Meaning-aware SOP gating ---
703
  def _contains_any(s: str, keywords: tuple) -> bool:
704
  low = (s or "").lower()
@@ -711,7 +728,9 @@ async def chat_with_ai(input_data: ChatInput):
711
  "asn", "grn", "pick", "picking"
712
  )
713
  ACTION_OR_ERROR_TERMS = (
 
714
  "close", "closing", "open", "navigate", "scan", "confirm", "generate", "update",
 
715
  "error", "issue", "fail", "failed", "not working", "locked", "mismatch",
716
  "access", "permission", "status"
717
  )
@@ -728,7 +747,10 @@ async def chat_with_ai(input_data: ChatInput):
728
  weak_domain_only = (mentions_domain and not has_any_action_or_error)
729
  low_context_hit = (matched_count < 2 and filter_mode in ("concise", "exact"))
730
 
731
- if weak_domain_only or (low_context_hit and not combined_ok):
 
 
 
732
  return {
733
  "bot_response": _build_clarifying_message(),
734
  "status": "NO_KB_MATCH",
@@ -745,12 +767,12 @@ async def chat_with_ai(input_data: ChatInput):
745
  "filter_mode": filter_mode,
746
  "best_combined": best_combined,
747
  "mentions_domain": mentions_domain,
748
- "has_any_action_or_error": has_any_action_or_error
 
749
  },
750
  }
751
 
752
  # Build SOP context if allowed
753
- is_perm_query = any(t in msg_norm for t in PERM_QUERY_TERMS)
754
  if is_perm_query:
755
  detected_intent = "errors"
756
 
 
699
  if detected_intent == "neutral" and any(h in sec_title for h in PREREQ_HEADINGS):
700
  detected_intent = "prereqs"
701
 
702
+ # --- Steps nudge: "how to / perform" + receiving/inbound => steps intent
703
+ STEPS_TERMS = ("how to", "procedure", "perform", "steps", "do", "navigate")
704
+ RECEIVING_TERMS = ("inbound", "receiving", "goods receipt", "grn")
705
+
706
+ mod_tags = ((top_meta or {}).get("module_tags") or "").lower()
707
+
708
+ looks_like_steps_query = any(t in msg_low for t in STEPS_TERMS)
709
+ looks_like_receiving = (
710
+ any(t in msg_low for t in RECEIVING_TERMS)
711
+ or "receiving" in mod_tags
712
+ or "inbound" in sec_title
713
+ or "receiving" in sec_title
714
+ )
715
+
716
+ if detected_intent in ("neutral", "prereqs") and looks_like_steps_query and looks_like_receiving:
717
+ detected_intent = "steps"
718
+
719
  # --- Meaning-aware SOP gating ---
720
  def _contains_any(s: str, keywords: tuple) -> bool:
721
  low = (s or "").lower()
 
728
  "asn", "grn", "pick", "picking"
729
  )
730
  ACTION_OR_ERROR_TERMS = (
731
+ "how to", "procedure", "perform", # added
732
  "close", "closing", "open", "navigate", "scan", "confirm", "generate", "update",
733
+ "receive", "receiving", # added
734
  "error", "issue", "fail", "failed", "not working", "locked", "mismatch",
735
  "access", "permission", "status"
736
  )
 
747
  weak_domain_only = (mentions_domain and not has_any_action_or_error)
748
  low_context_hit = (matched_count < 2 and filter_mode in ("concise", "exact"))
749
 
750
+ # Bypass gate when strong steps signals are present for Receiving module
751
+ strong_steps_bypass = looks_like_steps_query and looks_like_receiving
752
+
753
+ if (weak_domain_only or (low_context_hit and not combined_ok)) and not strong_steps_bypass:
754
  return {
755
  "bot_response": _build_clarifying_message(),
756
  "status": "NO_KB_MATCH",
 
767
  "filter_mode": filter_mode,
768
  "best_combined": best_combined,
769
  "mentions_domain": mentions_domain,
770
+ "has_any_action_or_error": has_any_action_or_error,
771
+ "strong_steps_bypass": strong_steps_bypass
772
  },
773
  }
774
 
775
  # Build SOP context if allowed
 
776
  if is_perm_query:
777
  detected_intent = "errors"
778