-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfis_api.py
More file actions
47 lines (38 loc) · 1.57 KB
/
Copy pathfis_api.py
File metadata and controls
47 lines (38 loc) · 1.57 KB
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
from fastapi import FastAPI, HTTPException
from pydantic import BaseModel
import uvicorn
from .main import run_financial_analysis
# 1. Initialize FastAPI
app = FastAPI(
title="Financial Intelligence System API",
description="Multi-Agent AI System for Stock Analysis",
version="1.0"
)
# 2. Define Request Model
class TickerRequest(BaseModel):
ticker: str
# 3. Define the Endpoint
@app.post("/analyze", summary="Analyze a specific stock ticker")
async def analyze_stock(request: TickerRequest):
"""
Triggers the multi-agent workflow for the provided ticker.
Returns structured financial analysis including recommendation, risk level, and key drivers.
"""
ticker = request.ticker.upper().strip()
if not ticker:
raise HTTPException(status_code=400, detail="Ticker symbol cannot be empty")
try:
# Call your existing main function
result = run_financial_analysis(ticker)
# Check if analysis was successful
if not result.get("success", True):
error_msg = result.get("error", f"No data found for ticker '{ticker}'")
raise HTTPException(status_code=404, detail=error_msg)
return result
except Exception as e:
# Log the error internally (print to console)
print(f"Server Error: {str(e)}")
raise HTTPException(status_code=500, detail=str(e))
# 4. Entry point for debugging (Optional)
if __name__ == "__main__":
uvicorn.run("fis_api:app", host="127.0.0.1", port=8000, reload=True)