File size: 1,821 Bytes
3e6b9d2
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
#!/usr/bin/env python3
"""Test script for PydanticAI integration."""

import asyncio
import sys
from pydanticai_app.agents import finance_agent
from pydanticai_app.utils import extract_answer_from_reasoning, extract_key_terms


async def test_finance_agent():
    """Test the finance agent."""
    print("=" * 70)
    print("Testing PydanticAI Finance Agent")
    print("=" * 70)
    print()
    
    test_questions = [
        "Qu'est-ce qu'une obligation?",
        "Expliquez le concept de date de valeur.",
        "Qu'est-ce que le CAC 40?",
    ]
    
    for i, question in enumerate(test_questions, 1):
        print(f"[{i}/{len(test_questions)}] Question: {question}")
        print("-" * 70)
        
        try:
            # Run agent
            result = await finance_agent.run(question)
            
            # Get raw response
            raw_response = result.output if hasattr(result, 'output') else str(result)
            
            # Extract answer from reasoning tags
            clean_answer = extract_answer_from_reasoning(str(raw_response))
            
            # Extract key terms
            key_terms = extract_key_terms(clean_answer)
            
            print(f"βœ… Response received")
            print(f"Answer length: {len(clean_answer)} chars")
            print(f"Key terms: {key_terms[:5]}")
            print(f"Answer preview: {clean_answer[:200]}...")
            print()
            
        except Exception as e:
            print(f"❌ Error: {e}")
            import traceback
            traceback.print_exc()
            print()
            return False
    
    print("=" * 70)
    print("βœ… All tests passed!")
    print("=" * 70)
    return True


if __name__ == "__main__":
    success = asyncio.run(test_finance_agent())
    sys.exit(0 if success else 1)