docs: add comprehensive README and project scaffolding
- README completo con istruzioni di installazione, configurazione e utilizzo - API Swagger/OpenAPI documentata - File env.example con variabili di configurazione - Dockerfile multi-stage ottimizzato - Docker Compose con Ollama e LLM Monitor - Struttura completa dell'app FastAPI (main.py, config, api routes) - Servizio client Ollama reusabile - Dashboard web HTML con TailwindCSS - Test suite con pytest - Makefile per comandi comuni - CONTRIBUTING.md per i contributori - LICENSE MIT - .editorconfig e .dockerignore - requirements.txt e requirements-dev.txt
This commit is contained in:
@@ -0,0 +1,82 @@
|
||||
"""
|
||||
LLM Monitor - Dashboard per controllare i modelli caricati in Ollama
|
||||
Entry point dell'applicazione FastAPI
|
||||
"""
|
||||
|
||||
import logging
|
||||
from fastapi import FastAPI
|
||||
from fastapi.staticfiles import StaticFiles
|
||||
from fastapi.responses import FileResponse
|
||||
from fastapi.middleware.cors import CORSMiddleware
|
||||
from pathlib import Path
|
||||
import os
|
||||
|
||||
# Configurazione logging
|
||||
logging.basicConfig(level=logging.INFO)
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
# Importare le rotte
|
||||
from app.api.health import router as health_router
|
||||
from app.api.models import router as models_router
|
||||
from app.config import settings
|
||||
|
||||
# Creare l'app FastAPI
|
||||
app = FastAPI(
|
||||
title="LLM Monitor API",
|
||||
description="Dashboard per il monitoraggio dei modelli LLM in Ollama",
|
||||
version="1.0.0",
|
||||
docs_url="/docs",
|
||||
redoc_url="/redoc",
|
||||
openapi_url="/openapi.json"
|
||||
)
|
||||
|
||||
# Configurare CORS
|
||||
app.add_middleware(
|
||||
CORSMiddleware,
|
||||
allow_origins=settings.CORS_ORIGINS.split(","),
|
||||
allow_credentials=True,
|
||||
allow_methods=["*"],
|
||||
allow_headers=["*"],
|
||||
)
|
||||
|
||||
# Registrare le rotte API
|
||||
app.include_router(health_router, prefix="/api/v1", tags=["health"])
|
||||
app.include_router(models_router, prefix="/api/v1", tags=["models"])
|
||||
|
||||
# Servire i file statici
|
||||
static_path = Path(__file__).parent / "app" / "web" / "static"
|
||||
if static_path.exists():
|
||||
app.mount("/static", StaticFiles(directory=static_path), name="static")
|
||||
|
||||
# Servire la dashboard web
|
||||
templates_path = Path(__file__).parent / "app" / "web" / "templates"
|
||||
|
||||
@app.get("/")
|
||||
async def root():
|
||||
"""Redirect alla dashboard"""
|
||||
return FileResponse(templates_path / "index.html")
|
||||
|
||||
@app.get("/dashboard")
|
||||
async def dashboard():
|
||||
"""Dashboard principale"""
|
||||
return FileResponse(templates_path / "index.html")
|
||||
|
||||
# Event hooks
|
||||
@app.on_event("startup")
|
||||
async def startup_event():
|
||||
logger.info("🚀 LLM Monitor avviato")
|
||||
logger.info(f"📊 Ollama host: {settings.OLLAMA_HOST}")
|
||||
|
||||
@app.on_event("shutdown")
|
||||
async def shutdown_event():
|
||||
logger.info("🛑 LLM Monitor arrestato")
|
||||
|
||||
if __name__ == "__main__":
|
||||
import uvicorn
|
||||
uvicorn.run(
|
||||
"main:app",
|
||||
host=settings.API_HOST,
|
||||
port=settings.API_PORT,
|
||||
reload=settings.ENVIRONMENT == "development",
|
||||
log_level=settings.LOG_LEVEL.lower()
|
||||
)
|
||||
Reference in New Issue
Block a user