File size: 2,330 Bytes
9d29c62
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
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())