feat(product-suite): add cmhub vision AI writing
This commit is contained in:
+20
-4
@@ -419,34 +419,41 @@ class ProductSuiteGenerateWorker(BaseWorker):
|
||||
|
||||
|
||||
class ProductSuiteAiWriteWorker(BaseWorker):
|
||||
"""Generate product selling-point copy without blocking the suite workspace."""
|
||||
"""Analyze local product images without blocking the suite workspace."""
|
||||
|
||||
def __init__(
|
||||
self,
|
||||
instruction,
|
||||
context,
|
||||
*,
|
||||
image_paths=None,
|
||||
config=None,
|
||||
cmhub_config_path=None,
|
||||
):
|
||||
super().__init__()
|
||||
self.instruction = str(instruction or "")
|
||||
self.context = str(context or "")
|
||||
self.image_paths = [str(path or "") for path in list(image_paths or [])]
|
||||
self.config = config
|
||||
self.cmhub_config_path = cmhub_config_path
|
||||
|
||||
def execute(self):
|
||||
if self.should_cancel():
|
||||
return {"cancelled": True}
|
||||
text = ai.gen_title(
|
||||
result = ai.analyze_product_images(
|
||||
self.instruction,
|
||||
self.context,
|
||||
self.image_paths,
|
||||
config=self.config,
|
||||
cmhub_config_path=self.cmhub_config_path,
|
||||
)
|
||||
if self.should_cancel():
|
||||
return {"cancelled": True}
|
||||
return {"text": str(text or "").strip()}
|
||||
return {
|
||||
"text": str(result.get("text") or "").strip(),
|
||||
"image_count": int(result.get("image_count", 0) or 0),
|
||||
"metadata": dict(result.get("metadata") or {}),
|
||||
}
|
||||
|
||||
|
||||
class ProductSuiteImportImagesWorker(BaseWorker):
|
||||
@@ -2875,10 +2882,12 @@ class CMHubSettingsWorker(BaseWorker):
|
||||
}
|
||||
title_count = self._priced_count(models, "title")
|
||||
image_count = self._priced_count(models, "image")
|
||||
vision_count = self._priced_count(models, "vision")
|
||||
self._log_run_event(
|
||||
"step=cmhub_settings result=success detail=title_aliases={title_count} image_aliases={image_count} points_balance={points_balance} elapsed_ms={elapsed_ms}".format(
|
||||
"step=cmhub_settings result=success detail=title_aliases={title_count} image_aliases={image_count} vision_aliases={vision_count} points_balance={points_balance} elapsed_ms={elapsed_ms}".format(
|
||||
title_count=title_count,
|
||||
image_count=image_count,
|
||||
vision_count=vision_count,
|
||||
points_balance=payload.get("points_balance") if payload.get("points_balance") is not None else "",
|
||||
elapsed_ms=elapsed_ms,
|
||||
)
|
||||
@@ -2900,6 +2909,13 @@ class CMHubSettingsWorker(BaseWorker):
|
||||
if str(model.get("operation_type") or "").lower() == operation
|
||||
and str(model.get("pricing_status") or "").lower() != "unpriced"
|
||||
and str(model.get("alias") or "").strip()
|
||||
and (
|
||||
operation != "vision"
|
||||
or (
|
||||
str(model.get("pricing_status") or "").lower() == "priced"
|
||||
and bool(model.get("requires_image"))
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
def _create_run_log(self):
|
||||
|
||||
Reference in New Issue
Block a user