Skip to content

[WIP] AI content with paragraphs generation#1018

Open
andreytroeglazov wants to merge 10 commits intomainfrom
ai-generation
Open

[WIP] AI content with paragraphs generation#1018
andreytroeglazov wants to merge 10 commits intomainfrom
ai-generation

Conversation

@andreytroeglazov
Copy link
Copy Markdown
Collaborator

Generated summary with claude of what I have discovered:

Summary of Evaluated Approaches

Module-Based Approaches

1. drupal/ai + AI Automators (submodule)

What it does: Configures chained, multi-step field population triggered on entity save. No code required.

Why not: Designed for populating existing fields on save, not for deciding which paragraph types to create and how many. Our use case requires structural decision-making — the AI must choose which paragraphs to generate and in what order. AI Automators can't orchestrate multi-entity creation with parent-child relationships.

2. drupal/ai_agents + drupal/paragraphs_ai

What it does: Plugin-based agent framework for text-to-action operations. Built-in agents create/edit content types, fields, taxonomies, and paragraph types. Provides a tool-use loop where the AI reasons and takes actions iteratively.

Why not for full generation: These are site-building agents — they manage configuration (create paragraph types, add fields), not content. paragraphs_ai explicitly states: "This agent can not create or edit paragraph content — only the paragraph types themselves." The agent loop also adds unnecessary latency (3-5 API round-trips) for what is essentially a single-shot generation task.

What we will use from it: paragraphs_ai's GetParagraphFieldInformation plugin for dynamic schema discovery — so our generator automatically knows about paragraph types and their fields without hardcoding. This requires applying the patch from #3580185 which adds the GetParagraphFieldInformation, GetParagraphFieldConfigForm, and
CreateParagraphBundle function-call plugins.

3. drupal/ai_interpolator

What it does: Predecessor to AI Automators — data transformation pipelines.

Why not: AI Automators (already in drupal/ai) is its evolution. No advantage over what's already installed.

4. drupal/openai (standalone module)

What it does: Original single-provider OpenAI integration with Drush content generation.

Why not: Community is shifting to drupal/ai (provider-agnostic). Would lock us to OpenAI only and duplicates functionality we already have.

5. drupal/eca + drupal/ai_integration_eca

What it does: Event-Condition-Action workflow builder with AI actions.

Why not: Overkill for this task. Better suited for complex event-driven workflows, not single-shot content generation.

6. Drupal Canvas AI

What it does: Visual page builder with AI assistant for generating complete pages.

Why not: Generates Canvas pages, not traditional nodes with paragraph entities. Different content architecture than our project uses.

Chosen Approach: Custom Form + Service using drupal/ai

What it does: A custom module (server_ai_content) with an admin form at /admin/content/ai-generate where the user types a prompt. A ParagraphSchemaDiscovery service uses paragraphs_ai's GetParagraphFieldInformation (from patch #3580185) to dynamically discover available paragraph types and their fields. A ContentGenerator
service sends one structured GPT-4o call (via drupal/ai provider abstraction) with the discovered schema + user prompt, parses the JSON response, creates paragraph entities (with DALL-E 3 images where needed), attaches them to a landing page node, and saves as draft. User is redirected to the unpublished node preview.

Example prompt:

Create me a landing page for the 2026 New Year celebration. Include a hero section, event details, FAQ section, and a call to action for registration.

Why this approach:

  • Simplest path
  • Uses existing infrastructuredrupal/ai for OpenAI calls (already configured), paragraphs_ai for schema discovery (with patch #3580185)
  • Single API call — GPT sees full page context, content flows naturally between sections, lower latency than agent loops
  • Dynamic schema — if paragraph types change, the generator picks it up automatically
  • Full control — we define exactly how entities are created and attached
  • POC-friendly — synchronous flow with spinner, can be extended later (batch processing, more content types, provider swapping)

@andreytroeglazov
Copy link
Copy Markdown
Collaborator Author

image Result: screencapture-drupal-starter-ddev-site-4443-world-rock-music-2026-04-02-16_19_16

Will push code soon, still testing.

TB: 2.4h investigation + 3.4h implementation

@amitaibu
Copy link
Copy Markdown
Member

amitaibu commented Apr 2, 2026

Wow! 💪

@amitaibu
Copy link
Copy Markdown
Member

amitaibu commented Apr 2, 2026

Later we can move this form to be on the top of /node/add -- so a content editor can decide to create manually, or just go with the form

@andreytroeglazov
Copy link
Copy Markdown
Collaborator Author

andreytroeglazov commented Apr 2, 2026

screencapture-drupal-starter-ddev-site-4443-marvel-comics-epic-crossover-event-2026-04-02-17_53_47

Fixed some problems, tuned promt a bit.

@amitaibu right now it uses only paragraphs without references to other content on the site

@andreytroeglazov
Copy link
Copy Markdown
Collaborator Author

"I have a marvel comics event, need a page for this"

Promt for above page ^^

@andreytroeglazov
Copy link
Copy Markdown
Collaborator Author

paragraphs_ai is not used anymore, it's done mostly for site building, even paragraphs schema lookup returns yaml which needs parsing and converting to a promt so I gave up on this and removed, as a result no external core dependencies except drupal/ai.

@amitaibu
Copy link
Copy Markdown
Member

amitaibu commented Apr 2, 2026

@andreytroeglazov
Copy link
Copy Markdown
Collaborator Author

Added "Generate with AI" button which redirects to promt form
Selection_097
Selection_098

Now it picks all paragraphs, including paragraph with entity reference fields (last paragraph on the screenshot).
screencapture-drupal-starter-ddev-site-4443-sustainable-urban-gardening-growing-green-city-2026-04-06-18_13_30

@amitaibu
Copy link
Copy Markdown
Member

amitaibu commented Apr 6, 2026

Now it picks all paragraphs, including paragraph with entity reference fields

How does AI know which content to reference?

Let's address the issues here, and then move dev to d.o. (but not create a release yet)
So this/ new PR will change to ddev composer require and a bunch of config

@andreytroeglazov
Copy link
Copy Markdown
Collaborator Author

How does AI know which content to reference?

We send titles + ids to it, so it picks relevant to promt.

@amitaibu
Copy link
Copy Markdown
Member

amitaibu commented Apr 6, 2026

We send titles + ids to it

Link to the code, please. Are we sending all titles/ IDs?

* @return \Drupal\media\MediaInterface|null
* The created media entity, or NULL on failure.
*/
protected function callDallE(string $image_prompt): ?MediaInterface {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We're relying on AI module now, so we don't know for sure consumer is going to use OpenAI, so name should change here

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed

@amitaibu
Copy link
Copy Markdown
Member

amitaibu commented Apr 6, 2026

Link to the code, please. Are we sending all titles/ IDs?

Found it

https://github.com/Gizra/drupal-starter/pull/1018/changes#diff-570568ad92386c50e86f5628955cf345ef21f68a490def60e3dcd33bfb8e2ab2R343

I have some ideas on how to prevent it from exploding if we get too many items, but that could be a follow up

@andreytroeglazov
Copy link
Copy Markdown
Collaborator Author

I have some ideas on how to prevent it from exploding if we get too many items, but that could be a follow up
Are we sending all titles/ IDs?

50 only for now, I haven't thought how to get relevant list for AI yet

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants