""" Test script for Semantic Scholar Direct API integration """ import asyncio import os import sys from dotenv import load_dotenv # Load environment variables load_dotenv() # Add project root to path sys.path.insert(0, os.path.dirname(__file__)) from mcp_tools.scholar_tool import SemanticScholarTool from agents.research_agent import ResearchAgent async def test_scholar_tool(): """Test Semantic Scholar tool directly""" print("=" * 70) print("TEST 1: Semantic Scholar Tool Direct API") print("=" * 70) tool = SemanticScholarTool() # Test search print("\n๐Ÿ“ Testing search for '3I/ATLAS'...") papers = await tool.search_papers("3I/ATLAS", max_results=3) if papers: print(f"\nโœ… Success! Found {len(papers)} papers:") for i, paper in enumerate(papers, 1): print(f"\n{i}. {paper['title']}") print(f" Authors: {', '.join([a['name'] for a in paper.get('authors', [])[:3]])}") print(f" Year: {paper.get('year', 'N/A')}") print(f" Citations: {paper.get('citationCount', 0)}") if paper.get('abstract'): print(f" Abstract: {paper['abstract'][:150]}...") else: print("\nโŒ No papers found") await tool.disconnect() return len(papers) > 0 async def test_research_agent(): """Test ResearchAgent with Semantic Scholar""" print("\n" + "=" * 70) print("TEST 2: Research Agent with Semantic Scholar") print("=" * 70) agent = ResearchAgent() await agent.initialize() # Test search print("\n๐Ÿ“ Testing search for 'transformer neural networks'...") papers = await agent.search("transformer neural networks", max_results=3, source="scholar") if papers: print(f"\nโœ… Success! Found {len(papers)} papers:") for i, paper in enumerate(papers, 1): print(f"\n{i}. {paper['title']}") print(f" Year: {paper.get('year', 'N/A')}") print(f" Citations: {paper.get('citationCount', 0)}") else: print("\nโŒ No papers found") await agent.cleanup() return len(papers) > 0 async def main(): """Run all tests""" print("\n๐Ÿงช Starting Semantic Scholar API Tests\n") # Check API key api_key = os.getenv("SEMANTIC_SCHOLAR_API") if api_key: print(f"โœ“ API Key found: {api_key[:10]}...") else: print("โš ๏ธ No API key found - using public rate-limited access") print() # Run tests test1_passed = await test_scholar_tool() test2_passed = await test_research_agent() # Summary print("\n" + "=" * 70) print("TEST SUMMARY") print("=" * 70) print(f"Test 1 (Scholar Tool): {'โœ… PASSED' if test1_passed else 'โŒ FAILED'}") print(f"Test 2 (Research Agent): {'โœ… PASSED' if test2_passed else 'โŒ FAILED'}") print("=" * 70) if test1_passed and test2_passed: print("\n๐ŸŽ‰ All tests passed! Semantic Scholar API is working!") else: print("\nโš ๏ธ Some tests failed - check the output above") if __name__ == "__main__": asyncio.run(main())