Spaces:
Running

File size: 2,297 Bytes
8f3b9c2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
"""Prompt field definitions and final prompt assembly."""

from __future__ import annotations

FIELDS: tuple[dict[str, object], ...] = (
    {
        "id": "task",
        "label": "Task",
        "required": True,
        "color": "#9a3412",
        "surface": "#fff7ed",
    },
    {
        "id": "context",
        "label": "Context",
        "required": True,
        "color": "#0f766e",
        "surface": "#ecfdf5",
    },
    {
        "id": "references",
        "label": "References",
        "required": True,
        "color": "#4338ca",
        "surface": "#eef2ff",
    },
    {
        "id": "role",
        "label": "Role",
        "required": False,
        "color": "#7e22ce",
        "surface": "#faf5ff",
    },
    {
        "id": "audience",
        "label": "Audience",
        "required": False,
        "color": "#0369a1",
        "surface": "#f0f9ff",
    },
    {
        "id": "tone",
        "label": "Tone",
        "required": False,
        "color": "#0f766e",
        "surface": "#f0fdfa",
    },
    {
        "id": "constraints",
        "label": "Constraints",
        "required": False,
        "color": "#9f1239",
        "surface": "#fff1f2",
    },
    {
        "id": "outputFormat",
        "label": "Output Format",
        "required": False,
        "color": "#065f46",
        "surface": "#f0fdf4",
    },
    {
        "id": "example",
        "label": "Example",
        "required": False,
        "color": "#7c2d12",
        "surface": "#fff7ed",
    },
)

FIELD_BY_ID: dict[str, dict[str, object]] = {str(f["id"]): f for f in FIELDS}
FIELD_LABELS: dict[str, str] = {str(f["id"]): str(f["label"]) for f in FIELDS}


def assemble_prompt(fields: dict[str, str]) -> tuple[str, list[dict[str, object]]]:
    """Assemble populated fields into final prompt text and frontend section metadata."""
    sections: list[dict[str, object]] = []
    parts: list[str] = []

    for field in FIELDS:
        val = fields.get(str(field["id"]), "").strip()
        if not val:
            continue
        sections.append({
            "label": field["label"],
            "value": val,
            "color": field["color"],
            "surface": field["surface"],
        })
        parts.append(f"{field['label']}: {val}")

    return "\n\n".join(parts), sections