feat(product-suite): add cmhub vision AI writing
This commit is contained in:
@@ -54,6 +54,7 @@ from PySide6.QtWidgets import (
|
||||
|
||||
from ... import (
|
||||
accounts,
|
||||
ai,
|
||||
appconfig,
|
||||
diagnostics,
|
||||
image_studio,
|
||||
@@ -3386,8 +3387,9 @@ class ProductSuiteTab(QWidget):
|
||||
return
|
||||
local_assets = [asset for asset in self._original_assets(state) if _asset_usable(asset)]
|
||||
if not local_assets:
|
||||
self._message("缺少商品原图", "请先添加或拉取至少一张可用商品原图。")
|
||||
self._message("缺少可用商品原图", "请先添加商品原图,或等待已拉取的商品原图下载完成。")
|
||||
return
|
||||
selected_assets = local_assets[: ai.CMHUB_VISION_MAX_IMAGES]
|
||||
self._save_controls_to_state(state)
|
||||
context = (
|
||||
"商品ID:%s;平台:%s;国家地区:%s;输出语言:%s。当前已有要求:%s"
|
||||
@@ -3400,15 +3402,15 @@ class ProductSuiteTab(QWidget):
|
||||
)
|
||||
)
|
||||
instruction = (
|
||||
"请为电商商品图片生成简洁、可执行的商品卖点与画面要求。"
|
||||
"只输出可直接用于生图的中文提示词,包含核心卖点、目标人群、使用场景和禁用元素,"
|
||||
"不要虚构商品参数。"
|
||||
"请为当前商品原图生成简洁、可执行的商品卖点与画面要求。"
|
||||
"内容应包含核心卖点、目标人群、使用场景和禁用元素,不要虚构商品参数。"
|
||||
)
|
||||
state.ai_prompt_snapshot = state.prompt
|
||||
state.ai_started_at = time.monotonic()
|
||||
worker = ProductSuiteAiWriteWorker(
|
||||
instruction,
|
||||
context,
|
||||
image_paths=[asset.local_path for asset in selected_assets],
|
||||
config=self.config,
|
||||
cmhub_config_path=self.cmhub_config_path,
|
||||
)
|
||||
@@ -3419,7 +3421,10 @@ class ProductSuiteTab(QWidget):
|
||||
state.ai_thread = self._start_thread(worker, "商品套图AI帮写")
|
||||
if state is self._displayed_state:
|
||||
self._apply_running_state(state)
|
||||
self._status("AI帮写已开始,可切换到其他套图任务", "info")
|
||||
message = "AI帮写已开始,可切换到其他套图任务"
|
||||
if len(local_assets) > ai.CMHUB_VISION_MAX_IMAGES:
|
||||
message += ";已使用前%d张商品原图进行理解" % ai.CMHUB_VISION_MAX_IMAGES
|
||||
self._status(message, "info")
|
||||
|
||||
def cancel_ai_write(self, checked=False):
|
||||
state = self._displayed_state
|
||||
@@ -3444,7 +3449,11 @@ class ProductSuiteTab(QWidget):
|
||||
if state is self._displayed_state:
|
||||
self._offer_pending_ai_result(state)
|
||||
else:
|
||||
self._status("AI帮写已完成,切回对应套图任务后确认是否采用", "success")
|
||||
self._status(
|
||||
self._ai_write_success_message(result)
|
||||
+ ",切回对应套图任务后确认是否采用",
|
||||
"success",
|
||||
)
|
||||
else:
|
||||
state.prompt = text
|
||||
self._persist_state(state)
|
||||
@@ -3454,10 +3463,22 @@ class ProductSuiteTab(QWidget):
|
||||
self.prompt_edit.setPlainText(text)
|
||||
finally:
|
||||
self._loading = False
|
||||
self._status("AI帮写已完成", "success")
|
||||
self._status(self._ai_write_success_message(result), "success")
|
||||
if state is self._displayed_state:
|
||||
self._apply_running_state(state)
|
||||
|
||||
def _ai_write_success_message(self, result):
|
||||
image_count = max(0, int(dict(result or {}).get("image_count", 0) or 0))
|
||||
parts = ["AI帮写完成"]
|
||||
if image_count:
|
||||
parts.append("已理解%d张商品原图" % image_count)
|
||||
metadata = dict(dict(result or {}).get("metadata") or {})
|
||||
if metadata.get("points_cost") is not None:
|
||||
parts.append("图片理解扣点%s" % metadata["points_cost"])
|
||||
if metadata.get("points_balance") is not None:
|
||||
parts.append("当前余额%s" % metadata["points_balance"])
|
||||
return ":".join(parts[:2]) + ("," + ",".join(parts[2:]) if len(parts) > 2 else "")
|
||||
|
||||
def _offer_pending_ai_result(self, state):
|
||||
if not state.pending_ai_text:
|
||||
return
|
||||
|
||||
Reference in New Issue
Block a user