Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
|
@@ -301,10 +301,12 @@ async def chat_with_ai(input_data: ChatInput):
|
|
| 301 |
"""
|
| 302 |
Policy:
|
| 303 |
A) If 'resolved/working' detected → auto-create tracking incident, auto-mark Resolved, and ask if further help needed.
|
| 304 |
-
B) If user intent is 'create ticket' →
|
| 305 |
C) Ticket status intent → if number missing, ask for it; else return status from ServiceNow.
|
| 306 |
-
D) Feedback-only → ask details
|
|
|
|
| 307 |
E) Otherwise, use HYBRID search; rewrite answer from KB only; ask resolved if 'OK', or refine if 'PARTIAL'.
|
|
|
|
| 308 |
"""
|
| 309 |
try:
|
| 310 |
msg_norm = (input_data.user_message or "").lower().strip()
|
|
@@ -364,7 +366,7 @@ async def chat_with_ai(input_data: ChatInput):
|
|
| 364 |
else:
|
| 365 |
err = (result or {}).get("error", "Unknown error")
|
| 366 |
return {
|
| 367 |
-
"bot_response": f"⚠️ I couldn’t create the tracking incident automatically ({err}).
|
| 368 |
"status": "PARTIAL",
|
| 369 |
"context_found": False,
|
| 370 |
"ask_resolved": False,
|
|
@@ -390,12 +392,16 @@ async def chat_with_ai(input_data: ChatInput):
|
|
| 390 |
# --- (B) Incident intent
|
| 391 |
if _is_incident_intent(msg_norm):
|
| 392 |
return {
|
| 393 |
-
"bot_response":
|
|
|
|
|
|
|
|
|
|
| 394 |
"status": (input_data.prev_status or "PARTIAL"),
|
| 395 |
"context_found": False,
|
| 396 |
"ask_resolved": False,
|
| 397 |
-
"suggest_incident":
|
| 398 |
-
"
|
|
|
|
| 399 |
"top_hits": [],
|
| 400 |
"sources": [],
|
| 401 |
"debug": {"intent": "create_ticket"},
|
|
@@ -466,7 +472,7 @@ async def chat_with_ai(input_data: ChatInput):
|
|
| 466 |
"• Site & environment (prod/test)\n"
|
| 467 |
"• When it started and how many users are impacted"
|
| 468 |
if not second_try else
|
| 469 |
-
"It still looks unresolved after clarification.
|
| 470 |
),
|
| 471 |
"status": "NO_KB_MATCH",
|
| 472 |
"context_found": False,
|
|
@@ -500,8 +506,7 @@ async def chat_with_ai(input_data: ChatInput):
|
|
| 500 |
clarify_text = (
|
| 501 |
_build_clarifying_message()
|
| 502 |
if not second_try
|
| 503 |
-
else "I still don’t find a relevant KB match for this scenario even after clarification.
|
| 504 |
-
"Would you like me to raise a ServiceNow incident?"
|
| 505 |
)
|
| 506 |
return {
|
| 507 |
"bot_response": clarify_text,
|
|
|
|
| 301 |
"""
|
| 302 |
Policy:
|
| 303 |
A) If 'resolved/working' detected → auto-create tracking incident, auto-mark Resolved, and ask if further help needed.
|
| 304 |
+
B) If user intent is 'create incident/ticket' → SHOW INCIDENT FORM (ask Short & Long description). No Yes/No confirmation here.
|
| 305 |
C) Ticket status intent → if number missing, ask for it; else return status from ServiceNow.
|
| 306 |
+
D) Feedback-only → first ask clarifying details; after user shares details, try KB again.
|
| 307 |
+
If still no context after clarification → suggest incident ONCE (Yes/No).
|
| 308 |
E) Otherwise, use HYBRID search; rewrite answer from KB only; ask resolved if 'OK', or refine if 'PARTIAL'.
|
| 309 |
+
|
| 310 |
"""
|
| 311 |
try:
|
| 312 |
msg_norm = (input_data.user_message or "").lower().strip()
|
|
|
|
| 366 |
else:
|
| 367 |
err = (result or {}).get("error", "Unknown error")
|
| 368 |
return {
|
| 369 |
+
"bot_response": f"⚠️ I couldn’t create the tracking incident automatically ({err}).",
|
| 370 |
"status": "PARTIAL",
|
| 371 |
"context_found": False,
|
| 372 |
"ask_resolved": False,
|
|
|
|
| 392 |
# --- (B) Incident intent
|
| 393 |
if _is_incident_intent(msg_norm):
|
| 394 |
return {
|
| 395 |
+
"bot_response":(
|
| 396 |
+
"Okay, let’s create a ServiceNow incident.\n\n"
|
| 397 |
+
"Please provide:\n• Short Description (one line)\n• Detailed Description (steps, error text, IDs, site, environment)"
|
| 398 |
+
),
|
| 399 |
"status": (input_data.prev_status or "PARTIAL"),
|
| 400 |
"context_found": False,
|
| 401 |
"ask_resolved": False,
|
| 402 |
+
"suggest_incident": False,
|
| 403 |
+
"show_incident_form": True,
|
| 404 |
+
"followup": None,
|
| 405 |
"top_hits": [],
|
| 406 |
"sources": [],
|
| 407 |
"debug": {"intent": "create_ticket"},
|
|
|
|
| 472 |
"• Site & environment (prod/test)\n"
|
| 473 |
"• When it started and how many users are impacted"
|
| 474 |
if not second_try else
|
| 475 |
+
"It still looks unresolved after clarification."
|
| 476 |
),
|
| 477 |
"status": "NO_KB_MATCH",
|
| 478 |
"context_found": False,
|
|
|
|
| 506 |
clarify_text = (
|
| 507 |
_build_clarifying_message()
|
| 508 |
if not second_try
|
| 509 |
+
else "I still don’t find a relevant KB match for this scenario even after clarification."
|
|
|
|
| 510 |
)
|
| 511 |
return {
|
| 512 |
"bot_response": clarify_text,
|