clipwright/clipwright/pipeline/profile_prompts.py

125 lines
5 KiB
Python

"""Profile -> prompt fragments (PLAN #1, full).
The single mapping between a channel :class:`~clipwright.pipeline.profiles.Profile`
and the text the generators read. Both generation paths use it and nothing else:
* the clipping path (``gemini_worker.DETAIL_PROMPT_TEMPLATE``, via ``main.py``)
* the Studio path (``media/thumbnail.py``: titles, concepts, description)
Every helper is pure and accepts ``profile=None``; a ``None`` profile returns the
empty string, so a caller that was never given a channel renders exactly the
prompt it did before profiles existed. A non-empty block ends with a single ``\\n``
so it can be dropped onto its own line in an f-string without shifting anything
(an empty string leaves the line blank, byte-for-byte as today).
Keep the blocks short: they are constraints on an already-long prompt, not a
second prompt.
"""
from __future__ import annotations
from clipwright.pipeline.profiles import Profile
# Full sentences, keyed by the enums ``profiles.py`` validates. Kept here so a
# new enum value fails loudly (missing from the map) instead of silently
# dropping the constraint.
_KEYWORD_POSITION_TEXT = {
"start": "Put the main keyword or subject in the first 3 words",
"middle": "Put the main keyword or subject near the middle",
"end": "Put the main keyword or subject at the end",
"any": "Place the main keyword or subject wherever it reads best",
}
_NUMBER_POLICY_TEXT = {
"allow": "Numbers are allowed when they earn attention",
"avoid": "Avoid numbers unless a number is the point",
"require": "Every title must contain a concrete number",
}
_REQUIRED_SIGNAL_TEXT = {
"consequence": "Every title must carry a concrete consequence or stake",
"curiosity": "Every title must open a curiosity gap the video pays off",
"either": "Every title must carry a consequence or a curiosity gap",
"none": "",
}
def _quoted(items):
return "; ".join(f'"{item}"' for item in items)
def title_rules_block(profile: Profile | None) -> str:
"""Title constraints: length, banned content, keyword/number/signal policy, tone."""
if profile is None:
return ""
rules = profile.title_rules
lines = ["CHANNEL TITLE RULES:"]
if profile.tone:
lines.append(f"- Tone: {profile.tone}.")
lines.append(
f"- Hard maximum {rules.max_chars} characters; the payoff must land inside "
f"the first {rules.mobile_chars} (phones truncate there).")
position = _KEYWORD_POSITION_TEXT.get(rules.keyword_position)
if position:
lines.append(f"- {position}.")
signal = _REQUIRED_SIGNAL_TEXT.get(rules.required_signal)
if signal:
lines.append(f"- {signal}.")
number = _NUMBER_POLICY_TEXT.get(rules.number_policy)
if number:
lines.append(f"- {number}.")
if rules.banned_patterns:
lines.append(f"- Never use the phrases: {_quoted(rules.banned_patterns)}.")
if rules.banned_openers:
lines.append(f"- Never open a title with: {_quoted(rules.banned_openers)}.")
return "\n".join(lines) + "\n"
def hook_block(profile: Profile | None) -> str:
"""Hook style and the patterns the channel already knows work."""
if profile is None:
return ""
lines = []
if profile.hook_style:
lines.append(f"- Hook style: {profile.hook_style}.")
if profile.hook_patterns:
lines.append(f"- Patterns that work for this channel: {_quoted(profile.hook_patterns)}.")
if not lines:
return ""
return "CHANNEL HOOK RULES:\n" + "\n".join(lines) + "\n"
def description_block(profile: Profile | None) -> str:
"""Description structure, the channel's links and its tone."""
if profile is None:
return ""
lines = []
if profile.description_template:
template = profile.description_template.replace("\n", "\\n")
lines.append(f'- Follow this structure for the blurb: "{template}".')
if profile.links:
lines.append(f"- Include these links: {', '.join(profile.links)}.")
if profile.tone:
lines.append(f"- Tone: {profile.tone}.")
if not lines:
return ""
return "CHANNEL DESCRIPTION RULES:\n" + "\n".join(lines) + "\n"
def thumbnail_block(profile: Profile | None) -> str:
"""Thumbnail roles, palette and whether a presenter photo is expected."""
if profile is None:
return ""
thumb = profile.thumbnail
lines = []
if thumb.role_order:
lines.append(f"- Concept roles, in priority order: {', '.join(thumb.role_order)}.")
if thumb.palette:
lines.append(f"- Palette: {', '.join(thumb.palette)}.")
presenter = ("available and encouraged" if thumb.presenter_photo
else "not expected; prefer objects, scenes or symbols")
lines.append(f"- Presenter photo is {presenter}.")
return "CHANNEL THUMBNAIL RULES:\n" + "\n".join(lines) + "\n"
def clip_rules_block(profile: Profile | None) -> str:
"""The clipping path's block: hook guidance then title constraints."""
return hook_block(profile) + title_rules_block(profile)