raj999 commited on
Commit
ad16e06
·
1 Parent(s): d50f94e
Files changed (2) hide show
  1. llm/client.py +2 -2
  2. scripts/openai_smoke.py +37 -0
llm/client.py CHANGED
@@ -52,8 +52,8 @@ class OpenAIClient:
52
  except Exception as exc: # pragma: no cover - network call
53
  last_error = exc
54
  if _is_rate_limit_error(exc):
55
- # User indicated ~3 req/min; wait ~20s before retrying.
56
- wait_time = max(delay, 20.0)
57
  logger.warning(
58
  "OpenAI rate limit encountered (attempt %s). Waiting %.1fs",
59
  attempt + 1,
 
52
  except Exception as exc: # pragma: no cover - network call
53
  last_error = exc
54
  if _is_rate_limit_error(exc):
55
+ # User indicated ~3 req/min; wait a full 60s to be safe.
56
+ wait_time = 60.0
57
  logger.warning(
58
  "OpenAI rate limit encountered (attempt %s). Waiting %.1fs",
59
  attempt + 1,
scripts/openai_smoke.py ADDED
@@ -0,0 +1,37 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Minimal one-call smoke test to verify OpenAI API access.
3
+
4
+ Usage:
5
+ export OPENAI_API_KEY=your_key
6
+ uv run python scripts/openai_smoke.py --model gpt-4o-mini
7
+ """
8
+ import argparse
9
+ import os
10
+ import sys
11
+ from pathlib import Path
12
+
13
+ # Ensure repository root is on sys.path for local execution.
14
+ ROOT = Path(__file__).resolve().parents[1]
15
+ if str(ROOT) not in sys.path:
16
+ sys.path.insert(0, str(ROOT))
17
+
18
+ from llm.client import OpenAIClient
19
+
20
+
21
+ def main():
22
+ parser = argparse.ArgumentParser(description="OpenAI API smoke test (single call).")
23
+ parser.add_argument("--model", default="gpt-4o-mini", help="Model name to test.")
24
+ args = parser.parse_args()
25
+
26
+ api_key = os.getenv("OPENAI_API_KEY")
27
+ if not api_key:
28
+ raise SystemExit("Set OPENAI_API_KEY before running this script.")
29
+
30
+ client = OpenAIClient(api_key=api_key, model=args.model)
31
+ prompt = "Say a short greeting with exactly 3 words."
32
+ resp = client.chat(prompt, max_retries=1)
33
+ print("Response:", resp)
34
+
35
+
36
+ if __name__ == "__main__":
37
+ main()