Download test_fixed_agent.py from AbdullahIsaMarkus/Final_Assignment_Agent: direct link, hf CLI and curl.
- Browser
- Download file 4.96 kB
-
https://huggingface.co/spaces/AbdullahIsaMarkus/Final_Assignment_Agent/resolve/main/test_fixed_agent.py
- Command line
-
hf download hf://spaces/AbdullahIsaMarkus/Final_Assignment_Agent/test_fixed_agent.py
-
curl -L -o test_fixed_agent.py https://huggingface.co/spaces/AbdullahIsaMarkus/Final_Assignment_Agent/resolve/main/test_fixed_agent.py
4.96 kB
| #!/usr/bin/env python3 | |
| """ | |
| Test script to verify the fixes for list handling and DuckDuckGo integration | |
| """ | |
| import os | |
| import sys | |
| # Add current directory to path | |
| sys.path.insert(0, os.path.dirname(os.path.abspath(__file__))) | |
| # Set test API key | |
| os.environ["ANTHROPIC_API_KEY"] = "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" | |
| def test_clean_answer_with_lists(): | |
| """Test that _clean_answer now handles lists properly""" | |
| print("=" * 60) | |
| print("Testing _clean_answer with different input types") | |
| print("=" * 60) | |
| try: | |
| from app import LangGraphAgent | |
| # Create a test agent | |
| agent = LangGraphAgent(os.environ["ANTHROPIC_API_KEY"]) | |
| # Test cases that previously caused errors | |
| test_inputs = [ | |
| "Normal string answer", | |
| ["This", "was", "a", "list"], # This caused the error! | |
| {"answer": "dict input"}, | |
| 42, | |
| ["The answer is:", "42"], | |
| None, | |
| ] | |
| for test_input in test_inputs: | |
| print(f"\nInput: {test_input} (type: {type(test_input)})") | |
| try: | |
| result = agent._clean_answer(test_input) | |
| print(f"β Success: '{result}'") | |
| except AttributeError as e: | |
| print(f"β AttributeError: {e}") | |
| except Exception as e: | |
| print(f"β Other error: {type(e).__name__}: {e}") | |
| except Exception as e: | |
| print(f"Failed to import or create agent: {e}") | |
| def test_web_search_without_serpapi(): | |
| """Test that web search works with DuckDuckGo""" | |
| print("\n" + "=" * 60) | |
| print("Testing DuckDuckGo web search (no API key needed)") | |
| print("=" * 60) | |
| try: | |
| from app import web_search | |
| # Test queries | |
| queries = [ | |
| "Python programming", | |
| "Current president of France", | |
| "What is 2 + 2", | |
| ] | |
| for query in queries: | |
| print(f"\nSearching for: '{query}'") | |
| try: | |
| result = web_search(query, max_results=3) | |
| print(f"β Search successful!") | |
| print(f"Result preview: {result[:200]}...") | |
| except Exception as e: | |
| print(f"β Search failed: {e}") | |
| except Exception as e: | |
| print(f"Failed to import web_search: {e}") | |
| def test_tool_input_handling(): | |
| """Test that all tools handle list inputs""" | |
| print("\n" + "=" * 60) | |
| print("Testing tool input handling") | |
| print("=" * 60) | |
| try: | |
| from app import calculator, python_executor, analyze_reversed_text | |
| # Test with list inputs | |
| test_cases = [ | |
| ("calculator", calculator, ["2", "+", "2"]), | |
| ("python_executor", python_executor, ["print('Hello')", "print('World')"]), | |
| ("analyze_reversed_text", analyze_reversed_text, ["hello", "world"]), | |
| ] | |
| for tool_name, tool_func, list_input in test_cases: | |
| print(f"\nTesting {tool_name} with list input: {list_input}") | |
| try: | |
| result = tool_func(list_input) | |
| print(f"β Success: {result[:100]}...") | |
| except AttributeError as e: | |
| print(f"β AttributeError: {e}") | |
| except Exception as e: | |
| print(f"β Other error: {type(e).__name__}: {e}") | |
| except Exception as e: | |
| print(f"Failed to import tools: {e}") | |
| def test_gaia_question(): | |
| """Test with an actual GAIA-like question""" | |
| print("\n" + "=" * 60) | |
| print("Testing with GAIA-like question") | |
| print("=" * 60) | |
| try: | |
| from app import BasicAgent | |
| # Create agent | |
| agent = BasicAgent() | |
| if agent.agent is None: | |
| agent.set_api_key(os.environ["ANTHROPIC_API_KEY"]) | |
| # Test question | |
| question = "What is the capital of France?" | |
| print(f"Question: {question}") | |
| print("Running agent...") | |
| try: | |
| answer = agent(question) | |
| print(f"β Answer: {answer}") | |
| except Exception as e: | |
| print(f"β Error: {type(e).__name__}: {e}") | |
| except Exception as e: | |
| print(f"Failed to test agent: {e}") | |
| if __name__ == "__main__": | |
| print("GAIA Agent Fix Verification Tests") | |
| print("=" * 80) | |
| # Run all tests | |
| test_clean_answer_with_lists() | |
| test_web_search_without_serpapi() | |
| test_tool_input_handling() | |
| test_gaia_question() | |
| print("\n" + "=" * 80) | |
| print("Test Summary:") | |
| print("1. _clean_answer should now handle lists without 'lower' error") | |
| print("2. Web search should work with DuckDuckGo (no API key)") | |
| print("3. All tools should handle list inputs gracefully") | |
| print("4. Agent should provide clean, concise answers") |