feat(ai): enforce direct image edit contract

This commit is contained in:
chengma
2026-07-20 17:52:59 +08:00
parent 61db0f4ed6
commit 2a2cbad7bd
11 changed files with 382 additions and 94 deletions
+21 -4
View File
@@ -3261,24 +3261,41 @@ class CMHubSettingsWorker(BaseWorker):
return _elapsed_ms(started)
class AIModelTestWorker(BaseWorker):
"""Test one AI model connection without blocking the GUI thread."""
"""Test text models or validate image-model configuration off the GUI thread."""
def __init__(self, model_name, ai_models_path=None, db_path=None, diagnostic_log_dir=None):
def __init__(
self,
model_name,
ai_models_path=None,
db_path=None,
diagnostic_log_dir=None,
check_image_config=False,
):
super().__init__()
self.model_name = model_name
self.ai_models_path = ai_models_path or appconfig.AI_MODELS_PATH
self.db_path = db_path
self.diagnostic_log_dir = diagnostic_log_dir
self.check_image_config = bool(check_image_config)
self._run_id = None
def execute(self):
self._run_id = self._create_run_log()
started = time.monotonic()
self._log_run_event(
f"step=test_connection result=start detail=AI模型 {self.model_name}"
"step={step} result=start detail=AI模型 {name}".format(
step="check_image_config" if self.check_image_config else "test_connection",
name=self.model_name,
)
)
try:
result = appconfig.test_ai_model(self.model_name, path=self.ai_models_path)
if self.check_image_config:
result = appconfig.check_image_model_config(
self.model_name,
path=self.ai_models_path,
)
else:
result = appconfig.test_ai_model(self.model_name, path=self.ai_models_path)
except Exception as exc:
error = diagnostics.redact_log_text(str(exc) or exc.__class__.__name__)
elapsed_ms = self._elapsed_ms(started)