Spaces:
Sleeping
Sleeping
File size: 713 Bytes
15e9798 |
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 |
import os
from fastapi import FastAPI, Request
from fastapi.middleware.cors import CORSMiddleware
from dotenv import load_dotenv
from portfolio_agent import portfolio_agent
load_dotenv()
app = FastAPI()
# Allow frontend access
app.add_middleware(
CORSMiddleware,
allow_origins=["*"],
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
@app.get("/")
def root():
return {"status": "Portfolio Agent API is running"}
@app.post("/chat")
async def chat(request: Request):
data = await request.json()
message = data.get("message", "")
extra_context = os.getenv("extra_context")
answer = portfolio_agent(message, extra_context)
return {"reply": answer}
|