|
|
""" |
|
|
Test script for Semantic Scholar Direct API integration |
|
|
""" |
|
|
|
|
|
import asyncio |
|
|
import os |
|
|
import sys |
|
|
from dotenv import load_dotenv |
|
|
|
|
|
|
|
|
load_dotenv() |
|
|
|
|
|
|
|
|
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() |
|
|
|
|
|
|
|
|
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() |
|
|
|
|
|
|
|
|
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") |
|
|
|
|
|
|
|
|
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() |
|
|
|
|
|
|
|
|
test1_passed = await test_scholar_tool() |
|
|
test2_passed = await test_research_agent() |
|
|
|
|
|
|
|
|
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()) |
|
|
|