2025-07-17 13:09:24 +02:00
|
|
|
"""
|
|
|
|
|
Models API endpoints
|
|
|
|
|
"""
|
|
|
|
|
|
|
|
|
|
from fastapi import APIRouter, Depends, HTTPException, status
|
|
|
|
|
from sqlalchemy.ext.asyncio import AsyncSession
|
|
|
|
|
from typing import List
|
2025-07-18 14:41:39 +02:00
|
|
|
import structlog
|
2025-07-17 13:09:24 +02:00
|
|
|
|
|
|
|
|
from app.core.database import get_db
|
|
|
|
|
from app.schemas.training import TrainedModelResponse
|
|
|
|
|
from app.services.training_service import TrainingService
|
|
|
|
|
|
2025-07-21 20:43:17 +02:00
|
|
|
from shared.auth.decorators import (
|
|
|
|
|
get_current_tenant_id_dep
|
|
|
|
|
)
|
2025-07-19 16:59:37 +02:00
|
|
|
|
2025-07-18 14:41:39 +02:00
|
|
|
logger = structlog.get_logger()
|
2025-07-17 13:09:24 +02:00
|
|
|
router = APIRouter()
|
|
|
|
|
|
|
|
|
|
training_service = TrainingService()
|
|
|
|
|
|
2025-07-26 23:29:57 +02:00
|
|
|
@router.get("/tenants/{tenant_id}/", response_model=List[TrainedModelResponse])
|
2025-07-17 13:09:24 +02:00
|
|
|
async def get_trained_models(
|
2025-07-21 20:43:17 +02:00
|
|
|
tenant_id: str = Depends(get_current_tenant_id_dep),
|
2025-07-17 13:09:24 +02:00
|
|
|
db: AsyncSession = Depends(get_db)
|
|
|
|
|
):
|
|
|
|
|
"""Get trained models"""
|
|
|
|
|
try:
|
2025-07-19 16:59:37 +02:00
|
|
|
return await training_service.get_trained_models(tenant_id, db)
|
2025-07-17 13:09:24 +02:00
|
|
|
except Exception as e:
|
|
|
|
|
logger.error(f"Get trained models error: {e}")
|
|
|
|
|
raise HTTPException(
|
|
|
|
|
status_code=status.HTTP_500_INTERNAL_SERVER_ERROR,
|
|
|
|
|
detail="Failed to get trained models"
|
|
|
|
|
)
|