Builds PaperTrail from the base skeleton into a full evidence-verification platform for the "Built with Claude: Life Sciences" hackathon (Builder Track). New named-user features (Build Beyond the Bench): - Lab Notebook Companion โ rough bench notes -> structured, searchable, grounded experiment records (lib/labNotebook, /console/lab-notebook, migration 0059) - Clinical Trial Matcher โ de-identified patient notes -> ranked eligible ClinicalTrials.gov trials with per-criterion inclusion/exclusion reasoning (lib/trialMatcher, /console/trial-matcher, migrations 0060) Platform: - Deterministic verification moat (biostats recompute, exact-span grounding) - 11 biomedical evidence engines (FAERS, GWAS, Open Targets, ChEMBL, ClinVar, PharmGKB, PubTator, DDI, repurposing, biomarker, unified verifier) - Evidence Intelligence (KG, dossier, provenance/export, RWE) + enterprise governance (RBAC, /api/v1 gateway, metering, audit chain, retention) - 17 OSS projects assimilated into native TypeScript on our stack (backend/engines retained + credited in NOTICE) - Multi-format upload (PDF/DOCX/XLSX/CSV/MD/TXT), logo, marketing site - Next.js 16 upgrade, benchmark harness (honest smoke-test caveat) Licensing: Apache-2.0 (LICENSE + NOTICE).
252 lines
5.7 KiB
Markdown
252 lines
5.7 KiB
Markdown
# API Reference
|
|
|
|
## Table of Contents
|
|
- [REST API](#rest-api)
|
|
- [WebSocket API](#websocket-api)
|
|
- [Python Client](#python-client)
|
|
- [Output Files](#output-files)
|
|
|
|
---
|
|
|
|
## REST API
|
|
|
|
Base URL: `http://localhost:8000`
|
|
|
|
### Generate Report
|
|
|
|
**POST `/report/`**
|
|
|
|
```json
|
|
{
|
|
"task": "What are the latest AI developments?",
|
|
"report_type": "research_report",
|
|
"report_source": "web",
|
|
"tone": "Objective",
|
|
"source_urls": [],
|
|
"query_domains": [],
|
|
"generate_in_background": false
|
|
}
|
|
```
|
|
|
|
**Response:**
|
|
|
|
```json
|
|
{
|
|
"report": "# Research Report\n\n...",
|
|
"research_id": "task_1234567890_query",
|
|
"costs": 0.05,
|
|
"pdf_path": "outputs/task_123.pdf",
|
|
"docx_path": "outputs/task_123.docx"
|
|
}
|
|
```
|
|
|
|
### Chat with Report
|
|
|
|
**POST `/api/chat`**
|
|
|
|
```json
|
|
{
|
|
"report": "The full report text...",
|
|
"messages": [
|
|
{"role": "user", "content": "What are the key findings?"}
|
|
]
|
|
}
|
|
```
|
|
|
|
### Report Management
|
|
|
|
| Method | Endpoint | Description |
|
|
|--------|----------|-------------|
|
|
| GET | `/api/reports` | List all reports |
|
|
| GET | `/api/reports/{id}` | Get single report |
|
|
| POST | `/api/reports` | Create/update report |
|
|
| PUT | `/api/reports/{id}` | Update report |
|
|
| DELETE | `/api/reports/{id}` | Delete report |
|
|
|
|
### File Operations
|
|
|
|
| Method | Endpoint | Description |
|
|
|--------|----------|-------------|
|
|
| POST | `/upload/` | Upload document |
|
|
| DELETE | `/delete/{filename}` | Delete file |
|
|
| GET | `/outputs/{filename}` | Get output file |
|
|
|
|
### Configuration
|
|
|
|
| Method | Endpoint | Description |
|
|
|--------|----------|-------------|
|
|
| GET | `/getConfig` | Get current config |
|
|
| POST | `/setConfig` | Update config |
|
|
|
|
---
|
|
|
|
## WebSocket API
|
|
|
|
**Endpoint:** `ws://localhost:8000/ws`
|
|
|
|
### Send Research Request
|
|
|
|
```json
|
|
{
|
|
"task": "Research query",
|
|
"report_type": "research_report",
|
|
"report_source": "web",
|
|
"tone": "Objective",
|
|
"source_urls": [],
|
|
"mcp_enabled": false,
|
|
"mcp_strategy": "fast",
|
|
"mcp_configs": []
|
|
}
|
|
```
|
|
|
|
### Message Types (Server โ Client)
|
|
|
|
| Type | Content | Description |
|
|
|------|---------|-------------|
|
|
| `logs` | `starting_research` | Research initiated |
|
|
| `logs` | `planning_research` | Generating sub-queries |
|
|
| `logs` | `running_subquery_research` | Researching sub-query |
|
|
| `logs` | `research_step_finalized` | Research complete |
|
|
| `logs` | `agent_generated` | Agent role selected |
|
|
| `logs` | `scraping_urls` | Scraping web pages |
|
|
| `logs` | `mcp_optimization` | MCP processing |
|
|
| `logs` | `image_planning` | Planning images |
|
|
| `logs` | `images_ready` | Images generated |
|
|
| `report` | - | Streaming report chunks |
|
|
| `report_complete` | - | Final complete report |
|
|
| `path` | `pdf`, `docx`, `md` | Output file paths |
|
|
| `error` | - | Error messages |
|
|
| `human_feedback` | `request` | Request user input |
|
|
|
|
### Message Format
|
|
|
|
```json
|
|
{
|
|
"type": "logs",
|
|
"content": "starting_research",
|
|
"output": "๐ Starting the research task...",
|
|
"metadata": null
|
|
}
|
|
```
|
|
|
|
### Frontend Handler Example
|
|
|
|
```typescript
|
|
ws.onmessage = (event) => {
|
|
const data = JSON.parse(event.data);
|
|
|
|
switch (data.type) {
|
|
case 'logs':
|
|
setLogs(prev => [...prev, data]);
|
|
break;
|
|
case 'report':
|
|
setAnswer(prev => prev + data.output);
|
|
break;
|
|
case 'report_complete':
|
|
setAnswer(data.output);
|
|
break;
|
|
case 'path':
|
|
setPaths(prev => ({...prev, [data.content]: data.output}));
|
|
break;
|
|
case 'error':
|
|
setError(data.output);
|
|
break;
|
|
}
|
|
};
|
|
```
|
|
|
|
---
|
|
|
|
## Python Client
|
|
|
|
### Basic Usage
|
|
|
|
```python
|
|
from gpt_researcher import GPTResearcher
|
|
import asyncio
|
|
|
|
async def main():
|
|
researcher = GPTResearcher(
|
|
query="What are the latest AI developments?",
|
|
report_type="research_report",
|
|
)
|
|
|
|
await researcher.conduct_research()
|
|
report = await researcher.write_report()
|
|
|
|
print(f"Report: {report}")
|
|
print(f"Costs: ${researcher.get_costs()}")
|
|
|
|
asyncio.run(main())
|
|
```
|
|
|
|
### With MCP
|
|
|
|
```python
|
|
researcher = GPTResearcher(
|
|
query="Research topic",
|
|
mcp_configs=[{
|
|
"name": "github",
|
|
"command": "npx",
|
|
"args": ["-y", "@modelcontextprotocol/server-github"],
|
|
"env": {"GITHUB_TOKEN": os.getenv("GITHUB_TOKEN")}
|
|
}],
|
|
mcp_strategy="deep",
|
|
)
|
|
```
|
|
|
|
### With WebSocket Streaming
|
|
|
|
```python
|
|
class MockWebSocket:
|
|
async def send_json(self, data):
|
|
print(f"[{data['type']}] {data.get('output', '')}")
|
|
|
|
researcher = GPTResearcher(
|
|
query="Research topic",
|
|
websocket=MockWebSocket(),
|
|
)
|
|
```
|
|
|
|
### GPTResearcher Parameters
|
|
|
|
| Parameter | Type | Default | Description |
|
|
|-----------|------|---------|-------------|
|
|
| `query` | str | required | Research question |
|
|
| `report_type` | str | `research_report` | Type of report |
|
|
| `report_source` | str | `web` | Data source |
|
|
| `tone` | Tone | `Objective` | Writing tone |
|
|
| `source_urls` | list | `[]` | Specific URLs to research |
|
|
| `document_urls` | list | `[]` | Document URLs |
|
|
| `query_domains` | list | `[]` | Restrict to domains |
|
|
| `config_path` | str | None | Path to JSON config |
|
|
| `websocket` | WebSocket | None | For streaming |
|
|
| `mcp_configs` | list | `[]` | MCP server configs |
|
|
| `mcp_strategy` | str | `fast` | MCP strategy |
|
|
| `verbose` | bool | `True` | Verbose output |
|
|
|
|
---
|
|
|
|
## Output Files
|
|
|
|
```
|
|
outputs/
|
|
โโโ task_{timestamp}_{query}.md
|
|
โโโ task_{timestamp}_{query}.pdf
|
|
โโโ task_{timestamp}_{query}.docx
|
|
โโโ images/
|
|
โโโ {research_id}/
|
|
โโโ img_{hash}_{index}.png
|
|
```
|
|
|
|
---
|
|
|
|
## Error Codes
|
|
|
|
| Code | Description |
|
|
|------|-------------|
|
|
| 400 | Bad Request - Invalid parameters |
|
|
| 404 | Not Found - Report not found |
|
|
| 429 | Rate Limited - API quota exceeded |
|
|
| 500 | Internal Server Error |
|