File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1111
1212load_dotenv ()
1313
14+ # Track missing dependencies so we don't call sys.exit at import time.
15+ MISSING_OPENAI_API_KEY = False
16+ MISSING_PILLOW = False
17+
1418# Check environment
1519openai_key = os .getenv ("OPENAI_API_KEY" )
1620if not openai_key :
1721 print ("❌ OPENAI_API_KEY not found in environment" )
1822 print (" Set it in .env or export OPENAI_API_KEY=your_key" )
19- sys . exit ( 1 )
20-
21- print ("✅ OPENAI_API_KEY found" )
22- print ()
23+ MISSING_OPENAI_API_KEY = True
24+ else :
25+ print ("✅ OPENAI_API_KEY found" )
26+ print ()
2327
2428# Import pydantic-ai components (matching agent.py pattern)
2529from pydantic_ai import Agent
@@ -58,10 +62,15 @@ class VisionTestResponse(BaseModel):
5862 print (f"✅ Test image created: { test_image_path } ({ len (PNG_1x1_RED )} bytes)" )
5963except ImportError :
6064 print ("❌ PIL/Pillow not installed. Install with: pip install Pillow" )
61- sys . exit ( 1 )
65+ MISSING_PILLOW = True
6266
6367print ()
6468
69+ if __name__ == "__main__" :
70+ # When run as a script, exit with a non-zero status if required dependencies are missing.
71+ if MISSING_OPENAI_API_KEY or MISSING_PILLOW :
72+ sys .exit (1 )
73+
6574# Create OpenAI provider and model (matching agent.py)
6675print ("🔄 Creating OpenAI gpt-4o model client..." )
6776provider = OpenAIProvider (api_key = openai_key )
You can’t perform that action at this time.
0 commit comments