Spaces:
Sleeping
Sleeping
Update main.py
Browse files
main.py
CHANGED
|
@@ -312,14 +312,18 @@ def _soft_match_score(a: str, b: str) -> float:
|
|
| 312 |
# combine (weights tuned to prefer phrase overlaps slightly)
|
| 313 |
return min(1.0, 0.65 * jacc + 0.45 * big)
|
| 314 |
|
|
|
|
| 315 |
def _detect_next_intent(user_query: str) -> bool:
|
| 316 |
q = _norm_text(user_query)
|
| 317 |
keys = [
|
| 318 |
-
|
| 319 |
-
|
|
|
|
|
|
|
| 320 |
]
|
| 321 |
return any(k in q for k in keys)
|
| 322 |
|
|
|
|
| 323 |
def _resolve_next_steps(user_query: str, numbered_text: str, max_next: int = 8, min_score: float = 0.25):
|
| 324 |
"""
|
| 325 |
Robust next-step resolver:
|
|
@@ -932,38 +936,43 @@ async def chat_with_ai(input_data: ChatInput):
|
|
| 932 |
context_preformatted = False
|
| 933 |
|
| 934 |
if best_doc and detected_intent == "steps":
|
| 935 |
-
|
| 936 |
-
|
| 937 |
-
|
| 938 |
-
|
| 939 |
-
|
| 940 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 941 |
if full_steps:
|
| 942 |
-
|
| 943 |
-
|
| 944 |
input_data.user_message,
|
| 945 |
numbered_full,
|
| 946 |
max_next=6,
|
| 947 |
-
min_score=0.35
|
| 948 |
-
|
| 949 |
-
|
| 950 |
-
|
| 951 |
-
|
| 952 |
-
|
| 953 |
-
|
| 954 |
-
|
| 955 |
-
|
| 956 |
-
|
| 957 |
-
|
| 958 |
-
|
| 959 |
-
|
| 960 |
-
|
| 961 |
-
|
| 962 |
-
|
| 963 |
-
|
| 964 |
-
|
| 965 |
-
|
| 966 |
-
|
| 967 |
|
| 968 |
elif best_doc and detected_intent == "errors":
|
| 969 |
full_errors = get_best_errors_section_text(best_doc)
|
|
@@ -1081,7 +1090,7 @@ Return ONLY the rewritten guidance."""
|
|
| 1081 |
return {
|
| 1082 |
"bot_response": bot_text,
|
| 1083 |
"status": status,
|
| 1084 |
-
"context_found":
|
| 1085 |
"ask_resolved": (status == "OK" and detected_intent != "errors"),
|
| 1086 |
"suggest_incident": (status == "PARTIAL"),
|
| 1087 |
"followup": (assist_followup if assist_followup else ("Is this helpful, or should I raise a ticket?" if status == "PARTIAL" else None)),
|
|
|
|
| 312 |
# combine (weights tuned to prefer phrase overlaps slightly)
|
| 313 |
return min(1.0, 0.65 * jacc + 0.45 * big)
|
| 314 |
|
| 315 |
+
|
| 316 |
def _detect_next_intent(user_query: str) -> bool:
|
| 317 |
q = _norm_text(user_query)
|
| 318 |
keys = [
|
| 319 |
+
'after','after this','what next','whats next','next step',
|
| 320 |
+
'then what','following step','continue','subsequent','proceed',
|
| 321 |
+
# new entries
|
| 322 |
+
'what to do','what should i do','how to proceed','how do i continue','proceed further','next?'
|
| 323 |
]
|
| 324 |
return any(k in q for k in keys)
|
| 325 |
|
| 326 |
+
|
| 327 |
def _resolve_next_steps(user_query: str, numbered_text: str, max_next: int = 8, min_score: float = 0.25):
|
| 328 |
"""
|
| 329 |
Robust next-step resolver:
|
|
|
|
| 936 |
context_preformatted = False
|
| 937 |
|
| 938 |
if best_doc and detected_intent == "steps":
|
| 939 |
+
|
| 940 |
+
sec = (top_meta or {}).get('section', '')
|
| 941 |
+
actions = kb_results.get('actions', [])
|
| 942 |
+
sec_low = (sec or '').lower()
|
| 943 |
+
wants_delete = ('delete' in actions) or ('remove' in actions) or ('delete' in sec_low) or ('remov' in sec_low)
|
| 944 |
+
if wants_delete and sec:
|
| 945 |
+
full_steps = get_section_text(best_doc, sec)
|
| 946 |
+
else:
|
| 947 |
+
full_steps = get_best_steps_section_text(best_doc)
|
| 948 |
+
if not full_steps and sec:
|
| 949 |
+
full_steps = get_section_text(best_doc, sec)
|
| 950 |
if full_steps:
|
| 951 |
+
numbered_full = _ensure_numbering(full_steps)
|
| 952 |
+
next_only = _resolve_next_steps(
|
| 953 |
input_data.user_message,
|
| 954 |
numbered_full,
|
| 955 |
max_next=6,
|
| 956 |
+
min_score=0.35)
|
| 957 |
+
if next_only is not None:
|
| 958 |
+
if len(next_only) == 0:
|
| 959 |
+
context = "You are at the final step of this SOP. No further steps."
|
| 960 |
+
next_step_applied = True
|
| 961 |
+
next_step_info = {"count": 0}
|
| 962 |
+
context_preformatted = True
|
| 963 |
+
else:
|
| 964 |
+
|
| 965 |
+
context = _format_steps_as_numbered(next_only)
|
| 966 |
+
next_step_applied = True
|
| 967 |
+
next_step_info = {"count": len(next_only)}
|
| 968 |
+
context_preformatted = True
|
| 969 |
+
else:
|
| 970 |
+
context = full_steps
|
| 971 |
+
context_preformatted = False
|
| 972 |
+
|
| 973 |
+
# clear filter info for debug clarity
|
| 974 |
+
filt_info = {'mode': None, 'matched_count': None, 'all_sentences': None}
|
| 975 |
+
context_found = True
|
| 976 |
|
| 977 |
elif best_doc and detected_intent == "errors":
|
| 978 |
full_errors = get_best_errors_section_text(best_doc)
|
|
|
|
| 1090 |
return {
|
| 1091 |
"bot_response": bot_text,
|
| 1092 |
"status": status,
|
| 1093 |
+
"context_found": context_found,
|
| 1094 |
"ask_resolved": (status == "OK" and detected_intent != "errors"),
|
| 1095 |
"suggest_incident": (status == "PARTIAL"),
|
| 1096 |
"followup": (assist_followup if assist_followup else ("Is this helpful, or should I raise a ticket?" if status == "PARTIAL" else None)),
|