File size: 896 Bytes
df33039
 
 
33f778e
df33039
 
 
 
 
33f778e
df33039
 
 
33f778e
 
 
df33039
 
 
33f778e
df33039
 
 
33f778e
df33039
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import re

def format_llm_response(llm_output):
    """
    Formats LLM output into structured Markdown and extracts approach titles.
    
    Returns:
        formatted_markdown (str): Markdown-formatted response
        approach_titles (list): Extracted approach titles for dropdown selection
    """
    lines = llm_output.split("\n")
    formatted_response = []
    approach_titles = []

    for line in lines:
        line = line.strip()
        if re.match(r"^Approach \d+: ", line):  # Detects headings
            formatted_response.append(f"### {line}")  # Format as header
            approach_titles.append(line.replace("Approach ", ""))  # Extract title
        elif line.startswith("*"):
            formatted_response.append(f"- {line}")  # Format as bullet points
        else:
            formatted_response.append(line)

    return "\n".join(formatted_response), approach_titles