Generators & providers¶
The generation core turns a GenerationTask into the exact payload its matching
CmsPublisher method expects, then publishing writes it to the CMS. Generators
are pure with respect to the outside world; publishing is a separate step.
The Generator pipeline¶
Every entity generator subclasses generation/generators/base.py::Generator and
runs a fixed pipeline:
| Step | Method | What it does |
|---|---|---|
| context | build_context |
Resolve site name/id/title/niche from task + job; subclasses extend it (e.g. the article generator adds ledger avoidance titles; settings_tune adds the site's real categories) |
| prompt | prompt |
The per-entity provider prompt. Bodies come from the ai_prompt_templates table when an active row exists, else a per-entity default string |
| provider | run |
Resolve the text provider via the registry (request override → template default → registry default) and call generate |
| coerce | _coerce_content |
Rename aliased keys and normalize shape variance on a real result before validation (see below) |
| validate | validate |
Stub results are trusted; real results are schema-checked (required keys) plus per-entity quality gates |
| normalize | normalize |
Merge extracted provider fields over the deterministic context-derived default_payload |
Under the stub provider the result carries no real fields, so normalize
falls back to the deterministic default_payload -- that is what lets the styled
shell come up green with no live provider key. The real path (stubs off) merges
structured provider fields over those defaults.
The generators¶
| Generator | Entity | Provider | Normalizes to |
|---|---|---|---|
SettingsGenerator |
settings |
text | SiteSettingsUpdate (meta title/desc, language, footer, nav, cdn_base_url) |
LogoGenerator |
logo |
image | icon_url / default_favicon media paths |
TaxonomyGenerator |
taxonomy |
text | category list |
StyleGenerator |
style |
(assign) | style_slug of an existing style |
TemplateGenerator |
template |
(assign) | template_id of an existing template |
PageTypeGenerator |
page_type |
text | page-type descriptors |
ArticleGenerator |
article |
text | ContentCreate (title, slug, content_blocks, SEO, taxonomy) + image_briefs |
ImageGenerator |
image |
image | uploaded media_path (one child per brief) |
SeoEnrichGenerator |
seo_enrich |
text | SEO subset (seo_title, seo_description, og_*, canonical_url, schema_type, noindex) |
SettingsTuneGenerator |
settings_tune |
(deterministic) | navigation from real taxonomy + ads/robots passthrough |
Article generation¶
ArticleGenerator (generators/article.py) is the Phase-2 content engine.
run dispatches to the configured article-source strategy
(generation/sources/) named by params.source:
ai_generate(default) -- fresh generation via the text provider.wp_import-- WordPress → CMS (MySQL primary + REST fallback; HTML →content_blocksviageneration/converters.py).cms_copy-- CMS → CMS (GET /admin/v1/content/{id}).
All three feed the same publish path and the same {content_create, image_briefs}
shape.
Quality gates (real results): non-empty title, no control chars, no
placeholder tokens, and a title-similarity check against the ai_content_ledger
avoidance list (rejects near-duplicates ≥ 0.9). Body word count is bounded
(20–4000), no <script>, and at least one featured image brief is required.
Dedup / avoidance: the context carries recent ledger titles for
(site, category) (a single query); run short-circuits an already-made
(site_ref, title_hash|slug) so a re-run makes no duplicate content.
Providers¶
Two registries (generation/providers/registry.py), split by modality. Selection
precedence is request override → prompt-template default → registry default.
Text providers¶
| Provider | name |
Default model | Notes |
|---|---|---|---|
OpenAIProvider |
openai |
gpt-4o |
Registry default. Credentials from the harvester ai_accounts rows (keyed by account_id) at call time, never stored |
ClaudeProvider |
claude |
(Anthropic) | Resolves its key from /common/cms-ai-forge/anthropic inside a try/except; a missing key returns a stubbed "key not provided" result instead of raising. Reserved for a later code-gen phase -- not the content default |
Why OpenAI is the text default
Content generation reuses the OpenAI pipeline backed by the harvester
ai_accounts. Claude has no key wired for content, so it must not be the
content default (AISD-152).
Image providers¶
Claude cannot generate images, so image generation is a separate provider family.
| Provider | name |
Default model | Notes |
|---|---|---|---|
OpenAIImageProvider |
openai_image |
gpt-image-1 |
Real image generation (NOT DALL-E). Normalizes the dual-shape response ({"url"} / {"b64"}) to bytes; a brief carrying source_url (the migration strategies) is fetched directly rather than generated |
PlaceholderImageProvider |
placeholder |
-- | Registry default. Deterministic 1×1 PNG; no network. Used to exercise the media path under stubs |
Logo generation uses the real image model¶
LogoGenerator explicitly resolves the openai_image provider (gpt-image),
not the placeholder square (AISD-170). With stubs on it returns deterministic stub
media paths and performs no upload; with stubs off it generates a horizontal
wordmark logo and a square monogram favicon via gpt-image and uploads both
through MediaPublisher, returning icon_url / default_favicon.
Publishing¶
CmsPublisher (publishing/cms_publisher.py) authenticates once as the forge
service account (POST /admin/v1/auth/login; refresh-then-relogin on 401) and
maps each entity to its admin endpoint. Every write is idempotent -- GET-by-lookup
then POST/PATCH, deterministic slug matching by cursor-paging the content list
(the list endpoint has no slug filter), and an Idempotency-Key header derived
from task_id + step.
MediaPublisher uploads image bytes to cms-media (prd) / cms-media-stg
(stage) and returns the relative media path the CMS stores; cms-api
absolutizes it against cdn_base_url on read.
Article image chord¶
At an article's validated → assets_ready step the entity worker spawns one
image child per brief and dispatches them as a Celery chord whose callback
(finalize_article_assets) wires the featured + inline images onto the article
and re-enqueues its publish. publish_task claims the pre-publish transition
before any network call (an atomic guarded UPDATE), so the slug POST is
exactly-once even when both the chord callback and the last image child's
in-drive completion race to finalize.