Quellcode durchsuchen

模型下载问题修复

lxylxy123321 vor 1 Woche
Ursprung
Commit
ff1ff8f9d3
1 geänderte Dateien mit 4 neuen und 10 gelöschten Zeilen
  1. 4 10
      backend/app/services/model_service.py

+ 4 - 10
backend/app/services/model_service.py

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