A8多套打包+M4归档+R5多图:存量功能备份

A8 多套交付包(packaging_task.py):
- 修复交付包只打第1条混乱note的bug,按ImageCandidate.strategy分A/B/C组
- 每组生独立note_0N夹(6图+文案.txt),同seq留最新去重,老数据兼容
- task74端到端验:3套各6图,独立agent7项交叉验证全过

M4 归档(tasks.py/exports.py/前端):
- list_tasks加date_from/date_to/product_id筛选+product_name批量填(防N+1)
- 新增exports.py:产品JSON导出+标杆CSV导出(UTF-8 BOM)
- 前端HistoryFilters日期/产品筛选+产品列+打回原因红banner
- response.py加raise_param_error;独立agent验A1/A2/A9通过

R5 产品多图(product_images.py/020迁移/前端):
- product_images表+5端点(上传/列/改场景/设主图/删图)
- 生图按ROLE_SCENE_PREFERENCE选对应场景图,回落primary
- 前端ProductImageManager多图画廊

R6 账号config拆页(settings/):
- 配置页按角色拆/settings(运营+组长+admin)+/config(仅admin)
- Key只显末4位不显余额(守红线)

核销表对齐真实代码状态:D1改稿框/M7裂变/E12评图分纠偏为已完成(曾漏回写)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
yangqianqian
2026-06-18 17:32:49 +08:00
parent 285791c12f
commit 4bed7425a8
41 changed files with 1211 additions and 236 deletions

View File

