""" Model router for Lily LLM API """ from fastapi import APIRouter, HTTPException, Form from typing import Optional import logging from ...models.schemas import HealthResponse from ...services.model_service import load_model_async, get_current_profile, is_model_loaded from ...models import list_available_models logger = logging.getLogger(__name__) router = APIRouter() @router.post("/load-model") async def load_model_endpoint(model_id: str): """모델 로드 HTTP 엔드포인트""" try: logger.info(f"📥 HTTP 요청으로 모델 로드 시작: {model_id}") await load_model_async(model_id) return {"success": True, "message": f"모델 '{model_id}' 로드 완료"} except Exception as e: logger.error(f"❌ HTTP 모델 로드 실패: {e}") return {"success": False, "error": str(e)} @router.get("/models") async def list_models(): """사용 가능한 모델 목록""" return { "models": list_available_models(), "current_model": get_current_profile().get_model_info() if get_current_profile() else None } @router.post("/switch-model") async def switch_model(model_id: str): """모델 변경""" try: await load_model_async(model_id) return { "message": f"모델 변경 성공: {model_id}", "current_model": get_current_profile().display_name } except Exception as e: raise HTTPException(status_code=500, detail=f"모델 변경 실패: {str(e)}") @router.get("/health", response_model=HealthResponse) async def health_check(): """헬스 체크 엔드포인트""" available_models = list_available_models() return HealthResponse( status="healthy", model_loaded=is_model_loaded(), current_model=get_current_profile().display_name if get_current_profile() else "None", available_models=available_models )