Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
|
@@ -526,21 +526,27 @@ def _build_clarifying_message() -> str:
|
|
| 526 |
"or should I raise a ServiceNow ticket for you?")
|
| 527 |
|
| 528 |
|
|
|
|
| 529 |
def _build_tracking_descriptions(issue_text: str, resolved_text: str) -> Tuple[str, str]:
|
| 530 |
"""
|
| 531 |
-
ShortDescription:
|
| 532 |
-
-
|
| 533 |
-
-
|
|
|
|
| 534 |
"""
|
| 535 |
issue = (issue_text or "").strip()
|
| 536 |
resolved = (resolved_text or "").strip()
|
| 537 |
|
| 538 |
-
# Detect if it's a process/SOP query (heuristic
|
| 539 |
is_process_query = bool(re.search(r"\b(how to|steps|procedure|process)\b", issue.lower()))
|
| 540 |
|
|
|
|
| 541 |
if is_process_query:
|
| 542 |
-
|
|
|
|
|
|
|
| 543 |
else:
|
|
|
|
| 544 |
short_desc = issue[:100]
|
| 545 |
|
| 546 |
long_desc = (
|
|
@@ -551,8 +557,6 @@ def _build_tracking_descriptions(issue_text: str, resolved_text: str) -> Tuple[s
|
|
| 551 |
|
| 552 |
return short_desc, long_desc
|
| 553 |
|
| 554 |
-
|
| 555 |
-
|
| 556 |
def _is_incident_intent(msg_norm: str) -> bool:
|
| 557 |
intent_phrases = [
|
| 558 |
"create ticket", "create a ticket", "raise ticket", "raise a ticket", "open ticket", "open a ticket",
|
|
@@ -1136,23 +1140,35 @@ Return ONLY the rewritten guidance."""
|
|
| 1136 |
|
| 1137 |
options = [{"type": "yesno", "title": "Share details or raise a ticket?"}] if status == "PARTIAL" else []
|
| 1138 |
|
|
|
|
| 1139 |
# ----- Cache last issue hint (used if user later says "issue resolved thanks")
|
| 1140 |
try:
|
| 1141 |
-
|
| 1142 |
-
|
| 1143 |
-
|
| 1144 |
-
|
| 1145 |
-
|
| 1146 |
-
|
| 1147 |
-
|
| 1148 |
-
|
| 1149 |
-
|
| 1150 |
-
|
| 1151 |
-
|
| 1152 |
-
|
| 1153 |
-
|
| 1154 |
-
|
| 1155 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1156 |
except Exception:
|
| 1157 |
pass
|
| 1158 |
|
|
|
|
| 526 |
"or should I raise a ServiceNow ticket for you?")
|
| 527 |
|
| 528 |
|
| 529 |
+
|
| 530 |
def _build_tracking_descriptions(issue_text: str, resolved_text: str) -> Tuple[str, str]:
|
| 531 |
"""
|
| 532 |
+
ShortDescription rules:
|
| 533 |
+
- Process/SOP queries: "Process Steps β <user query>"
|
| 534 |
+
- Error queries: just the user query (e.g., "getting putaway error")
|
| 535 |
+
The function NEVER uses the resolution message for ShortDescription.
|
| 536 |
"""
|
| 537 |
issue = (issue_text or "").strip()
|
| 538 |
resolved = (resolved_text or "").strip()
|
| 539 |
|
| 540 |
+
# Detect if it's a process/SOP query (heuristic)
|
| 541 |
is_process_query = bool(re.search(r"\b(how to|steps|procedure|process)\b", issue.lower()))
|
| 542 |
|
| 543 |
+
# Avoid "Process Steps β Process Steps" duplication
|
| 544 |
if is_process_query:
|
| 545 |
+
# Remove any leading 'process steps' words from issue to avoid duplication
|
| 546 |
+
cleaned_issue = re.sub(r"^\s*(process\s*steps\s*[-β:]?\s*)", "", issue, flags=re.IGNORECASE).strip()
|
| 547 |
+
short_desc = f"Process Steps β {cleaned_issue or issue}"[:100]
|
| 548 |
else:
|
| 549 |
+
# Error or other query: use the issue as-is
|
| 550 |
short_desc = issue[:100]
|
| 551 |
|
| 552 |
long_desc = (
|
|
|
|
| 557 |
|
| 558 |
return short_desc, long_desc
|
| 559 |
|
|
|
|
|
|
|
| 560 |
def _is_incident_intent(msg_norm: str) -> bool:
|
| 561 |
intent_phrases = [
|
| 562 |
"create ticket", "create a ticket", "raise ticket", "raise a ticket", "open ticket", "open a ticket",
|
|
|
|
| 1140 |
|
| 1141 |
options = [{"type": "yesno", "title": "Share details or raise a ticket?"}] if status == "PARTIAL" else []
|
| 1142 |
|
| 1143 |
+
# ----- Cache last issue hint (used if user later says "issue resolved thanks")
|
| 1144 |
# ----- Cache last issue hint (used if user later says "issue resolved thanks")
|
| 1145 |
try:
|
| 1146 |
+
# Always prefer the user's query as the base
|
| 1147 |
+
base_query = (input_data.user_message or "").strip()
|
| 1148 |
+
if detected_intent == "steps":
|
| 1149 |
+
# For process/SOP: cache the user query β not the heading "Process Steps"
|
| 1150 |
+
LAST_ISSUE_HINT = base_query[:100]
|
| 1151 |
+
elif detected_intent == "errors":
|
| 1152 |
+
# For errors: build "<user query> β <first error line shown>"
|
| 1153 |
+
shown_lines = [ln.strip() for ln in (bot_text or "").splitlines() if ln.strip()]
|
| 1154 |
+
|
| 1155 |
+
# Pick the first bullet/colon line that is NOT escalation
|
| 1156 |
+
top_error_line = ""
|
| 1157 |
+
for ln in shown_lines:
|
| 1158 |
+
if re.match(r"^\s*[\-\*\u2022]\s*", ln) or (":" in ln):
|
| 1159 |
+
low = ln.lower()
|
| 1160 |
+
if "escalation" in low:
|
| 1161 |
+
continue # skip escalation sentences
|
| 1162 |
+
top_error_line = ln
|
| 1163 |
+
break
|
| 1164 |
+
# Strip any trailing escalation phrase from the chosen line (safety)
|
| 1165 |
+
if top_error_line:
|
| 1166 |
+
top_error_line = re.split(r"\bif you want to escalate\b", top_error_line, flags=re.IGNORECASE)[0].strip()
|
| 1167 |
+
if top_error_line:
|
| 1168 |
+
LAST_ISSUE_HINT = f"{base_query} β {top_error_line}"
|
| 1169 |
+
else:
|
| 1170 |
+
LAST_ISSUE_HINT = base_query
|
| 1171 |
+
LAST_ISSUE_HINT = LAST_ISSUE_HINT[:100]
|
| 1172 |
except Exception:
|
| 1173 |
pass
|
| 1174 |
|