srilakshu012456 commited on
Commit
5dd6a63
·
verified ·
1 Parent(s): fee1d0f

Update main.py

Browse files
Files changed (1) hide show
  1. main.py +23 -7
main.py CHANGED
@@ -659,16 +659,32 @@ async def chat_with_ai(input_data: ChatInput):
659
  bot_text = context
660
  bot_text = _strip_any_source_lines(bot_text).strip()
661
 
662
- # If the intent is steps, render lines as a numbered Markdown list
663
  if kb_results.get("user_intent", "neutral") == "steps":
664
  raw_lines = [ln.strip() for ln in bot_text.splitlines() if ln.strip()]
665
- # Some SOPs may have steps concatenated on a single line separated by ". " → split defensively
666
- if len(raw_lines) == 1:
667
- # split on ". " while keeping abbreviations safe (very simple heuristic)
668
- parts = [p.strip() for p in re.split(r"\.\s+(?=[A-Z0-9])", raw_lines[0]) if p.strip()]
669
- raw_lines = parts if len(parts) > 1 else raw_lines
670
- bot_text = _format_steps_markdown(raw_lines)
671
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
672
 
673
  status = "OK" if (
674
  (best_combined is not None and best_combined >= gate_combined_ok)
 
659
  bot_text = context
660
  bot_text = _strip_any_source_lines(bot_text).strip()
661
 
662
+ # If the intent is steps, render lines as a numbered Markdown list
663
  if kb_results.get("user_intent", "neutral") == "steps":
664
  raw_lines = [ln.strip() for ln in bot_text.splitlines() if ln.strip()]
 
 
 
 
 
 
665
 
666
+ # If everything is on a single line, split defensively on ". "
667
+ if len(raw_lines) == 1:
668
+ parts = [p.strip() for p in re.split(r"\.\s+(?=[A-Z0-9])", raw_lines[0]) if p.strip()]
669
+ raw_lines = parts if len(parts) > 1 else raw_lines
670
+
671
+ # 🔴 NEW: merge number-only lines with the next line
672
+ merged: list[str] = []
673
+ i = 0
674
+ while i < len(raw_lines):
675
+ curr = raw_lines[i]
676
+ # A number-only line (e.g., "1", "2", "3")
677
+ if re.fullmatch(r"\d+", curr) and (i + 1) < len(raw_lines):
678
+ nxt = raw_lines[i + 1].strip()
679
+ # Combine into one line: "1. <next line text>"
680
+ merged.append(f"{curr}. {nxt}")
681
+ i += 2 # skip the next line; already merged
682
+ else:
683
+ merged.append(curr)
684
+ i += 1
685
+
686
+ # Finally: normalize and render as Markdown numbered list
687
+ bot_text = _format_steps_markdown(merged)
688
 
689
  status = "OK" if (
690
  (best_combined is not None and best_combined >= gate_combined_ok)