|
@@ -1,12 +1,8 @@
|
|
|
-import json
|
|
|
|
|
from pathlib import Path
|
|
from pathlib import Path
|
|
|
from typing import Any
|
|
from typing import Any
|
|
|
|
|
|
|
|
-from app.config import get_settings
|
|
|
|
|
from app.core.logging import logger
|
|
from app.core.logging import logger
|
|
|
|
|
|
|
|
-settings = get_settings()
|
|
|
|
|
-
|
|
|
|
|
|
|
|
|
|
async def test_model(model_id: str, prompt: str, max_new_tokens: int = 128, temperature: float = 0.8, top_p: float = 0.95) -> dict[str, Any]:
|
|
async def test_model(model_id: str, prompt: str, max_new_tokens: int = 128, temperature: float = 0.8, top_p: float = 0.95) -> dict[str, Any]:
|
|
|
"""加载已缓存模型并生成测试响应。"""
|
|
"""加载已缓存模型并生成测试响应。"""
|
|
@@ -14,8 +10,13 @@ async def test_model(model_id: str, prompt: str, max_new_tokens: int = 128, temp
|
|
|
import torch
|
|
import torch
|
|
|
from transformers import AutoModelForCausalLM, AutoTokenizer
|
|
from transformers import AutoModelForCausalLM, AutoTokenizer
|
|
|
|
|
|
|
|
- # 查找模型路径
|
|
|
|
|
- model_dir = settings.models_dir / model_id.replace("/", "_")
|
|
|
|
|
|
|
+ # 从数据库获取模型实际路径
|
|
|
|
|
+ from app.services.model_service import get_model_info
|
|
|
|
|
+ info = await get_model_info(model_id)
|
|
|
|
|
+ if not info or not info.get("path"):
|
|
|
|
|
+ return {"error": f"Model not found in cache: {model_id}"}
|
|
|
|
|
+
|
|
|
|
|
+ model_dir = Path(info["path"])
|
|
|
if not (model_dir / "config.json").exists():
|
|
if not (model_dir / "config.json").exists():
|
|
|
return {"error": f"Model directory not found: {model_dir}"}
|
|
return {"error": f"Model directory not found: {model_dir}"}
|
|
|
|
|
|