feat: add FastAPI web service wrapper

- Create REST API with endpoints for single and batch analysis
- Add async job support for long-running batch operations
- Implement job status tracking and listing endpoints
- Add 9 tests for API endpoints
- Update requirements.txt with fastapi, uvicorn, httpx
- Document API usage in README

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <noreply@anthropic.com>
This commit is contained in:
2026-03-12 23:26:26 -04:00
parent 1c6d903301
commit 3479ba8a46
4 changed files with 514 additions and 2 deletions
+42 -2
View File
@@ -16,7 +16,8 @@ SPARC automatically collects, parses, and analyzes patents from companies to pro
- **AI Analysis**: Uses Claude 3.5 Sonnet via OpenRouter to analyze innovation quality and market potential
- **Portfolio Analysis**: Evaluates multiple patents holistically for comprehensive insights
- **Batch Processing**: Analyze multiple companies concurrently with progress tracking
- **Robust Testing**: 31 tests covering all major functionality
- **REST API**: FastAPI web service with async job support
- **Robust Testing**: 40 tests covering all major functionality
## Architecture
@@ -25,6 +26,7 @@ SPARC/
├── serp_api.py # Patent retrieval and PDF parsing
├── llm.py # Claude AI integration via OpenRouter
├── analyzer.py # High-level orchestration
├── api.py # FastAPI web service
├── types.py # Data models
└── config.py # Environment configuration
```
@@ -127,6 +129,44 @@ for result in batch_result.results:
batch_result = analyzer.analyze_companies_sequential(["nvidia", "amd"])
```
### REST API
Start the FastAPI server:
```bash
uvicorn SPARC.api:app --reload
```
API endpoints:
| Endpoint | Method | Description |
|----------|--------|-------------|
| `/health` | GET | Health check |
| `/analyze/{company}` | GET | Analyze single company |
| `/analyze/batch` | POST | Analyze multiple companies |
| `/analyze/batch/async` | POST | Start async batch job |
| `/jobs/{job_id}` | GET | Get job status |
| `/jobs` | GET | List all jobs |
Interactive docs available at `http://localhost:8000/docs`
Example API usage:
```bash
# Single company
curl http://localhost:8000/analyze/nvidia
# Batch analysis
curl -X POST http://localhost:8000/analyze/batch \
-H "Content-Type: application/json" \
-d '{"companies": ["nvidia", "amd", "intel"]}'
# Async batch (for long-running jobs)
curl -X POST http://localhost:8000/analyze/batch/async \
-H "Content-Type: application/json" \
-d '{"companies": ["nvidia", "amd", "intel", "qualcomm"]}'
```
## Running Tests
```bash
@@ -159,7 +199,7 @@ pytest tests/ --cov=SPARC --cov-report=term-missing
- [X] LLM integration for analysis
- [X] Company performance estimation
- [X] Multi-company batch processing
- [ ] FastAPI web service wrapper
- [X] FastAPI web service wrapper
- [X] Docker containerization
- [X] Results persistence (database)
- [ ] Visualization dashboard