rebuild(llm): add audited model connectivity tests

This commit is contained in:
leefer
2026-07-30 10:25:07 +08:00
parent d8f0dd930c
commit 08f69b0641
9 changed files with 197 additions and 8 deletions
+16
View File
@@ -35,9 +35,12 @@ from backend.features.accounts.schemas import (
ModelInput,
ModelPoolItemResponse,
ModelSelectionInput,
ModelTestResponse,
ModelUpdateInput,
PasswordChangeInput,
)
from backend.http.errors import AppError
from backend.llm.gateway import LLMGatewayError
router = APIRouter()
@@ -312,3 +315,16 @@ def delete_model(
) -> MessageResponse:
request.app.state.container.model_pool.delete(model_id)
return MessageResponse(message="模型已删除。")
@router.post("/admin/models/{model_id}/test", response_model=ModelTestResponse)
def test_model(
request: Request,
model_id: Annotated[int, Path(ge=1)],
principal: AdminWritePrincipal,
) -> dict[str, object]:
try:
return request.app.state.container.llm.test_model(principal, model_id)
except LLMGatewayError as exc:
status = 404 if exc.code == "model_not_found" else 503
raise AppError(exc.code, str(exc), status) from exc