model_service.py 836 B

1234567891011121314151617181920212223242526
  1. from pathlib import Path
  2. from typing import Any
  3. from app.config import get_settings
  4. from app.core.logging import logger
  5. settings = get_settings()
  6. async def download_model(model_id: str, use_modelscope: bool = False) -> dict[str, Any]:
  7. """从 HF 或 ModelScope 下载模型到本地缓存。"""
  8. logger.info(f"Downloading model {model_id} (modelscope={use_modelscope})")
  9. return {"model_id": model_id, "status": "downloading"}
  10. def list_cached_models() -> list[dict[str, Any]]:
  11. """列出本地已缓存的模型。"""
  12. models_dir = settings.models_dir
  13. if not models_dir.exists():
  14. return []
  15. return [{"id": d.name, "path": str(d)} for d in models_dir.iterdir() if d.is_dir()]
  16. def get_model_info(model_id: str) -> dict[str, Any] | None:
  17. """获取已缓存模型的元数据。"""
  18. return None