-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
50 lines (36 loc) · 1.56 KB
/
main.py
File metadata and controls
50 lines (36 loc) · 1.56 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
48
49
50
import os
from dotenv import load_dotenv
load_dotenv()
from fastapi import FastAPI # noqa: E402
from fastapi.staticfiles import StaticFiles # noqa: E402
from slowapi import _rate_limit_exceeded_handler # noqa: E402
from slowapi.errors import RateLimitExceeded # noqa: E402
from slowapi.middleware import SlowAPIMiddleware # noqa: E402
from starlette.requests import Request # noqa: E402
from starlette.responses import Response # noqa: E402
from app.routes import api_routes, view_routes # noqa: E402
from app.utils.logger import logger # noqa: E402
logger.info("Variáveis de ambiente carregadas com sucesso")
logger.info(f"Servidor iniciado com modelo: {os.getenv('GEMINI_MODEL_NAME')}")
app = FastAPI(
title="Anime Chatbot",
summary="Anime Chatbot é um chatbot que responde perguntas sobre anime.",
version="1.0",
contact={
"name": "Felipe André",
"url": "https://developer-felipe-andre.vercel.app/",
"email": "profissionalf.andre@gmail.com",
},
)
app.state.limiter = api_routes.limiter
@app.exception_handler(RateLimitExceeded)
def _rate_limit_exceeded_handler_wrapper(request: Request, exc: Exception) -> Response:
return _rate_limit_exceeded_handler(request, exc) # type: ignore
app.add_middleware(SlowAPIMiddleware)
app.mount("/static", StaticFiles(directory="app/static"), name="static")
app.include_router(view_routes.router)
app.include_router(api_routes.router, prefix="/api")
if __name__ == "__main__":
import uvicorn
port = int(os.getenv("APP_PORT", 8000))
uvicorn.run(app, host="0.0.0.0", port=port)