File size: 2,084 Bytes
1a28176
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""One live end-to-end check of LLM item generation (ITEM_GENERATION.md).

Calls the real provider (whichever key is configured - Groq or Anthropic),
prints the drafted items, and exits non-zero on failure. Run it once after
setting a key, and again after any provider/model/prompt change:

    cd backend && ../scripts/smoke_test_generation.sh   # or:
    cd backend && GROQ_API_KEY=... .venv/bin/python ../scripts/smoke_test_generation.py
"""

import sys
from pathlib import Path

sys.path.insert(0, str(Path(__file__).resolve().parent.parent / "backend"))

from app import item_generation  # noqa: E402


def main() -> int:
    p = item_generation.provider()
    if not p:
        print("FAIL: no GROQ_API_KEY or ANTHROPIC_API_KEY set.")
        return 1
    print(f"provider={p} model={item_generation.generation_model()} "
          f"prompt_version={item_generation.PROMPT_VERSION}")
    try:
        draft = item_generation.generate_items(
            name="Gratitude",
            description=(
                "The tendency to notice and appreciate the positive things in "
                "one's life, and to feel thankful for what one has and for "
                "what others do."
            ),
            n_items=10,
        )
    except item_generation.GenerationError as exc:
        print(f"FAIL ({exc.status_code}): {exc}")
        return 1
    print(f"\n{len(draft.items)} items:")
    for i, item in enumerate(draft.items, 1):
        print(f"  {i:2}. {item}")
    if draft.notes:
        print(f"\nnotes: {draft.notes}")
    # Cheap rule checks (the human review still judges quality):
    problems = []
    for item in draft.items:
        if not item.lower().startswith(("i ", "i'", "my ", "when ")):
            problems.append(f"not first-person? {item!r}")
        if "?" in item:
            problems.append(f"question: {item!r}")
    if problems:
        print("\nrule warnings (review, not necessarily failures):")
        for w in problems:
            print(f"  - {w}")
    print("\nOK")
    return 0


if __name__ == "__main__":
    sys.exit(main())