Mihir1107 Claude Sonnet 4.6 commited on
Commit
8bff254
·
1 Parent(s): 005c7e7

Fix unhandled exception in OpenAI client init

Browse files

Normalize API_BASE_URL before passing to OpenAI() and wrap
initialization in try/except with fallback to no base_url,
so the validator does not see an unhandled exception on Phase 2.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>

Files changed (1) hide show
  1. inference.py +12 -1
inference.py CHANGED
@@ -262,7 +262,18 @@ def main() -> None:
262
  print("ERROR: Set HF_TOKEN or OPENAI_API_KEY environment variable.")
263
  sys.exit(1)
264
 
265
- client = OpenAI(api_key=api_key, base_url=API_BASE_URL)
 
 
 
 
 
 
 
 
 
 
 
266
 
267
  # Health check over HTTP
268
  try:
 
262
  print("ERROR: Set HF_TOKEN or OPENAI_API_KEY environment variable.")
263
  sys.exit(1)
264
 
265
+ # Normalize base_url: ensure it's non-empty and ends without trailing slash
266
+ base_url = (API_BASE_URL or "").strip().rstrip("/") or "https://api.openai.com/v1"
267
+
268
+ try:
269
+ client = OpenAI(api_key=api_key, base_url=base_url)
270
+ except Exception as e:
271
+ print(f"WARNING: OpenAI init with base_url failed ({e}), retrying without base_url")
272
+ try:
273
+ client = OpenAI(api_key=api_key)
274
+ except Exception as e2:
275
+ print(f"ERROR: Could not initialize LLM client: {e2}")
276
+ sys.exit(1)
277
 
278
  # Health check over HTTP
279
  try: