|
| 1 | +# Phase 1 — CLDR Ticket Validator (Reader · Prompt Preparer · Prompt → LLM) |
| 2 | + |
| 3 | +This folder contains the Phase-1 tools used to **read a CLDR JIRA ticket**, **prepare a short LLM prompt**, and **post that prompt to an LLM** to get a JSON triage result. |
| 4 | + |
| 5 | +Path: `tools/scripts/llm/ticket_valdator/` |
| 6 | + |
| 7 | +--- |
| 8 | + |
| 9 | +## Files |
| 10 | + |
| 11 | +* `cldr_ticket_reader.py` — reads a JIRA ticket and prints a human-readable report |
| 12 | + |
| 13 | + * Also exposes `get_ticket_details_string(ticket_key, jira_client)` for other tools. |
| 14 | +* `cldr_dynamic_prompter.py` — **prepares** a concise, ticket-specific prompt |
| 15 | + |
| 16 | + * CLI prints the prompt; also exposes `make_prompt(ticket_key, category=None, auto_category=False)`. |
| 17 | +* `cldr_prompt_to_llm.py` — **posts** the prepared prompt to OpenAI and prints the model’s reply (JSON). |
| 18 | + |
| 19 | +> Keep it simple: three files, three responsibilities — **reader → prompt → LLM**. |
| 20 | +
|
| 21 | +--- |
| 22 | + |
| 23 | +## Requirements |
| 24 | + |
| 25 | +* Python 3.9+ |
| 26 | +* Packages: |
| 27 | + |
| 28 | + ```bash |
| 29 | + pip install jira "openai>=1.0.0" |
| 30 | + ``` |
| 31 | +* Access to the CLDR JIRA (`https://unicode-org.atlassian.net`) |
| 32 | +* (For posting to an LLM) An OpenAI API key |
| 33 | + |
| 34 | +--- |
| 35 | + |
| 36 | +## Quick Setup |
| 37 | + |
| 38 | +Open each script and paste credentials as indicated at the top (you can use env vars if you prefer; avoid committing real keys): |
| 39 | + |
| 40 | +* **JIRA** |
| 41 | + `JIRA_SERVER`, `JIRA_USER_EMAIL`, `JIRA_API_TOKEN` |
| 42 | +* **OpenAI** (only needed for auto-category in the prompter, and for the poster) |
| 43 | + `OPENAI_API_KEY` (and optionally `OPENAI_MODEL`, default `gpt-4o-mini`) |
| 44 | + |
| 45 | +--- |
| 46 | + |
| 47 | +## Usage |
| 48 | + |
| 49 | +### 1) Read a ticket (human-readable report) |
| 50 | + |
| 51 | +```bash |
| 52 | +python cldr_ticket_reader.py CLDR-18761 |
| 53 | +``` |
| 54 | + |
| 55 | +### 2) Prepare a prompt (print to stdout) |
| 56 | + |
| 57 | +Default (Phase-1 triage, no category forced): |
| 58 | + |
| 59 | +```bash |
| 60 | +python cldr_dynamic_prompter.py CLDR-18761 |
| 61 | +``` |
| 62 | + |
| 63 | +Force a category (adds targeted questions): |
| 64 | + |
| 65 | +```bash |
| 66 | +python cldr_dynamic_prompter.py CLDR-18761 --category "Documentation Issue" |
| 67 | +``` |
| 68 | + |
| 69 | +Auto-pick a category (one lightweight LLM call): |
| 70 | + |
| 71 | +```bash |
| 72 | +python cldr_dynamic_prompter.py CLDR-18761 --auto-category |
| 73 | +``` |
| 74 | + |
| 75 | +> Programmatic use in other tools: |
| 76 | +> |
| 77 | +> ```python |
| 78 | +> from cldr_dynamic_prompter import make_prompt |
| 79 | +> prompt = make_prompt("CLDR-18761", category="Software Bug") # or auto_category=True |
| 80 | +> ``` |
| 81 | +
|
| 82 | +### 3) Post the prompt to OpenAI (get JSON) |
| 83 | +
|
| 84 | +```bash |
| 85 | +python cldr_prompt_to_llm.py CLDR-18761 |
| 86 | +# or |
| 87 | +python cldr_prompt_to_llm.py CLDR-18761 --category "Feature Request" |
| 88 | +# or |
| 89 | +python cldr_prompt_to_llm.py CLDR-18761 --auto-category --model gpt-4o-mini |
| 90 | +``` |
| 91 | +
|
| 92 | +The script prints only the model reply; it also tries to trim to the first valid `{ ... }` block if extra text appears. |
| 93 | + |
| 94 | +--- |
| 95 | + |
| 96 | +## Editing the Prompt (user-friendly) |
| 97 | + |
| 98 | +Most users will only edit these two functions in **`cldr_dynamic_prompter.py`**: |
| 99 | + |
| 100 | +* `build_triage_prompt(data)` — the default Phase-1 JSON classification prompt |
| 101 | +* `build_topic_prompt(category, topic, data)` — short follow-ups when a category is chosen |
| 102 | + |
| 103 | +**Tip:** Keep descriptions short; Title/Description appear once. If you need a different tone, edit just these functions. (In a later phase we can move the template into a separate `templates/` file and add a `--template` flag.) |
| 104 | + |
| 105 | +--- |
| 106 | + |
| 107 | +## Expected JSON (Phase-1) |
| 108 | + |
| 109 | +The LLM output should match keys like: |
| 110 | + |
| 111 | +```json |
| 112 | +{ |
| 113 | + "spam": false, |
| 114 | + "outOfScopeForCLDR": false, |
| 115 | + "needsEngineeringTC": true, |
| 116 | + "needsLanguageSpecialist": false, |
| 117 | + "stretchValidation": { "likelyTrue": true, "evidenceLinks": [] }, |
| 118 | + "changeTaskTypeToFixInSurveyTool": true, |
| 119 | + "notes": "1–3 brief sentences" |
| 120 | +} |
| 121 | +``` |
| 122 | + |
| 123 | +--- |
| 124 | + |
| 125 | +## Troubleshooting |
| 126 | + |
| 127 | +* **401 / auth error:** Recheck JIRA email/token; ensure your account can read the ticket. |
| 128 | +* **OpenAI call failed:** Paste a valid `OPENAI_API_KEY` or remove `--auto-category` and skip the poster tool. |
| 129 | +* **Messy model output:** `cldr_prompt_to_llm.py` already extracts the first JSON block; tighten your prompt if needed. |
| 130 | +* **Classification feels generic:** Use `--category` to add targeted questions or refine `build_topic_prompt`. |
| 131 | + |
| 132 | +--- |
| 133 | + |
| 134 | +## Security |
| 135 | + |
| 136 | +* **Do not commit real tokens/API keys** to the repo. |
| 137 | +* Prefer environment variables or a local config file ignored by git. |
| 138 | +* Rotate any tokens that may have been shared accidentally. |
| 139 | + |
| 140 | +--- |
| 141 | + |
| 142 | +## Summary |
| 143 | + |
| 144 | +Phase-1 tools are ready: |
| 145 | + |
| 146 | +1. **Reader**: get ticket details |
| 147 | +2. **Prompter**: print a concise, LLM-ready prompt |
| 148 | +3. **Poster**: send to OpenAI and print JSON |
| 149 | + |
| 150 | +Small, composable, and easy to tweak. |
0 commit comments