feat(settings): support gateway source switching
This commit is contained in:
@@ -106,6 +106,47 @@ class AITests(TempDirMixin, unittest.TestCase):
|
||||
appconfig.save_cmhub_config({"api_key": "sk-cmhub-secret"}, path=key_path)
|
||||
return cfg, key_path
|
||||
|
||||
def test_freeze_runtime_config_keeps_worker_credentials_and_models_in_memory(self):
|
||||
with self.make_temp_dir() as temp_dir:
|
||||
config = self._config()
|
||||
config["ai"]["cmhub"] = {
|
||||
"base_url": "https://cmhub.example.com",
|
||||
"image_alias": "image-hd",
|
||||
"connect_timeout": 3,
|
||||
}
|
||||
cmhub_path = os.path.join(temp_dir, "cmhub.json")
|
||||
models_path = os.path.join(temp_dir, "ai_models.json")
|
||||
self._write_models(models_path)
|
||||
appconfig.save_cmhub_config({"api_key": "sk-before-save"}, path=cmhub_path)
|
||||
|
||||
snapshot = ai.freeze_runtime_config(
|
||||
config,
|
||||
cmhub_config_path=cmhub_path,
|
||||
models_path=models_path,
|
||||
include_cmhub=True,
|
||||
)
|
||||
appconfig.save_cmhub_config({"api_key": "sk-after-save"}, path=cmhub_path)
|
||||
replacement_models = appconfig.list_ai_models(
|
||||
path=models_path,
|
||||
reveal_api_key=True,
|
||||
)
|
||||
for model in replacement_models:
|
||||
model["name"] = "已保存后替换的%s模型" % model["category"]
|
||||
appconfig.save_ai_models_config({"models": replacement_models}, path=models_path)
|
||||
|
||||
self.assertEqual(
|
||||
"sk-before-save",
|
||||
ai._cmhub_runtime(snapshot, "image", cmhub_path)["api_key"],
|
||||
)
|
||||
ai.validate_direct_generation_config(
|
||||
snapshot,
|
||||
"title",
|
||||
models_path=models_path,
|
||||
)
|
||||
self.assertIn("direct_models", snapshot["_cmshopee_ai_runtime"])
|
||||
|
||||
self.assert_removed(temp_dir)
|
||||
|
||||
def _collected_tasks(self, temp_dir, cfg, titles=None):
|
||||
titles = titles or ["旧标题A", "旧标题B"]
|
||||
db.init_db(cfg["db_path"])
|
||||
|
||||
Reference in New Issue
Block a user