Spaces:
Running
Running
Download src/core/fields.py from ArielJoe/Prompt-Builder: direct link, hf CLI and curl.
- Browser
- Download file 2.3 kB
-
https://huggingface.co/spaces/ArielJoe/Prompt-Builder/resolve/main/src/core/fields.py
- Command line
-
hf download hf://spaces/ArielJoe/Prompt-Builder/src/core/fields.py
-
curl -L -o fields.py https://huggingface.co/spaces/ArielJoe/Prompt-Builder/resolve/main/src/core/fields.py
2.3 kB
| """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 | |