|
| 1 | +# Opik integration |
| 2 | + |
| 3 | +We trace the FAQ automation with Opik and score it with Opik experiments. |
| 4 | +The local eval framework (`faq_automation/evals/`) stays the source of truth; |
| 5 | +Opik mirrors it. To go back, delete the Opik files and env vars below. |
| 6 | + |
| 7 | +## Platforms |
| 8 | + |
| 9 | +| | Opik Cloud (shared, Friday demos) | Local (private dev) | |
| 10 | +|---|---|---| |
| 11 | +| URL | `https://www.comet.com/opik/api` | `http://localhost:5173/api` (`cd ../opik && ./opik.sh`) | |
| 12 | +| Workspace | `default` | `default` | |
| 13 | +| Auth | `OPIK_API_KEY` (GitHub secret in CI, never in git) | none | |
| 14 | +| Automation project | `faq-automation-ci` | `faq-automation` | |
| 15 | +| Assistant project | `faq-assistant-lambda` | `faq-assistant` | |
| 16 | + |
| 17 | +## Tracing |
| 18 | + |
| 19 | +`faq_automation/rag_agent.py` (full SDK, 2 lines + 1 decorator): |
| 20 | + |
| 21 | +```python |
| 22 | +from opik import track |
| 23 | +from opik.integrations.openai import track_openai |
| 24 | + |
| 25 | +self.openai_client = track_openai(OpenAI(api_key=openai_api_key)) |
| 26 | + |
| 27 | +@track |
| 28 | +def process_proposal(self, ...): ... |
| 29 | +``` |
| 30 | + |
| 31 | +The Slack worker (`faq-assistant`, separate repo) intentionally does NOT ship |
| 32 | +the SDK — Lambda stays zero-dependency. It uses a ~140-line stdlib-only |
| 33 | +`@track` drop-in (`opik_lite.py`) that POSTs one trace per answer. Same |
| 34 | +annotation, one-line import swap. |
| 35 | + |
| 36 | +## Evals on Opik |
| 37 | + |
| 38 | +`faq_automation/evals/opik_eval.py` (additive port, same cases and check |
| 39 | +predicates as `runner.py`): |
| 40 | + |
| 41 | +```bash |
| 42 | +source .env # OPIK_API_KEY |
| 43 | +# push cases once: |
| 44 | +OPIK_URL_OVERRIDE=https://www.comet.com/opik/api OPIK_WORKSPACE=default \ |
| 45 | + OPIK_PROJECT_NAME=faq-automation-ci \ |
| 46 | + uv run --project faq_automation python -m faq_automation.evals.opik_eval --push-dataset |
| 47 | +# before/after (deterministic action_match + placement_match, no judge cost): |
| 48 | +uv run --project faq_automation python -m faq_automation.evals.opik_eval \ |
| 49 | + --experiment friday-before --num-results 1 |
| 50 | +uv run --project faq_automation python -m faq_automation.evals.opik_eval \ |
| 51 | + --experiment friday-after --num-results 5 |
| 52 | +``` |
| 53 | + |
| 54 | +## Prompts in Opik |
| 55 | + |
| 56 | +We do NOT load prompts from Opik — `rag_agent.SYSTEM_PROMPT` and |
| 57 | +`PROMPT_TEMPLATE` remain the single source of truth. We mirror them into the |
| 58 | +Prompt Library so every version sits next to the traces/experiments that used |
| 59 | +it. Re-running with unchanged templates creates no new version: |
| 60 | + |
| 61 | +```bash |
| 62 | +OPIK_URL_OVERRIDE=https://www.comet.com/opik/api OPIK_WORKSPACE=default \ |
| 63 | + OPIK_PROJECT_NAME=faq-automation-ci \ |
| 64 | + uv run --project faq_automation python scripts/push_prompts_to_opik.py |
| 65 | +``` |
| 66 | + |
| 67 | +Library entries: `faq-triage-system`, `faq-triage-user-template` |
| 68 | +(metadata records the source symbol and the model from `DEFAULT_MODEL`). |
| 69 | + |
| 70 | +## History backfill |
| 71 | + |
| 72 | +`scripts/backfill_opik_history.py` logs past `faq-proposal` issues as |
| 73 | +`faq-proposal-triage` traces with real timestamps: input = original issue + |
| 74 | +regenerated retrieval context, output = the actual historical decision from |
| 75 | +the bot PR or close comment (or MANUAL). `--dry-run` first, `--limit N` to |
| 76 | +bound it. |
| 77 | + |
| 78 | +## CI wiring |
| 79 | + |
| 80 | +`.github/workflows/faq-automation.yml` ("Process FAQ with AI" step) sets |
| 81 | +`OPIK_URL_OVERRIDE` / `OPIK_WORKSPACE` / `OPIK_PROJECT_NAME=faq-automation-ci` |
| 82 | +and `OPIK_API_KEY` from secrets. Without a key the SDK degrades to no-op — |
| 83 | +automation never breaks because of tracing. |
0 commit comments