34 lines
959 B
Python
34 lines
959 B
Python
"""模型 API。"""
|
|
|
|
from __future__ import annotations
|
|
|
|
from fastapi import APIRouter, HTTPException
|
|
|
|
from ..providers import ProviderError
|
|
from ..schemas import ModelBulkIn, ModelPatchIn
|
|
from ..services import providers as svc
|
|
|
|
router = APIRouter(prefix="/api/models", tags=["models"])
|
|
|
|
|
|
@router.get("")
|
|
def list_models(provider_id: str | None = None):
|
|
return svc.list_models(provider_id)
|
|
|
|
|
|
@router.patch("/{model_id:path}")
|
|
def patch_model(model_id: str, payload: ModelPatchIn):
|
|
try:
|
|
if payload.enabled is not None:
|
|
svc.set_model_enabled(model_id, payload.enabled)
|
|
if payload.note is not None:
|
|
svc.set_model_note(model_id, payload.note)
|
|
return svc.get_model(model_id)
|
|
except ProviderError as exc:
|
|
raise HTTPException(status_code=exc.status, detail=exc.message)
|
|
|
|
|
|
@router.post("/bulk")
|
|
def bulk_models(payload: ModelBulkIn):
|
|
return svc.set_models_enabled(payload.ids, payload.enabled)
|