fix: restore llm model validation dependency
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
from backend.llm import LLMGateway, LLMGatewayError
|
||||
from backend.llm.service import LLMServiceMixin
|
||||
|
||||
|
||||
class ProviderFailure(RuntimeError):
|
||||
@@ -113,6 +115,31 @@ class LLMGatewayTests(unittest.TestCase):
|
||||
with self.assertRaisesRegex(LLMGatewayError, "额度已用完"):
|
||||
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__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user