feat: 试用过程中的细节优化
This commit is contained in:
@@ -36,10 +36,11 @@ def prompt_family(provider: str, model: str | None) -> str:
|
||||
|
||||
def build_prompt(provider: str, model: str | None, type_id: str, ctx: dict, style_set: int,
|
||||
lang: str, extra: dict | None = None, style_prompt: str | None = None,
|
||||
requirements: str | None = None) -> str:
|
||||
requirements: str | None = None, requirements_exclusive: bool = False) -> str:
|
||||
"""按模型家族构造指定图类型的完整生图 prompt。参数含义见各家族 build_prompt。"""
|
||||
module = _MODULE_BY_FAMILY[prompt_family(provider, model)]
|
||||
return module.build_prompt(
|
||||
type_id, ctx, style_set, lang,
|
||||
extra=extra, style_prompt=style_prompt, requirements=requirements,
|
||||
requirements_exclusive=requirements_exclusive,
|
||||
)
|
||||
|
||||
@@ -96,12 +96,13 @@ def _prompt_ecommerce_detail(ctx: dict, style: dict, lang: str) -> str:
|
||||
|
||||
def _prompt_size_chart(ctx: dict, style: dict, lang: str) -> str:
|
||||
dims = params_line_for_output(ctx, lang)
|
||||
annotation = ctx.get("dimension_annotation_instruction") or "Do not invent measurement directions or values."
|
||||
return (
|
||||
f"Product size chart infographic for \"{ctx['title']}\": product shown in clean front and side views "
|
||||
f"on light background, with thin measurement annotation lines (arrows) marking length, width and height, "
|
||||
f"on light background, with thin measurement annotation lines (arrows) only for supplied dimensions, "
|
||||
f"measurement values rendered next to each line"
|
||||
+ (f" (known specs: {dims})" if dims else "")
|
||||
+ f", small caption row, precise technical drawing aesthetic. {style['tone']}. "
|
||||
+ f". {annotation} Small caption row, precise technical drawing aesthetic. {style['tone']}. "
|
||||
f"{TEXT_RENDER[lang]} {QUALITY} {PRODUCT_REF_LOCK}"
|
||||
)
|
||||
|
||||
@@ -136,7 +137,8 @@ _PROMPT_BUILDERS = {
|
||||
|
||||
|
||||
def build_prompt(type_id: str, ctx: dict, style_set: int, lang: str, extra: dict | None = None,
|
||||
style_prompt: str | None = None, requirements: str | None = None) -> str:
|
||||
style_prompt: str | None = None, requirements: str | None = None,
|
||||
requirements_exclusive: bool = False) -> str:
|
||||
"""构造指定图类型的完整生图 prompt(主体参考语义)。
|
||||
|
||||
extra: 方案项信息 {title, detail, prompt_hint}——custom 类型必需,
|
||||
@@ -145,6 +147,15 @@ def build_prompt(type_id: str, ctx: dict, style_set: int, lang: str, extra: dict
|
||||
requirements: 生图要求(最高优先级,强制约束),置于 prompt 最前面,
|
||||
声明覆盖一切冲突指令,用户可在此输入强制要求。
|
||||
"""
|
||||
if requirements_exclusive:
|
||||
return " ".join([
|
||||
requirements_block(requirements),
|
||||
"Execute only the strict requirements above. Do not add marketing layouts, captions, overlays, "
|
||||
"props, default studio styling, or visible text unless explicitly requested.",
|
||||
"Preserve the reference image exactly unless the strict requirements explicitly request a "
|
||||
"specific change. When they do, make only that requested change and preserve everything else.",
|
||||
"Do not make any change that was not explicitly required.",
|
||||
])
|
||||
style = resolve_style(style_set, style_prompt)
|
||||
extra = extra or {}
|
||||
if type_id == "custom":
|
||||
|
||||
@@ -134,11 +134,28 @@ def build_context(raw: dict, fallback_name: str = "", fallback_desc: str = "") -
|
||||
break
|
||||
|
||||
dimensions = raw.get("dimensions") or {}
|
||||
dimension_values = (dimensions.get("length"), dimensions.get("width"), dimensions.get("height")) if isinstance(dimensions, dict) else ()
|
||||
dimensions_line = ""
|
||||
if len(dimension_values) == 3 and all(value is not None for value in dimension_values):
|
||||
unit = dimensions.get("unit") or "mm"
|
||||
dimensions_line = "L × W × H: " + " × ".join(str(value) for value in dimension_values) + f" {unit}"
|
||||
known_dimensions: list[tuple[str, object]] = []
|
||||
if isinstance(dimensions, dict):
|
||||
known_dimensions = [
|
||||
(label, dimensions[key]) for key, label in (("length", "length"), ("width", "width"), ("height", "height"))
|
||||
if dimensions.get(key) is not None
|
||||
]
|
||||
unit = (dimensions.get("unit") or "mm") if isinstance(dimensions, dict) else "mm"
|
||||
dimensions_line = "; ".join(f"{label}: {value} {unit}" for label, value in known_dimensions)
|
||||
known_labels = [label for label, _ in known_dimensions]
|
||||
missing_labels = [label for label in ("length", "width", "height") if label not in known_labels]
|
||||
dimension_annotation_instruction = (
|
||||
"STRICT MEASUREMENT OUTPUT RULE: render exactly "
|
||||
+ str(len(known_labels))
|
||||
+ " measurement arrows and labels, only for: "
|
||||
+ ", ".join(known_labels)
|
||||
+ ". The only permitted dimension values are: "
|
||||
+ dimensions_line
|
||||
+ ". Do not infer product measurements. Do not draw, label, or show an arrow for: "
|
||||
+ ", ".join(missing_labels or ["any additional direction"])
|
||||
+ ", depth, thickness, diameter, or any other unlisted dimension."
|
||||
if known_dimensions else ""
|
||||
)
|
||||
params_line = "; ".join(
|
||||
f"{p.get('key')}: {p.get('value')}" for p in (raw.get("params") or [])[:8]
|
||||
)
|
||||
@@ -158,6 +175,7 @@ def build_context(raw: dict, fallback_name: str = "", fallback_desc: str = "") -
|
||||
dimensions_line,
|
||||
))),
|
||||
"price": raw.get("price") or "",
|
||||
"dimension_annotation_instruction": dimension_annotation_instruction,
|
||||
}
|
||||
|
||||
def selling_point_lines(ctx: dict, lang: str, max_n: int = 3) -> str:
|
||||
|
||||
@@ -98,12 +98,13 @@ def _task_ecommerce_detail(ctx: dict, lang: str) -> str:
|
||||
|
||||
def _task_size_chart(ctx: dict, lang: str) -> str:
|
||||
dims = params_line_for_output(ctx, lang)
|
||||
annotation = ctx.get("dimension_annotation_instruction") or "Do not invent measurement directions or values."
|
||||
return (
|
||||
"Create a size chart: the unchanged product in clean front and side views on a light background, "
|
||||
"thin measurement annotation lines (arrows) marking length, width and height with values beside "
|
||||
"thin measurement annotation lines (arrows) only for supplied dimensions with values beside "
|
||||
"each line"
|
||||
+ (f" (known specs: {dims})" if dims else "")
|
||||
+ ", small caption row, precise technical-drawing aesthetic."
|
||||
+ f". {annotation} Small caption row, precise technical-drawing aesthetic."
|
||||
)
|
||||
|
||||
def _task_sku_collection(ctx: dict, lang: str) -> str:
|
||||
@@ -128,8 +129,19 @@ _TASK_BUILDERS = {
|
||||
|
||||
|
||||
def build_prompt(type_id: str, ctx: dict, style_set: int, lang: str, extra: dict | None = None,
|
||||
style_prompt: str | None = None, requirements: str | None = None) -> str:
|
||||
style_prompt: str | None = None, requirements: str | None = None,
|
||||
requirements_exclusive: bool = False) -> str:
|
||||
"""构造指定图类型的 prompt:要求块 → 指令 → 主体锁 → 锚定 → 风格 → 文案 → 画质 → 提醒。"""
|
||||
if requirements_exclusive:
|
||||
return "\n\n".join([
|
||||
requirements_block(requirements),
|
||||
"Edit the first image only as required above. Do not add marketing layouts, captions, overlays, "
|
||||
"props, default studio styling, or visible text unless explicitly requested above.",
|
||||
"PROTECTION: preserve the first image exactly unless the strict requirements explicitly request "
|
||||
"a specific change. When they do, make only that requested change and preserve everything else.",
|
||||
"Final check: follow the strict requirements over every default behavior; do not make changes "
|
||||
"that were not explicitly required.",
|
||||
])
|
||||
style = resolve_style(style_set, style_prompt)
|
||||
extra = extra or {}
|
||||
hint = (extra.get("prompt_hint") or "").strip()
|
||||
|
||||
@@ -129,12 +129,13 @@ def _task_ecommerce_detail(ctx: dict, lang: str) -> str:
|
||||
|
||||
def _task_size_chart(ctx: dict, lang: str) -> str:
|
||||
dims = params_line_for_output(ctx, lang)
|
||||
annotation = ctx.get("dimension_annotation_instruction") or "Do not invent measurement directions or values."
|
||||
return (
|
||||
"TASK: Measurement chart. Show the unchanged product in clean front and side views on a light "
|
||||
"background; overlay thin technical annotation lines (arrows) marking length, width and height "
|
||||
"with measurement values rendered beside each line"
|
||||
"background; overlay thin technical annotation lines (arrows) only for the supplied dimensions, "
|
||||
"with each measurement value rendered beside its line"
|
||||
+ (f" (known specs: {dims})" if dims else "")
|
||||
+ "; precise technical-drawing aesthetic, small caption row."
|
||||
+ f". {annotation}; precise technical-drawing aesthetic, small caption row."
|
||||
)
|
||||
|
||||
def _task_sku_collection(ctx: dict, lang: str) -> str:
|
||||
@@ -160,8 +161,21 @@ _TASK_BUILDERS = {
|
||||
|
||||
|
||||
def build_prompt(type_id: str, ctx: dict, style_set: int, lang: str, extra: dict | None = None,
|
||||
style_prompt: str | None = None, requirements: str | None = None) -> str:
|
||||
style_prompt: str | None = None, requirements: str | None = None,
|
||||
requirements_exclusive: bool = False) -> str:
|
||||
"""构造指定图类型的 edits 语义 prompt:要求块 → 编辑指令 → 保真锁 → 锚定 → 风格 → 文案 → 画质 → 终检。"""
|
||||
if requirements_exclusive:
|
||||
# 单张 AI 编辑:用户要求是唯一的画面意图,绝不能被套图的营销图/棚拍/俄文文案覆盖。
|
||||
return "\n\n".join([
|
||||
requirements_block(requirements),
|
||||
"TASK: Edit Image 1 only according to the STRICT REQUIREMENTS above. Do not add marketing "
|
||||
"layouts, captions, overlays, props, default studio styling, or any visible text unless the "
|
||||
"STRICT REQUIREMENTS explicitly ask for them.",
|
||||
"PROTECTION: preserve Image 1 exactly unless the STRICT REQUIREMENTS explicitly request a "
|
||||
"specific change. When they do, make only that requested change and preserve everything else.",
|
||||
"FINAL CHECK: follow the STRICT REQUIREMENTS over every default behavior. Preserve the product "
|
||||
"and do not make any change that is not explicitly required.",
|
||||
])
|
||||
style = resolve_style(style_set, style_prompt)
|
||||
extra = extra or {}
|
||||
hint = (extra.get("prompt_hint") or "").strip()
|
||||
|
||||
Reference in New Issue
Block a user