Spaces:
Sleeping
Sleeping
File size: 1,153 Bytes
ccb1bbd | 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 | """
main.py
-------
FastAPI backend exposing a single endpoint:
POST /research
body: {"topic": "reinforcement learning"}
returns: {status, reason, report, agent_log}
Run with:
uvicorn backend.main:app --reload --port 8000
"""
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from pydantic import BaseModel
from backend.orchestrator import run_research_pipeline
from backend import config
app = FastAPI(title="Education Research Agent API")
# Allow the Streamlit frontend (running on a different port) to call this API
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_methods=["*"],
allow_headers=["*"],
)
class ResearchRequest(BaseModel):
topic: str
@app.get("/health")
def health_check():
missing = config.validate_keys()
return {
"status": "ok",
"missing_required_keys": missing,
}
@app.post("/research")
def research(request: ResearchRequest):
topic = request.topic.strip()
if not topic:
return {"status": "error", "reason": "Empty topic.", "report": None, "agent_log": []}
return run_research_pipeline(topic)
|