fix: restore llm model validation dependency
This commit is contained in:
@@ -4,6 +4,7 @@ from datetime import datetime, timezone
|
|||||||
from typing import Any
|
from typing import Any
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
|
|
||||||
|
from backend.bootstrap.config import validate_text
|
||||||
from backend.features.screener.compiler import LLMCompilerError, test_llm_connection
|
from backend.features.screener.compiler import LLMCompilerError, test_llm_connection
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -1,8 +1,10 @@
|
|||||||
from __future__ import annotations
|
from __future__ import annotations
|
||||||
|
|
||||||
import unittest
|
import unittest
|
||||||
|
from unittest.mock import patch
|
||||||
|
|
||||||
from backend.llm import LLMGateway, LLMGatewayError
|
from backend.llm import LLMGateway, LLMGatewayError
|
||||||
|
from backend.llm.service import LLMServiceMixin
|
||||||
|
|
||||||
|
|
||||||
class ProviderFailure(RuntimeError):
|
class ProviderFailure(RuntimeError):
|
||||||
@@ -113,6 +115,31 @@ class LLMGatewayTests(unittest.TestCase):
|
|||||||
with self.assertRaisesRegex(LLMGatewayError, "额度已用完"):
|
with self.assertRaisesRegex(LLMGatewayError, "额度已用完"):
|
||||||
gateway.call("mentor", "mentor-v1", lambda model: "unused", (ProviderFailure,))
|
gateway.call("mentor", "mentor-v1", lambda model: "unused", (ProviderFailure,))
|
||||||
|
|
||||||
|
def test_saved_system_model_can_reach_the_connection_probe(self) -> None:
|
||||||
|
service = LLMServiceMixin()
|
||||||
|
service._system_credentials = {
|
||||||
|
"llm_models": [
|
||||||
|
{
|
||||||
|
"id": "primary-model",
|
||||||
|
"name": "主模型",
|
||||||
|
"api_key": "secret",
|
||||||
|
"base_url": "https://model.example/v1",
|
||||||
|
"model": "model-name",
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
service.llm_gateway = self.gateway()
|
||||||
|
expected = {"ok": True, "reply": "OK"}
|
||||||
|
with patch(
|
||||||
|
"backend.llm.service.test_llm_connection", return_value=expected
|
||||||
|
) as connection_probe:
|
||||||
|
result = service.test_system_llm_profile("primary-model", {})
|
||||||
|
|
||||||
|
self.assertEqual(result, expected)
|
||||||
|
connection_probe.assert_called_once_with(
|
||||||
|
"secret", "https://model.example/v1", "model-name"
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
unittest.main()
|
unittest.main()
|
||||||
|
|||||||
Reference in New Issue
Block a user