feat: add diagnostic logs for generation flows
This commit is contained in:
@@ -123,6 +123,46 @@ class AITests(TempDirMixin, unittest.TestCase):
|
||||
|
||||
self.assert_removed(temp_dir)
|
||||
|
||||
|
||||
def test_gen_title_accepts_openai_compatible_base_url(self):
|
||||
with self.make_temp_dir() as temp_dir:
|
||||
models_path = os.path.join(temp_dir, "ai_models.json")
|
||||
self._write_models(
|
||||
models_path,
|
||||
text={
|
||||
"name": "Text",
|
||||
"category": "text",
|
||||
"enabled": True,
|
||||
"url": "https://example.invalid/v1",
|
||||
"model": "text-model",
|
||||
"api_key": "sk-text-secret",
|
||||
"api_type": "chat",
|
||||
"connect_timeout_seconds": 1,
|
||||
"timeout_seconds": 1,
|
||||
"extra_body": {},
|
||||
},
|
||||
)
|
||||
calls = []
|
||||
|
||||
def fake_urlopen(request, timeout=None):
|
||||
calls.append(request)
|
||||
return _Response({"choices": [{"message": {"content": "新标题"}}]})
|
||||
|
||||
with mock.patch("app.ai.urllib.request.urlopen", side_effect=fake_urlopen):
|
||||
title = ai.gen_title(
|
||||
"优化标题",
|
||||
"旧标题",
|
||||
config=self._config(),
|
||||
models_path=models_path,
|
||||
)
|
||||
|
||||
self.assertEqual("新标题", title)
|
||||
self.assertEqual(
|
||||
"https://example.invalid/v1/chat/completions",
|
||||
calls[0].full_url,
|
||||
)
|
||||
|
||||
self.assert_removed(temp_dir)
|
||||
def test_missing_model_fields_raise_clear_error_without_secret(self):
|
||||
with self.make_temp_dir() as temp_dir:
|
||||
models_path = os.path.join(temp_dir, "ai_models.json")
|
||||
|
||||
Reference in New Issue
Block a user