import asyncio import os import sys import json from dotenv import load_dotenv # Add parent directory to path so we can import modules sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) from buddy_math_server.orchestrator import BuddyOrchestrator # Mock image data (1x1 pixel transparent gif) MOCK_IMAGE = b'GIF89a\x01\x00\x01\x00\x80\x00\x00\x00\x00\x00\xff\xff\xff!\xf9\x04\x01\x00\x00\x00\x00,\x00\x00\x00\x00\x01\x00\x01\x00\x00\x02\x01D\x00;' async def test_pipeline(): print("๐Ÿš€ Starting Backend Pipeline Verification...") # Load env load_dotenv() if not os.getenv("GOOGLE_API_KEY"): print("โŒ GOOGLE_API_KEY not found in environment!") return try: # Initialize Orchestrator print("๐Ÿ”น Initializing BuddyOrchestrator...") orchestrator = BuddyOrchestrator() # Test Case 1: Geometry Problem (Should trigger Image path) print("\n๐Ÿงช Test Case 1: Geometry Problem with Image") problem_text = """ ื‘ืžืฉื•ืœืฉ ื™ืฉืจ ื–ื•ื•ื™ืช ABC, ื”ื™ืชืจ ื”ื•ื 10 ืก"ืž. ื. ืžืฆื ืืช ืื•ืจืš ื”ื ื™ืฆื‘ ืื ื”ื ื™ืฆื‘ ื”ืฉื ื™ ื”ื•ื 6. ื‘. ื—ืฉื‘ ืืช ืฉื˜ื— ื”ืžืฉื•ืœืฉ. """ # Simulate the call from main.py -> solve_problem # passing image_data as kwargs print("๐Ÿ”น Calling solve_problem...") result = await orchestrator.solve_problem( problem_text=problem_text, grade="10", student_name="TestUser", student_gender="M", image_data=MOCK_IMAGE ) print("\nโœ… Pipeline Execution Successful!") print("๐Ÿ“„ Result Keys:", result.keys()) if "sections" in result: print(f"โœ… Generated {len(result['sections'])} sections") for s in result['sections']: print(f" - {s.get('section_title')}") else: print("โš ๏ธ No sections found in result (might be legacy fallback?)") print("Result dump:", json.dumps(result, ensure_ascii=False)[:200] + "...") except Exception as e: print(f"\nโŒ Pipeline Verified FAILED: {e}") import traceback traceback.print_exc() if __name__ == "__main__": asyncio.run(test_pipeline())