lxylxy123321 1 неделя назад
Родитель
Сommit
62f92737b9
1 измененных файлов с 6 добавлено и 1 удалено
  1. 6 1
      backend/app/services/model_service.py

+ 6 - 1
backend/app/services/model_service.py

@@ -43,10 +43,15 @@ async def download_model(model_id: str, use_modelscope: bool = False) -> dict[st
     """从 HF 或 ModelScope 下载模型到本地缓存。"""
     try:
         if use_modelscope:
+            import asyncio
+
             from modelscope.hub.snapshot_download import snapshot_download as ms_download
 
             download_dir = str(settings.models_dir / model_id.replace("/", "_"))
-            local_path = ms_download(model_id, local_dir=download_dir)
+            # 在线程池中执行,避免与 FastAPI 事件循环冲突
+            local_path = await asyncio.to_thread(
+                ms_download, model_id, local_dir=download_dir
+            )
         else:
             from huggingface_hub import snapshot_download