@@ -131,6 +131,38 @@ angle本条角度标签/ coverTitle封面大字≤10字/ imageBrief
硬性格式只输出JSON不要markdown代码块字符串内用中文引号「」。"""
# ── 第2环标杆爆款配方 → 文案 prompt借方法层结构禁抄竞品原话──────────────
_BM_DIM_LABELS: list[tuple[str, str]] = [
("title_formula", "标题公式"),
("opening_hook", "开篇钩子"),
("content_structure", "内容结构"),
("selling_point_style", "卖点表达风格"),
("emotion_tone", "情绪基调"),
("topic_tags", "话题标签思路"),
]
def _build_benchmark_block(refs: list[dict]) -> str:
"""把标杆 8维配方渲染成 prompt 块。只借'方法结构',硬约束禁抄竞品品牌/功效原话。"""
if not refs:
return ""
lines: list[str] = []
for i, f in enumerate(refs[:3], 1): # 最多取3条标杆避免prompt膨胀
dims = [f"{label}=「{str(f.get(key, '')).strip()}"
for key, label in _BM_DIM_LABELS if str(f.get(key, "")).strip()]
if dims:
lines.append(f" 标杆{i}" + "".join(dims))
if not lines:
return ""
body = "\n".join(lines)
return (
"\n【对标爆款配方参考(只借方法层结构,绝不照抄)】\n"
f"{body}\n"
"硬性约束:仅参考上面的标题套路/开篇方式/结构节奏/情绪基调来组织本产品文案;"
"禁止照搬竞品品牌名、产品名、功效原话或具体数字;产品信息一律以本产品为准。"
)
def build_prompt(product: dict, count: int, extra_rules: str = "") -> str:
"""
组装文案生成 user_prompt。
@@ -153,6 +185,7 @@ def build_prompt(product: dict, count: int, extra_rules: str = "") -> str:
angle_hint = f"文案角度要覆盖:{''.join(angles)}(每条用不同角度)。" if angles else ""
brand_rule = f"每条正文和标题中植入品牌词「{brand_kw}」一次(自然融入,不生硬)。" if brand_kw else ""
benchmark_block = _build_benchmark_block(product.get("benchmark_refs") or [])
lines = [
f"产品:{name}",
@@ -161,6 +194,7 @@ def build_prompt(product: dict, count: int, extra_rules: str = "") -> str:
angle_hint,
brand_rule,
custom,
benchmark_block,
f"\n【Q1随机变量池·每条身份/起因/小缺点各不相同,严格按下方分配使用】",
combos_text,
extra_rules,

View File

@@ -70,6 +70,23 @@ PAGE_ROLES = [
]
PAGE_ROLE_MAP = {r["role"]: r for r in PAGE_ROLES}
# ── R5多图分镜role → 优先产品图场景(scene) 偏好表 ──────────
# 生图时按分镜 role 选该场景的产品图当参考;取不到回落主图(primary)。
# scene 取值见 enums.ProductImageSceneprimary/scene/texture/ingredient/model
ROLE_SCENE_PREFERENCE = {
"hook": ["scene", "primary"], # 封面:真实生活场景优先
"pain_scene": ["scene", "primary"], # 痛点共鸣:使用前情境
"product_closeup": ["primary"], # 单品特写:白底主图
"ingredient": ["ingredient", "primary"], # 成分拆解:成分/包装细节
"texture": ["texture", "primary"], # 质地展示:质地特写
"applied_proof": ["model", "scene", "primary"], # 上脸:上脸图/场景
"social_proof": ["scene", "primary"], # 社交背书:场景
"closer": ["primary"], # 促单收尾:主图
"scenario": ["scene", "primary"],
"tutorial": ["model", "scene", "primary"],
}
# ── 生图风格预设(扒 image.js STYLE_PROMPTS:26-29──────────
# 按 style 参数选小红书风格调性,注入 base_prompt 的"视觉风格"行
STYLE_PROMPTS = {

View File

@@ -14,13 +14,36 @@ import logging
import os
from typing import Any, Protocol
from .constants import IMAGE_RETRY_ATTEMPTS, IMAGE_RETRY_BACKOFF_BASE, IMAGE_SIZE_DEFAULT
from .constants import IMAGE_RETRY_ATTEMPTS, IMAGE_RETRY_BACKOFF_BASE, IMAGE_SIZE_DEFAULT, ROLE_SCENE_PREFERENCE
from .image_scorer import score_image
from .storyboard import plan_image_set, sanitize_text
logger = logging.getLogger(__name__)
def _pick_reference_for_role(
role: str,
images_by_scene: dict[str, list[bytes]] | None,
fallback: list[bytes] | None,
) -> tuple[list[bytes] | None, str]:
"""R5多图按分镜 role 选该场景的产品图。取不到回落主图。
返回 (参考图bytes列表, 命中scene标签用于日志)。
"""
if images_by_scene:
for scene in ROLE_SCENE_PREFERENCE.get(role, ["primary"]):
imgs = images_by_scene.get(scene)
if imgs:
return imgs, scene
# 偏好全落空:用任意可用图兜底(仍优先 primary
if images_by_scene.get("primary"):
return images_by_scene["primary"], "primary"
for scene, imgs in images_by_scene.items():
if imgs:
return imgs, f"{scene}(兜底)"
return fallback, "fallback"
class ImageClient(Protocol):
"""worker 注入的图片生成客户端协议(隔离 key 细节)"""
async def gpt_edits(
@@ -129,12 +152,18 @@ async def generate_storyboard_images(
strategy: str | None = None,
target_role: str | None = None,
custom_prompt: str | None = None,
images_by_scene: dict[str, list[bytes]] | None = None,
flywheel_fragment: str | None = None,
) -> list[dict]:
"""
按 storyboard 逐张生图asyncio.gather 并发),返回每张结果列表。
strategy: None=默认叙事,'A'/'B'/'C'=三套正交叙事策略
target_role: 非空时只生成该 role 那一张R2 单张重生)
custom_prompt: 非空时追加到每张 per_prompt 末尾R2 人工提示词)
images_by_scene: R5多图{scene: [bytes]},按分镜 role 选对应场景图;
为空则全分镜共用 reference_images向后兼容
flywheel_fragment: R7 飞轮偏好片段(最近选图/打回真实信号聚合),注入图片
排版偏好;仅影响文字角度/版式取向,绝不改瓶身(合规红线)。
每项:{role, name, image_bytes, error}
"""
plan = plan_image_set(note, product, image_count, analysis, strategy=strategy)
@@ -169,8 +198,20 @@ async def generate_storyboard_images(
# R2 人工提示词:追加到末尾权重最高,但不覆盖前面合规/真实约束
if custom_prompt:
per_prompt += f"\n运营补充要求(在不违反上述合规与真实约束前提下尽量满足):{sanitize_text(custom_prompt, 200)}"
# R7 飞轮偏好:仅作用于文字角度/版式取向参考,绝不改瓶身(合规+真实红线)
if flywheel_fragment:
per_prompt += (
f"\n历史偏好参考(仅影响标题文字角度与排版取向,不得据此改动产品瓶身):"
f"{sanitize_text(flywheel_fragment, 300)}"
)
try:
img_bytes = await generate_one_image(client, per_prompt, reference_images)
# R5多图按本张分镜 role 选对应场景产品图;无多图则共用 reference_images
ref_for_item, _scene_hit = _pick_reference_for_role(
item["role"], images_by_scene, reference_images
)
if images_by_scene:
logger.info("分镜 %s 选用产品图场景=%s", item["role"], _scene_hit)
img_bytes = await generate_one_image(client, per_prompt, ref_for_item)
# 注gpt-image-2 渲染中文偶发错别字(约1/6)。vision/OCR 文字校验闸门实测
# 不可靠(漏报形近字+幻觉误伤品牌词),倩倩姐2026-06-16拍板先撤,纯生图,
# 错别字作已知问题记录,后续迭代再处理。详见记忆 clover-image-text-check-shelved。

View File

@@ -52,7 +52,8 @@ def aggregate_preference_context(
weight = int(e.get("signal_weight", 1))
# text_edit(改稿)是最强真实信号,角度按权重计入(倩倩姐2026-06-16拍板)
if sig_type in ("text_select", "approve", "text_edit") and angle:
# image_select(选图)按套别叙事角度计入,让选图偏好真正闭环回生图(R7断点2)
if sig_type in ("text_select", "approve", "text_edit", "image_select") and angle:
angle_counts[angle] += weight
elif sig_type == "reject_with_reason":
reason = str(e.get("reason") or "").strip()