Tutorial: DRUPAL AI: generuj automatycznie treści i tagi z modułami #AI AUTOMATORS i FIELD WIDGET ACTIONS
Prerequisites
- A Drupal website
- Module AI (version 12 alpha)
- Module Field Widget Actions (included in AI module)
- Module AI Automators (dependent on Field Widget Actions)
- Basic knowledge of Drupal content types and form management
What You'll Learn
- Ability to automate content creation and tagging directly within Drupal.
- Streamlined workflow for news portals and content editors.
- Increased productivity in content generation.
- Understanding of how to configure Drupal modules (AI, Field Widget Actions, AI Automators) for AI integration.
- Knowledge of using prompts and tokens for AI-driven content.
- Awareness of broad applications of AI beyond simple text generation.
In this tutorial, you will learn how to automate content creation and tagging within Drupal using the AI, Field Widget Actions, and AI Automators modules. This written article will guide you through configuring your Drupal website to leverage AI for generating content and tags automatically, significantly streamlining your workflow. We will cover the necessary module installations and configurations to achieve these powerful automations.
Table of Contents
- Introduction and Problem Statement
- Technical Setup: Modules and Configuration
- Live Demonstration and Advanced Applications
- Conclusion and Call to Action
Step 1: Introduction and Problem Statement
Content Creation with AI in Drupal
Creating content for a news portal can be time-consuming, especially with tasks like research, writing, correction, SEO, and preparing tags. To streamline content creation, increase editorial productivity, and improve content quality, AI can automate large parts of this process directly within Drupal. This tutorial focuses on using AI for content generation, tagging, and information retrieval.
First, you'll see a quick demonstration of what you can achieve. A "matches" content type has been created. This content type includes fields for tags and buttons to generate tags, fetch squads, and fetch goal scorers.
- Generate Tags:
- Edit a match content entry.
- Click "Generate Tags." This will create relevant tags (e.g., "Jagiellonia," "football," "European cups").
- Fetch Squads:
- Click "Fetch Squads." A list of player squads will appear.
- To format this list, select the text, ensure "HTML" text format is chosen (if available), and select "Reformat."
- Fetch Goal Scorers:
- Click "Fetch Goal Scorers." A list of goal scorers will appear.
- Reformat this list similar to the squads.
This process provides a well-organized match description with tags, squads, and goal scorers.
The AI functionality is achieved using the "AI" module (version 12 alpha), specifically the "Field Widget Actions" submodule. This module integrates with "AI Automators."
To configure this:
- Navigate to "Structure" > "Content types."
- Select the "Match" content type (or your custom content type).
- For a specific field (e.g., the field associated with "Field Widget Actions"), enter the field's edit settings.
- Enable the "Enable AI automator" option.
- Select the basic AI configuration. The prompt can be left empty for general fields.
- Crucially, check the "Field widget" option.
- Save the settings.
For taxonomy fields (like tags), the process is similar but specific:
- In the field's settings, define the "Automator type" as appropriate (e.g., "tags").
- Enter a prompt, such as "create a maximum of three tags that will match the title." This ensures a specific number of tags.
- Check the "Field widget" option.
After configuring fields:
- Go to "Manage form display" for your content type.
- For fields like "Squads," you will find the "Field widget action" option added by the module.
- Add a new action.
- Configure the action:
- Choose an available AI model (e.g., "Open AI GPT 4O search preview").
- Define a prompt for the action. For fetching squads, the prompt could be: "Based on the Note Title (which is the match name), tell me the team squads. Format the data as a list."
- Specify the desired format for the output data.
The same configuration is applied for "Goal Scorers," specifying the required output format. Tokens can be used in prompts (e.g., [node:title]). This allows the AI to reference existing fields. For instance, to generate a match description, you could use a prompt like "Create a match description based on the fields [node:field_squads_long] and [node:field_scorers]. Describe how the teams lined up and who scored and in what minute."
This AI integration can also be used to gather statistics (shots, cards, attendance) or for other news portal content, such as daily news, company data analysis, or weather forecasts.
Step 2: Technical Setup: Modules and Configuration
Technical Setup: Modules and Configuration
The setup involves specific modules and their configuration for different content fields.
1. Install Modules:
- Install the AI module (version 12 alpha). This module includes the Field Widget Actions module, which is central to this process.
- Note that this setup relies heavily on the AI Automators module.
2. Configure Content Type Fields:
- Navigate to the structure of your content types. For the demonstration, a 'Match' content type was used.
- For each field where you want to enable AI automation (e.g., fields for 'Squads' and 'Goal Scorers'):
- Edit the field settings.
- Enable the 'AI Automator' option.
- Select the basic configuration.
- Ensure the 'Field Widget' option is checked.
- Save the settings.
3. Configure Taxonomy Field (Tags):
- For taxonomy fields (e.g., 'Tags'), the configuration differs slightly in the 'Automator Type' name.
- In the specific prompt for tags, enter: "utworzyć maksymalnie trzy tagi, które będą pasować pod tytuł" (create a maximum of three tags that will match the title).
- Also, ensure the 'Field Widget' option is checked for this field.
4. Manage Form Display and Actions:
- Access the 'Manage Form' display settings.
- For each configured field (e.g., 'Squads'):
- Locate the 'Field Widget Action' option, which is added by the module.
- Add a new action. This action creates the button that generates the text.
- Select the desired AI model. For example, 'Open AI GPT 4O, search preview' was used.
- Define the prompt specific to that field. For instance, for 'Squads', the prompt specified to get team squads based on the 'Title' field (which is the match name) and described the desired format for the data list.
- Repeat this process for other fields like 'Goal Scorers', making sure to define the format in which the data should be returned.
- You can use tokens such as
note title. For descriptions, you can use tokens likenote field squads longandfield strzelcy(goal scorers) to base the description on other fields.
Step 3: Live Demonstration and Advanced Applications
Live Demonstration and Advanced Applications
Test the AI capabilities on an un-saved node before saving content. The solution has broad applicability across various content types, for example, it can be applied to any informational portal, news, data analysis for companies, stock market companies, daily news, or weather interpretation. You can also extract detailed statistics, such as the number of shots, yellow cards, red cards, or spectators at matches.
Step 4: Conclusion and Call to Action
Conclusion and Call to Action
If you want to implement something similar, contact us. Our contact details are in the video description.
If you want to discuss a specific case or have issues with what was shown, leave a comment. We will try to reply and help.
Key Concepts
- AI module (Drupal)
- Field Widget Actions module (Drupal)
- AI Automators module (Drupal)
- Content type configuration in Drupal (for AI support)
- Prompts (for guiding AI models)
- Tokens (for dynamic input to AI prompts)
- OpenAI GPT-4o (as an example AI model)
Conclusion
This tutorial article guided you through setting up and utilizing Drupal's AI, Field Widget Actions, and AI Automators modules to automate content generation and tagging. You now understand how to configure these tools to enhance your content creation process, making it more efficient and productive. With this knowledge, you can begin transforming your Drupal site's content management.