Download test_tools_interactive.py from polyHedra/PolyHedra: direct link, hf CLI and curl.
- Browser
- Download file 6.55 kB
-
https://huggingface.co/spaces/polyHedra/PolyHedra/resolve/main/test_tools_interactive.py
- Command line
-
hf download hf://spaces/polyHedra/PolyHedra/test_tools_interactive.py
-
curl -L -o test_tools_interactive.py https://huggingface.co/spaces/polyHedra/PolyHedra/resolve/main/test_tools_interactive.py
6.55 kB
| """Interactive Test for Polyhedra MCP Tools""" | |
| import asyncio | |
| from pathlib import Path | |
| from polyhedra.services.semantic_scholar import SemanticScholarService | |
| from polyhedra.services.citation_manager import CitationManager | |
| from polyhedra.services.context_manager import ContextManager | |
| from polyhedra.services.rag_service import RAGService | |
| from polyhedra.services.project_initializer import ProjectInitializer | |
| async def test_search_papers(): | |
| """Test 1: Search for papers""" | |
| print("\n" + "="*80) | |
| print("π§ͺ TEST 1: Search Papers") | |
| print("="*80) | |
| service = SemanticScholarService() | |
| query = "attention mechanism transformers" | |
| print(f"π Searching for: '{query}'") | |
| papers = await service.search(query=query, limit=3) | |
| print(f"β 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):,}") | |
| if paper.get('paperId'): | |
| print(f" ID: {paper['paperId']}") | |
| return papers[0] if papers else None | |
| async def test_get_paper(paper_id: str): | |
| """Test 2: Get detailed paper information""" | |
| print("\n" + "="*80) | |
| print("π§ͺ TEST 2: Get Paper Details") | |
| print("="*80) | |
| service = SemanticScholarService() | |
| print(f"π Fetching details for paper ID: {paper_id}") | |
| paper = await service.get_paper(paper_id) | |
| print(f"β Paper retrieved:") | |
| print(f" Title: {paper['title']}") | |
| print(f" Year: {paper.get('year', 'N/A')}") | |
| print(f" Authors: {', '.join(paper.get('authors', [])[:3])}") | |
| print(f" Citations: {paper.get('citationCount', 0):,}") | |
| if paper.get('abstract'): | |
| abstract = paper['abstract'][:200] + "..." if len(paper.get('abstract', '')) > 200 else paper.get('abstract', '') | |
| print(f" Abstract: {abstract}") | |
| return paper | |
| async def test_citation_manager(paper: dict): | |
| """Test 3: Add citation to bibliography""" | |
| print("\n" + "="*80) | |
| print("π§ͺ TEST 3: Citation Management") | |
| print("="*80) | |
| project_root = Path.cwd() | |
| citation_manager = CitationManager(project_root) | |
| # Create a sample BibTeX entry | |
| bibtex_entry = f"""@article{{{paper.get('paperId', 'test2024')}, | |
| title = {{{paper['title']}}}, | |
| author = {{{' and '.join(paper.get('authors', ['Unknown'])[:3])}}}, | |
| year = {{{paper.get('year', '2024')}}}, | |
| journal = {{ArXiv}}, | |
| note = {{Citations: {paper.get('citationCount', 0)}}} | |
| }}""" | |
| print("π Adding citation to references.bib:") | |
| print(bibtex_entry[:150] + "...") | |
| citation_manager.add_citation(bibtex_entry) | |
| print("β Citation added successfully") | |
| # List citations | |
| print("\nπ Current citations in bibliography:") | |
| citations = citation_manager.list_citations() | |
| print(f" Total citations: {len(citations)}") | |
| for key in list(citations.keys())[:3]: | |
| print(f" - {key}") | |
| async def test_context_manager(): | |
| """Test 4: File context management""" | |
| print("\n" + "="*80) | |
| print("π§ͺ TEST 4: Context Management") | |
| print("="*80) | |
| project_root = Path.cwd() | |
| context_manager = ContextManager(project_root) | |
| # Get project status | |
| print("π Getting project status...") | |
| status = context_manager.get_project_status() | |
| print(f"β Project root: {status.get('root', 'N/A')}") | |
| print(f" Files found: {len(status.get('files', []))}") | |
| # Read README | |
| print("\nπ Reading README.md...") | |
| readme_path = project_root / "README.md" | |
| if readme_path.exists(): | |
| content = context_manager.get_context(str(readme_path)) | |
| print(f"β README loaded ({len(content)} characters)") | |
| print(f" Preview: {content[:100]}...") | |
| else: | |
| print("β οΈ README.md not found") | |
| async def test_rag_service(): | |
| """Test 5: RAG Service (semantic search)""" | |
| print("\n" + "="*80) | |
| print("π§ͺ TEST 5: RAG Service") | |
| print("="*80) | |
| project_root = Path.cwd() | |
| rag_service = RAGService(project_root) | |
| print("π Testing semantic search capabilities...") | |
| print("β RAG service initialized") | |
| print(" Note: RAG indexing requires papers to be saved in literature/") | |
| async def test_project_initializer(): | |
| """Test 6: Project Initialization""" | |
| print("\n" + "="*80) | |
| print("π§ͺ TEST 6: Project Structure") | |
| print("="*80) | |
| project_root = Path.cwd() | |
| initializer = ProjectInitializer(project_root) | |
| print("π Checking project structure...") | |
| # Check if standard directories exist | |
| dirs = ["literature", "ideas", "method", "paper"] | |
| existing = [d for d in dirs if (project_root / d).exists()] | |
| print(f"β Standard directories found: {len(existing)}/{len(dirs)}") | |
| for dir_name in existing: | |
| print(f" - {dir_name}/") | |
| async def main(): | |
| """Run all tests""" | |
| print("\n" + "="*80) | |
| print("π Polyhedra MCP Tools - Interactive Test Suite") | |
| print("="*80) | |
| try: | |
| # Test 1: Search papers | |
| paper = await test_search_papers() | |
| if paper and paper.get('paperId'): | |
| # Test 2: Get paper details | |
| detailed_paper = await test_get_paper(paper['paperId']) | |
| # Test 3: Citation management | |
| await test_citation_manager(detailed_paper) | |
| # Test 4: Context management | |
| await test_context_manager() | |
| # Test 5: RAG service | |
| await test_rag_service() | |
| # Test 6: Project structure | |
| await test_project_initializer() | |
| # Summary | |
| print("\n" + "="*80) | |
| print("β All Tests Completed Successfully!") | |
| print("="*80) | |
| print("\nπ Polyhedra tools are working correctly:") | |
| print(" β Paper search and retrieval") | |
| print(" β Citation management") | |
| print(" β Context/file management") | |
| print(" β RAG/semantic search") | |
| print(" β Project structure") | |
| print("\nπ‘ Try these commands in your AI assistant:") | |
| print(" - 'Search for papers about neural architecture search'") | |
| print(" - 'Add this paper to my bibliography'") | |
| print(" - 'Find similar papers to my research topic'") | |
| except Exception as e: | |
| print(f"\nβ Test failed with error: {e}") | |
| import traceback | |
| traceback.print_exc() | |
| if __name__ == "__main__": | |
| asyncio.run(main()) | |