|
|
|
|
|
""" |
|
|
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 = [ |
|
|
{ |
|
|
"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}") |
|
|
|
|
|
|
|
|
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() |