[WIP] AI content with paragraphs generation#1018
[WIP] AI content with paragraphs generation#1018andreytroeglazov wants to merge 10 commits intomainfrom
Conversation
|
Wow! 💪 |
|
Later we can move this form to be on the top of |
Fixed some problems, tuned promt a bit. @amitaibu right now it uses only paragraphs without references to other content on the site |
|
"I have a marvel comics event, need a page for this" Promt for above page ^^ |
web/modules/custom/server_ai_content/src/Service/ContentGenerator.php
Outdated
Show resolved
Hide resolved
web/modules/custom/server_ai_content/src/Service/ParagraphSchemaDiscovery.php
Outdated
Show resolved
Hide resolved
web/modules/custom/server_ai_content/src/Service/ContentGenerator.php
Outdated
Show resolved
Hide resolved
web/modules/custom/server_ai_content/tests/src/ExistingSite/AiContentGenerateFormTest.php
Outdated
Show resolved
Hide resolved
web/modules/custom/server_ai_content/src/Form/AiContentGenerateForm.php
Outdated
Show resolved
Hide resolved
web/modules/custom/server_ai_content/src/Service/ContentGenerator.php
Outdated
Show resolved
Hide resolved
web/modules/custom/server_ai_content/tests/src/ExistingSite/ContentGeneratorTest.php
Outdated
Show resolved
Hide resolved
|
|
web/modules/custom/server_ai_content/src/Service/ContentGenerator.php
Outdated
Show resolved
Hide resolved
web/modules/custom/server_ai_content/src/Service/ContentGenerator.php
Outdated
Show resolved
Hide resolved
web/modules/custom/server_ai_content/src/Form/AiContentGenerateForm.php
Outdated
Show resolved
Hide resolved
web/modules/custom/server_ai_content/src/Service/ContentGenerator.php
Outdated
Show resolved
Hide resolved
web/modules/custom/server_ai_content/tests/src/ExistingSite/ContentGeneratorTest.php
Outdated
Show resolved
Hide resolved
|
web/modules/custom/server_ai_content/src/Form/AiContentGenerateForm.php
Outdated
Show resolved
Hide resolved
web/modules/custom/server_ai_content/src/Service/ContentGenerator.php
Outdated
Show resolved
Hide resolved
web/modules/custom/server_ai_content/src/Form/AiContentGenerateForm.php
Outdated
Show resolved
Hide resolved
web/modules/custom/server_ai_content/src/Service/ContentGenerator.php
Outdated
Show resolved
Hide resolved
web/modules/custom/server_ai_content/src/Service/ContentGenerator.php
Outdated
Show resolved
Hide resolved
web/modules/custom/server_ai_content/src/Service/ContentGenerator.php
Outdated
Show resolved
Hide resolved
web/modules/custom/server_ai_content/src/Service/ContentGenerator.php
Outdated
Show resolved
Hide resolved
web/modules/custom/server_ai_content/src/Service/ParagraphSchemaDiscovery.php
Outdated
Show resolved
Hide resolved
web/modules/custom/server_ai_content/src/Service/ContentGenerator.php
Outdated
Show resolved
Hide resolved
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) |
We send titles + ids to it, so it picks relevant to promt. |
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 { |
There was a problem hiding this comment.
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
Found it I have some ideas on how to prevent it from exploding if we get too many items, but that could be a follow up |
50 only for now, I haven't thought how to get relevant list for AI yet |






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_aiWhat 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_aiexplicitly 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'sGetParagraphFieldInformationplugin 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 theGetParagraphFieldInformation,GetParagraphFieldConfigForm, andCreateParagraphBundlefunction-call plugins.3.
drupal/ai_interpolatorWhat 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_ecaWhat 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/aiWhat it does: A custom module (
server_ai_content) with an admin form at/admin/content/ai-generatewhere the user types a prompt. AParagraphSchemaDiscoveryservice usesparagraphs_ai'sGetParagraphFieldInformation(from patch #3580185) to dynamically discover available paragraph types and their fields. AContentGeneratorservice sends one structured GPT-4o call (via
drupal/aiprovider 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:
Why this approach:
drupal/aifor OpenAI calls (already configured),paragraphs_aifor schema discovery (with patch #3580185)