| from __future__ import annotations |
| """ |
| roadshow-server-v3 |
| AX Tech Connect ์์ฐ์ฉ ๋ฐฑ์๋ (๋ง์ดK Intent Taxonomy 116๊ฐ ๊ธฐ๋ฐ) |
| |
| ์๋๋ฆฌ์ค: cs-myk-v3 |
| ๊ตฌ์กฐ: 3-Layer (Foundation / Inference / Serving) |
| """ |
| import logging |
| from contextlib import asynccontextmanager |
|
|
| from fastapi import FastAPI |
| from fastapi.middleware.cors import CORSMiddleware |
|
|
| from config import settings |
| from data.executor import init_db |
| from routes import sessions, intents, scenarios, admin |
| from ws.handler import router as ws_router |
|
|
| logging.basicConfig( |
| level=logging.INFO, |
| format="%(asctime)s [%(levelname)s] %(name)s: %(message)s", |
| ) |
| logger = logging.getLogger(__name__) |
|
|
|
|
| @asynccontextmanager |
| async def lifespan(app: FastAPI): |
| """์ฑ ์๋ช
์ฃผ๊ธฐ๋ฅผ ๊ด๋ฆฌํ๋ค. |
| |
| ๊ธฐ๋ ์ DB๋ฅผ ์ด๊ธฐํ(์คํค๋ง ์์ฑ + ์นดํ๋ก๊ทธ ์๋)ํ๊ณ , |
| WARMUP_ON_START๊ฐ ์ผ์ ธ ์์ผ๋ฉด ๋ชจ๋ธ์ ๋ฏธ๋ฆฌ ํ์ตยท์ค๋นํ๋ค. |
| ์ข
๋ฃ ์ ๋ก๊น
ํ๋ค. |
| |
| Args: |
| app: FastAPI ์ ํ๋ฆฌ์ผ์ด์
์ธ์คํด์ค. |
| |
| Yields: |
| ์ ์ด๋ฅผ ์ ํ๋ฆฌ์ผ์ด์
์คํ ๊ตฌ๊ฐ์ผ๋ก ๋๊ธด๋ค. |
| """ |
| logger.info(f"Starting roadshow-server-v3 (scenario={settings.SCENARIO_ID})") |
| init_db() |
| logger.info(f"DB initialized: {settings.DB_PATH}") |
| if settings.WARMUP_ON_START: |
| from core.warmup import warmup_models |
| warmup_models() |
| yield |
| logger.info("Shutting down roadshow-server-v3") |
|
|
|
|
| app = FastAPI( |
| title="roadshow-server-v3", |
| description="AX Tech Connect ์์ฐ์ฉ ๋ฐฑ์๋ (๋ง์ดK Intent Taxonomy 116๊ฐ)", |
| version="3.0.0", |
| lifespan=lifespan, |
| ) |
|
|
| _cors_origins = ( |
| [o.strip() for o in settings.CORS_ORIGINS.split(",") if o.strip()] |
| if settings.CORS_ORIGINS |
| else ["*"] |
| ) |
| app.add_middleware( |
| CORSMiddleware, |
| allow_origins=_cors_origins, |
| allow_credentials=True, |
| allow_methods=["*"], |
| allow_headers=["*"], |
| ) |
|
|
| app.include_router(scenarios.router, prefix="/api/scenarios", tags=["scenarios"]) |
| app.include_router(sessions.router, prefix="/api/sessions", tags=["sessions"]) |
| app.include_router(intents.router, prefix="/api/intents", tags=["intents"]) |
| app.include_router(admin.router, prefix="/api/admin", tags=["admin"]) |
| app.include_router(ws_router) |
|
|
|
|
| @app.get("/health") |
| async def health() -> dict: |
| """ํฌ์ค ์ฒดํฌ ์๋ํฌ์ธํธ. |
| |
| Returns: |
| ์๋ฒ ์ํ(status), ์๋๋ฆฌ์ค ID(scenario_id), ํ๊ฒฝ(env)์ ๋ด์ dict. |
| """ |
| return { |
| "status": "ok", |
| "scenario_id": settings.SCENARIO_ID, |
| "env": settings.ENV, |
| } |
|
|
|
|
| if __name__ == "__main__": |
| import uvicorn |
| uvicorn.run( |
| "main:app", |
| host="0.0.0.0", |
| port=settings.PORT, |
| reload=settings.RELOAD, |
| ) |
|
|