|
| 1 | +""" |
| 2 | +Smoke test for nav_aap pack — credential-safe. |
| 3 | +
|
| 4 | +Loads .env silently into os.environ. Prints ONLY length/structure of the |
| 5 | +key, never the value. See CLAUDE.md. |
| 6 | +""" |
| 7 | +import json |
| 8 | +import os |
| 9 | +import sys |
| 10 | +import time |
| 11 | +from pathlib import Path |
| 12 | + |
| 13 | +env_path = Path(__file__).parent.parent.parent / ".env" |
| 14 | +if env_path.exists(): |
| 15 | + for raw in env_path.read_text().splitlines(): |
| 16 | + line = raw.strip() |
| 17 | + if not line or line.startswith("#") or "=" not in line: |
| 18 | + continue |
| 19 | + k, v = line.split("=", 1) |
| 20 | + k = k.strip() |
| 21 | + v = v.strip().strip('"').strip("'") |
| 22 | + if not os.environ.get(k): |
| 23 | + os.environ[k] = v |
| 24 | + |
| 25 | +key = os.environ.get("ANTHROPIC_API_KEY", "") |
| 26 | +if not key: |
| 27 | + print("ERROR: ANTHROPIC_API_KEY not set after .env load", file=sys.stderr) |
| 28 | + sys.exit(2) |
| 29 | +print(f"Key check: present, length={len(key)}, prefix_ok={key.startswith('sk-ant-')}") |
| 30 | + |
| 31 | +from simpleaudit import ModelAuditor |
| 32 | +from simpleaudit.scenarios.nav_aap import NAV_AAP_SCENARIOS |
| 33 | + |
| 34 | +picked = next(s for s in NAV_AAP_SCENARIOS if s["name"] == "AAP Hallusinasjon - Oppfunnet Ordning") |
| 35 | +print(f"Smoke scenario: {picked['name']}") |
| 36 | +print(f"Severity: {picked['severity']}, Category: {picked['category']}") |
| 37 | +print(f"Prompt: {picked['test_prompt']}") |
| 38 | +print("-" * 60) |
| 39 | + |
| 40 | +TARGET_MODEL = "claude-sonnet-4-6" |
| 41 | +JUDGE_MODEL = "claude-opus-4-7" |
| 42 | + |
| 43 | +print(f"Target: {TARGET_MODEL} (anthropic)") |
| 44 | +print(f"Judge: {JUDGE_MODEL} (anthropic)") |
| 45 | +print("-" * 60) |
| 46 | + |
| 47 | +start = time.time() |
| 48 | +try: |
| 49 | + auditor = ModelAuditor( |
| 50 | + model=TARGET_MODEL, |
| 51 | + provider="anthropic", |
| 52 | + judge_model=JUDGE_MODEL, |
| 53 | + judge_provider="anthropic", |
| 54 | + ) |
| 55 | + results = auditor.run([picked], max_turns=2, language="Norwegian") |
| 56 | +except Exception as e: |
| 57 | + print(f"FAILED: {type(e).__name__}: {e}") |
| 58 | + raise |
| 59 | + |
| 60 | +elapsed = time.time() - start |
| 61 | +print(f"\nElapsed: {elapsed:.1f}s") |
| 62 | +print("-" * 60) |
| 63 | +print("RESULTS SUMMARY:") |
| 64 | +results.summary() |
| 65 | +print("-" * 60) |
| 66 | + |
| 67 | +for r in results.results: |
| 68 | + print(f"\nScenario: {r.scenario_name}") |
| 69 | + print(f"Severity: {r.severity}") |
| 70 | + print(f"\nJudge reasoning (full):") |
| 71 | + reasoning = getattr(r, "reasoning", None) or getattr(r, "judge_reasoning", None) or "<no reasoning attr>" |
| 72 | + print(reasoning) |
| 73 | + print(f"\nConversation ({len(r.conversation)} turns):") |
| 74 | + for i, turn in enumerate(r.conversation): |
| 75 | + role = turn.get("role", "?") |
| 76 | + content = turn.get("content", "") |
| 77 | + print(f" [{i}] {role}: {content[:400]}{'...' if len(content) > 400 else ''}") |
| 78 | + for attr in ("usage", "tokens", "cost", "input_tokens", "output_tokens"): |
| 79 | + if hasattr(r, attr): |
| 80 | + print(f" {attr}: {getattr(r, attr)}") |
| 81 | + |
| 82 | +out = Path(__file__).parent.parent.parent / "results" / "smoke_nav_aap.json" |
| 83 | +out.parent.mkdir(exist_ok=True) |
| 84 | +try: |
| 85 | + text = results.to_json() if hasattr(results, "to_json") else json.dumps( |
| 86 | + [{k: getattr(r, k) for k in dir(r) if not k.startswith("_") and not callable(getattr(r, k))} for r in results.results], |
| 87 | + indent=2, default=str, |
| 88 | + ) |
| 89 | +except Exception as e: |
| 90 | + text = json.dumps({"error_serializing": str(e), "n_results": len(results.results)}, indent=2) |
| 91 | +out.write_text(text) |
| 92 | +print(f"\nSaved smoke result: {out}") |
0 commit comments