File size: 1,934 Bytes
ab04492
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
from fastapi import FastAPI, HTTPException
from pydantic import BaseModel
import uvicorn
from typing import Optional
import logging

# Configure logging
logging.basicConfig(level=logging.INFO)
logger = logging.getLogger(__name__)

# Initialize FastAPI
app = FastAPI(
    title="OpenHealth Agent API",
    description="Medical Literature Assistant Backend",
    version="0.1.0"
)

# Pydantic models
class QueryRequest(BaseModel):
    question: str
    max_papers: Optional[int] = 10
    min_year: Optional[int] = 2019

class HealthResponse(BaseModel):
    status: str
    timestamp: str
    version: str

# Root endpoint
@app.get("/")
async def root():
    return {
        "message": "OpenHealth Agent API",
        "endpoints": {
            "health": "/health",
            "search": "/search",
            "analyze": "/analyze"
        }
    }

# Health check
@app.get("/health", response_model=HealthResponse)
async def health_check():
    import datetime
    return {
        "status": "healthy",
        "timestamp": datetime.datetime.now().isoformat(),
        "version": "0.1.0"
    }

# Search endpoint (placeholder)
@app.post("/search")
async def search_papers(request: QueryRequest):
    logger.info(f"Received query: {request.question}")
    
    # For now, return mock data
    return {
        "status": "success",
        "query": request.question,
        "results": [
            {
                "title": "Sample Study on Diabetes Treatment",
                "authors": ["Smith J", "Johnson A"],
                "year": 2023,
                "journal": "New England Journal of Medicine",
                "abstract": "A randomized controlled trial comparing SGLT2 inhibitors to standard care."
            }
        ],
        "count": 1
    }

# Run the app
if __name__ == "__main__":
    uvicorn.run(
        "api:app",
        host="0.0.0.0",
        port=8000,
        reload=True  # Auto-reload on changes
    )