Spaces:
Sleeping
Sleeping
| import os | |
| from dotenv import load_dotenv | |
| load_dotenv() # MUST be first | |
| DEBUG = os.getenv("DEBUG", "").lower() in {"1", "true", "yes"} | |
| if DEBUG: | |
| print("TAVILY_API_KEY exists:", bool(os.getenv("TAVILY_API_KEY"))) | |
| print("GEMINI_API_KEY exists:", bool(os.getenv("GEMINI_API_KEY"))) | |
| from fastapi import FastAPI | |
| from fastapi.responses import StreamingResponse | |
| from app.agent.orchestrator import run_agent, run_agent_stream | |
| from app.schemas import QueryRequest, QueryResponse | |
| from fastapi.middleware.cors import CORSMiddleware | |
| import json | |
| app = FastAPI(title="Agentic Web Bot") | |
| app.add_middleware( | |
| CORSMiddleware, | |
| allow_origins=["*"], | |
| allow_methods=["*"], | |
| allow_headers=["*"], | |
| ) | |
| def root(): | |
| return {"status": "ok", "service": "Agentic Web Bot"} | |
| def healthz(): | |
| return {"ok": True} | |
| def ask_agent(payload: QueryRequest): | |
| return run_agent(payload.query) | |
| def ask_agent_stream(payload: QueryRequest): | |
| async def event_stream(): | |
| for event in run_agent_stream(payload.query): | |
| yield f"data: {json.dumps(event)}\n\n" | |
| return StreamingResponse( | |
| event_stream(), | |
| media_type="text/event-stream", | |
| headers={ | |
| "Cache-Control": "no-cache", | |
| "Connection": "keep-alive", | |
| } | |
| ) | |