File size: 990 Bytes
20b15f3
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
27
28
29
30
31
32
33
34
"""
ui/intent_text.py
-----------------
INTENT text <-> 3-field form conversion.

The backend hands us ONE string with three headed sections. We split it into
three editable fields and MUST rebuild the exact same "Problem: / Objective:
/ Additional Context:" shape before sending it into the search graph -- its
prompts assume that literal structure.
"""

import re

_SECTION_PATTERN = re.compile(
    r"Problem:\s*(.*?)\n\s*Objective:\s*(.*?)\n\s*Additional Context:\s*(.*)",
    re.S,
)


def split_intent_sections(text: str):
    m = _SECTION_PATTERN.search(text or "")
    if m:
        return m.group(1).strip(), m.group(2).strip(), m.group(3).strip()
    return (text or "").strip(), "", ""


def join_intent_sections(problem: str, objective: str, additional_context: str) -> str:
    ac = additional_context.strip() or "None specified."
    return (
        f"Problem:\n{problem.strip()}\n\n"
        f"Objective:\n{objective.strip()}\n\n"
        f"Additional Context:\n{ac}"
    )