File size: 2,181 Bytes
1637cd5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
67
68
69
70
71
72
73
74
75
#!/usr/bin/env python3
"""
Test inline code handling
"""

import os
from dotenv import load_dotenv
from app import BasicAgent

load_dotenv()

def test_inline_code():
    """Test questions with inline code"""
    
    agent = BasicAgent()
    api_key = os.getenv("ANTHROPIC_API_KEY")
    if not api_key:
        print("Error: ANTHROPIC_API_KEY not found")
        return
    
    agent.set_api_key(api_key)
    
    # Test cases with inline code
    test_cases = [
        {
            "question": "What is the output of this Python code: print(sum([1, 2, 3, 4, 5]))",
            "expected": "15"
        },
        {
            "question": """What is the output of this code?
```python
x = 5
y = 3
print(x * y + 2)
```""",
            "expected": "17"
        },
        {
            "question": "In the attached Python code, I try to use the string method zfill. It does not work. Can you fix the problem for me and give me the only the complete corrected code?",
            "expected": "Unable to determine (no code provided)"
        },
        {
            "question": """Fix this code and give me only the complete corrected code:
```python
number = 42
# This line has an error
padded = number.zfill(5)
print(padded)
```""",
            "expected": "Should provide corrected code"
        }
    ]
    
    for i, test in enumerate(test_cases, 1):
        print(f"\nTest {i}:")
        print(f"Question: {test['question'][:100]}...")
        print(f"Expected: {test['expected']}")
        
        try:
            answer = agent(test['question'])
            print(f"Got: {answer}")
            
            # Check if code was detected and executed
            if "```" in test['question'] and "unable to determine" not in answer.lower():
                print("βœ… Code was detected and processed")
            elif "attached" in test['question'].lower() and "unable to determine" in answer.lower():
                print("βœ… Correctly identified missing attachment")
            else:
                print("❌ May need improvement")
                
        except Exception as e:
            print(f"Error: {e}")

if __name__ == "__main__":
    test_inline_code()