fix(ai-outfit): 标题解析改为「按逗号分割」,避开 Markdown 表格坑 (§19.23)

实测模型常返回 Markdown 表格(編號/標題/字元數估算 三列),按行解析会把
表头/分隔线/带 | 数字的行当成标题,写进 Excel A 全是「| 編號 | 標題 | … |」。
改用「提示词约定标题逗号分隔 + 解析按逗号拆分」,简单可靠。

- ai_text_service._clean_titles:从按行拆改为按逗号拆(半角 , / 全角 ,,
  换行作兜底分隔),每段走 _clean_title_line 去空白/序号/引号、丢空
- config_service.DEFAULT_TITLE_PROMPT:改逗号分隔风格,明确禁 Markdown 表格/
  换行/序号/編號/字元數/引号/表情
- extract_text_from_response(取首条)、generate_texts/generate_titles/
  _TitleWorker 均不变

测试:逗号分隔(全角/半角)→ 多条;逗号+换行混用都拆开;逐段去序号/引号;
Markdown 表头单行不再炸成多条垃圾。全套 py37 通过(test_config_service 的
packaging 模板失败属并行 §19.13,与本改动无关)。离屏冒烟:逗号响应解析 +
按序回填 Excel A。

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This commit is contained in:
2026-06-23 16:24:34 +08:00
co-authored by Claude Opus 4.8
parent e7fab724fc
commit 61d8e20d86
5 changed files with 64 additions and 19 deletions
+12 -5
View File
@@ -34,6 +34,8 @@ class AiTextServiceError(RuntimeError):
_TITLE_LEAD = re.compile(r"^\s*(?:\d+\s*[\.\)、::]|[-*•])\s*")
_TITLE_CIRCLED = "①②③④⑤⑥⑦⑧⑨⑩"
_TITLE_QUOTES = "\"'「」『』“”‘’"
# Split titles on comma (half/full width) or newline (docs/11 §17.1 / §19.23).
_TITLE_SPLIT = re.compile(r"[,,\r\n]+")
def build_text_payload(config, prompt, image_data_url=None):
@@ -129,21 +131,26 @@ def _clean_title_line(line):
def _clean_titles(text):
"""Split raw text into a list of cleaned titles (one per non-empty line)."""
"""Split raw text into a list of cleaned titles, on comma (or newline).
The prompt asks the model to comma-separate titles (docs/11 §17.1 / §19.23);
splitting on `,`/`,`/newline avoids the Markdown-table mis-parse that line
splitting produced.
"""
if not text:
return []
out = []
for line in str(text).splitlines():
cleaned = _clean_title_line(line)
for piece in _TITLE_SPLIT.split(str(text)):
cleaned = _clean_title_line(piece)
if cleaned:
out.append(cleaned)
return out
def extract_titles_from_response(data):
"""Return all clean titles (one per non-empty line) from an AI JSON response.
"""Return all clean titles from an AI JSON response (comma-split, §17.1/§19.23).
Used by 批量标题生成 (docs/11 §17.1): one request → many titles.
Used by 批量标题生成: one request → many titles.
"""
return _clean_titles(_extract_raw_text(data))
+6 -5
View File
@@ -44,12 +44,13 @@ DEFAULT_OUTFIT_PROMPT = (
"电商主图风格,不加文字与促销标签。"
)
# Default title prompt (docs/11 §17.3, batch style). Used when title_prompt.txt absent.
# 数量由用户改写(如「生成 10 条」);一次请求返回多条、按序回填各行 A(§17.1)。
# Default title prompt (docs/11 §17.3, batch + comma-separated). Used when title_prompt.txt absent.
# 数量由用户改写(如「生成 10 条」);一次请求返回多条、按逗号拆分后按序回填各行 A(§17.1/§19.23)。
DEFAULT_TITLE_PROMPT = (
"请生成 10 条适合台湾蝦皮电商的中文女装商品标题,每行一条,"
"突出卖点与适穿场景,每条控制在 30 字以内。"
"只输出标题本身、每行一条,不要序号、引号、表情或促销词。"
"请生成 10 条适合台湾蝦皮电商的中文女装商品标题,突出卖点与适穿场景,"
"每条控制在 30 字以内。"
"标题之间用逗号「,」分隔,只输出标题本身,"
"不要使用 Markdown 表格、不要换行、不要序号/編號/字元數、不要引号或表情。"
)