feat(product-suite): add cmhub vision AI writing

This commit is contained in:
chengma
2026-07-17 09:09:09 +08:00
parent 56d6b59a00
commit 40a9f5fbf2
15 changed files with 575 additions and 40 deletions
+31
View File
@@ -20,6 +20,7 @@ from app.workers import BaseWorker, run_worker
from app.gui.workers import (
ImageStudioDownloadOriginalWorker,
ImageStudioPullImagesWorker,
ProductSuiteAiWriteWorker,
ProductSuiteGenerateWorker,
)
@@ -198,6 +199,36 @@ class WorkerTests(unittest.TestCase):
self.assertEqual({"asset_id": 12, "cancelled": True}, summary)
def test_product_suite_ai_write_worker_uses_image_analysis_not_title_generation(self):
worker = ProductSuiteAiWriteWorker(
"补充要求",
"输出语言:繁体中文",
image_paths=["first.jpg", "second.jpg"],
config={"ai": {"backend": "cmhub"}},
cmhub_config_path="cmhub.json",
)
expected = {
"text": "根据图片整理的商品卖点",
"image_count": 2,
"metadata": {"points_cost": 1, "points_balance": 231},
}
with mock.patch(
"app.gui.workers.ai.analyze_product_images",
return_value=expected,
) as analyze, mock.patch("app.gui.workers.ai.gen_title") as gen_title:
result = worker.execute()
analyze.assert_called_once_with(
"补充要求",
"输出语言:繁体中文",
["first.jpg", "second.jpg"],
config={"ai": {"backend": "cmhub"}},
cmhub_config_path="cmhub.json",
)
gen_title.assert_not_called()
self.assertEqual(expected, result)
def test_product_suite_worker_writes_generation_round_and_stable_slots(self):
with tempfile.TemporaryDirectory() as temp_dir:
db_path = os.path.join(temp_dir, "cmshopee.db")