V3 Phase 2: Content Guard + Story Engine + audience profiles#11
Merged
Conversation
CONTENT GUARD (scripts/content_guard.py) - 80+ regex rules covering 5 hard-block categories: - 广告法极限词 (最/第一/唯一/万能/顶级 …) - Off-platform diversion (微信/VX/wx/QQ/phone/外站 URL/二维码 …) - 医美/医疗功效 (治愈/祛斑/水光针/医生同款 …) - 财富诱导 (年入/月入/躺赚/财富自由 …) - Soft-warn rules: title>20 chars, !!! runs, emoji density >30 %, caption>800 - enforce() raises HardBlock / SoftWarn; scan_text() returns Violation list - CLI: `python3 scripts/content_guard.py --title T --script S --strict` - Wired into render_final.py: HARD violations halt export with exit 2, --no-content-guard escape hatch for emergencies STORY ENGINE (scripts/rewrite_script.py + prompts/) - 8 hook templates in prompts/hook_templates.yaml (反常识/痛点/数字/悬念/ 身份/反差/利益/场景) - 5 CTA templates in prompts/cta_templates.yaml weighted by Xiaohongshu CES score (关注 8 > 评论/分享 4 > 收藏/点赞 1) - 3 structures: pain_solve / story_reversal / listicle - emit_prompt() produces a structured LLM prompt; validate_llm_output() enforces the 5-field schema (hook/pain/turn/value[]/cta) and hooks the content guard before materialising the clean_script.md AUDIENCE PROFILES (scripts/profiles/) - tech_pro.yaml — AI/创业/efficiency vertical: 90s default, -16dB BGM, 64px subtitles, Heavy fonts, 3:4 Xiaohongshu / 9:16 抖音 export - lifestyle.yaml — vlog/穿搭/家居: 60s default, -10dB BGM, slower pacing - profiles.__init__ provides load_profile() + list_profiles() with a PyYAML-optional reader (zero new hard deps) - render_final.py `--profile tech_pro` flag overlays defaults onto fields the user didn't pass Tests: +56 (38 content guard, 5 profiles, 10 story engine, 3 render integration). Full suite 82 passing.
5 tasks
5 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes part of #10.
Summary
Three new subsystems land in this PR. They're independent enough to ship
together but each is fully self-contained.
1. Content Guard (
scripts/content_guard.py)Xiaohongshu/RED platform-rule lint. 80+ regex covering:
Two violation levels: HARD (refuse export) / SOFT (warn). Wired into
render_final.pyso the render aborts before any expensive work if thetitle or chapters trip a hard rule. Override with
--no-content-guard.2. Story Engine (
scripts/rewrite_script.py)LLM-driven script rewriter. Doesn't ship an LLM client — produces a
structured prompt the user pipes into Claude/ChatGPT, then validates
the JSON the LLM returns and materialises it into
clean_script.md.scripts/prompts/hook_templates.yaml): 反常识 /痛点 / 数字 / 悬念 / 身份 / 反差 / 利益 / 场景
scripts/prompts/cta_templates.yaml) weighted by小红书 CES (关注 8 > 评论/分享 4 > 收藏/点赞 1)
3. Audience profiles (
scripts/profiles/)tech_pro.yaml— AI/创业/effort verticallifestyle.yaml— vlog/穿搭/家居Each encodes default duration, cut frequency, subtitle density, font
preference, BGM gain, target aspect ratio. Loaded by
load_profile(name).render_final.py --profile tech_prooverlaysdefaults onto fields the user didn't pass via CLI.
PyYAML-optional reader so fresh installs don't need extra deps.
Tests
+56 new (38 content-guard, 5 profiles, 10 story-engine, 3 integration).
Full suite: 82 passing.
Test plan
pytest tests/greenpython3 scripts/content_guard.py --title "全网最低价"returns 1python3 scripts/content_guard.py --title "AI 失业焦虑?我看到机会"returns 0python3 scripts/render_final.py --helpshows--profile,--no-content-guardtitle=加微信 wx123→ hard-block exit code 2