File size: 695 Bytes
6733714
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
def generate_answer(question: str, context: str) -> str:
    """
    Deterministic, demo-safe answer generator.
    Uses retrieved context only.
    """

    if not context or context.strip() == "":
        return "The answer is not available in the provided documents."

    # Simple conclusion-first formatting
    lines = context.strip().split("\n")

    summary = []
    for line in lines:
        if len(line.strip()) > 30:
            summary.append(line.strip())
        if len(summary) == 3:
            break

    if not summary:
        return "The answer is not available in the provided documents."

    return (
        "Based on the documents:\n"
        + " ".join(summary)
    )