File size: 1,385 Bytes
8cbc9ec
 
cf84c8b
 
8cbc9ec
fccd138
37fe7f8
755f80a
 
 
8cbc9ec
 
 
fccd138
be32a67
8f62f8c
fccd138
a79668c
cf84c8b
 
 
a79668c
cf84c8b
25b1fee
cf84c8b
37fe7f8
a78bd20
37fe7f8
cf84c8b
 
 
e63759a
 
 
cf84c8b
 
 
 
 
 
f8b17b7
a79668c
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
import os

from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from prometheus_fastapi_instrumentator import Instrumentator
from slowapi import _rate_limit_exceeded_handler as _slowapi_handler
from slowapi.errors import RateLimitExceeded
from starlette.requests import Request
from starlette.responses import Response

from app.api.limiter import limiter
from app.api.routes import router


def handle_rate_limit(request: Request, exc: Exception) -> Response:
    return _slowapi_handler(request, exc)  # type: ignore[arg-type, return-value, unused-ignore]


app = FastAPI(
    title="AI Code Review Agent",
    description="Multi-agent AI platform that simulates a software engineering team",
    version="0.1.0",
)
Instrumentator().instrument(app).expose(app, endpoint="/metrics/prometheus")

app.state.limiter = limiter
app.add_exception_handler(RateLimitExceeded, handle_rate_limit)  # type: ignore[arg-type, unused-ignore]

# Allow Gradio frontend to talk to FastAPI
app.add_middleware(
    CORSMiddleware,
    allow_origins=os.getenv("ALLOWED_ORIGINS", "http://localhost:7860").split(","),
    allow_methods=["POST", "GET"],
    allow_headers=["X-API-Key", "Content-Type"],
)

app.include_router(router, prefix="/api/v1")


@app.get("/")
def root() -> dict[str, str]:
    return {"message": "AI Code Review Agent", "version": "0.1.0", "docs": "/docs"}