File size: 1,027 Bytes
ad16e06
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
"""
Minimal one-call smoke test to verify OpenAI API access.

Usage:
  export OPENAI_API_KEY=your_key
  uv run python scripts/openai_smoke.py --model gpt-4o-mini
"""
import argparse
import os
import sys
from pathlib import Path

# Ensure repository root is on sys.path for local execution.
ROOT = Path(__file__).resolve().parents[1]
if str(ROOT) not in sys.path:
    sys.path.insert(0, str(ROOT))

from llm.client import OpenAIClient


def main():
    parser = argparse.ArgumentParser(description="OpenAI API smoke test (single call).")
    parser.add_argument("--model", default="gpt-4o-mini", help="Model name to test.")
    args = parser.parse_args()

    api_key = os.getenv("OPENAI_API_KEY")
    if not api_key:
        raise SystemExit("Set OPENAI_API_KEY before running this script.")

    client = OpenAIClient(api_key=api_key, model=args.model)
    prompt = "Say a short greeting with exactly 3 words."
    resp = client.chat(prompt, max_retries=1)
    print("Response:", resp)


if __name__ == "__main__":
    main()