Revolutionizing Content Editing with AI in Drupal
Nowadays, artificial intelligence (AI) has become a powerful tool to enhance the process of creating and managing digital content. Drupal, known for its flexibility and robustness as a content management system (CMS), has already started to integrate this new technology, adding exceptional capabilities for generating and improving content.
In this detailed guide, as a showcase, we will demonstrate how to install and configure the modules AI (Artificial Intelligence) and Image Genie AI in Drupal, the first to integrate AI with CKEditor, thereby improving its editing capabilities, such as text generation, tone alterations, or translations, and the second to generate images, enabling the creation of complete content , quickly and efficiently.
It is worth mentioning that these modules are currently in development phase, so their use in production is currently discouraged.
Prerequisites
Before starting to integrate AI capabilities, it is essential to ensure certain requirements are met so that everything can function smoothly.
You will need to have at least Drupal 9 or a higher version installed, depending on what you want to use: the image generation module, for example, requires at least Drupal 10.3.
Although in this article we are going to focus on using OpenAI services, we can use many other LLM models both free and private such as Claude, Ollama, Mistral, or LM studio, to name a few. Regardless of the model chosen, an API key will be necessary to make calls to the model we choose. In the case of OpenAI, it can be obtained on its API keys page.
Basic installation and configuration
Once the prerequisites are confirmed, we can start with the installation and basic configuration of our Drupal to integrate the chosen AI.
Provider configuration
The first step is to integrate a provider of AI capabilities. As we have mentioned before, we will focus on the services provided by OpenAI, so we will install and activate the module OpenAI Provider:
composer require 'drupal/ai_provider_openai:1.0.x-dev@dev'
drush en ai_provider_openai
The module, as indicated, requires an OpenAI API key. Since these keys are sensitive data due to the credit consumption that occurs with each request to the AI provider's API, the module requires the module Key for secure secret storage. Since it is a dependency of the OpenAI Provider module, it should already be installed. If for any reason it is not, just run the following commands:
composer require 'drupal/key'
drush en key
Once installed, it will be possible to add a new key in the System > Keys section within the Drupal admin panel. We will add our OpenAI API key on that configuration page.
Finally, we must assign the API key we added to the OpenAI provider. For this, we access the AI > Provider settings section of the configuration panel and select the key created previously.
OpenAI module installation
The Drupal AI module provides a framework for integrating artificial intelligence capabilities into any site built with Drupal. This module offers a suite of tools and a base API that facilitate content generation and modification, automatic translations, and semantic search, among other functionalities.
To install it, simply use composer as we did previously:
composer require 'drupal/ai:^1.0@beta';
drush en ai
Integration with CKEditor
We will specifically focus on its capabilities related to content generation and translation, two key aspects for optimizing content creation in digital environments. For this, we need CKEditor to be able to make use of AI quickly and easily.
The first step is to enable the AI CKEditor integration module, one of the submodules of the Drupal AI module. This module introduces a plugin for CKEditor that acts as a bridge between the text editor and language models, offering functionalities such as text generation, translation, HTML code formatting, or changing the tone of the text, among others.
To activate the module, we will run the following command:
drush en ai_ckeditor
CKEditor configuration
The next step is to configure the plugin in CKEditor. In the section Configuration > Content authoring > Text formats and editors, we should edit the text format we want this tool to be available for and add the AI CKEditor plugin to the toolbar. The Source Editing plugin is also required so we should enable it as well.
Configuring the enabled functionalities
Once the plugin is integrated, it's necessary to enable and customize the different functionalities we want to be able to use. In the AI Tools section of the vertical tabs, available in the CKEditor plugins configuration panel, you will find the different options that can be enabled by checking the corresponding checkboxes.
Configuring translations and tone
For functionalities like translation and tone adjustment, it's necessary to associate vocabularies that define the available options.
In the case of translations, it is necessary to create a vocabulary with the languages to translate to. For example, we can create a taxonomy called "IA Translations" and add terms for different languages such as Spanish, English, Italian, etc.
In the case of tone, we must also create a taxonomy with the tones we want to use. For example, we can create a vocabulary called "IA Tone" and add terms like "formal", "critical", "informative", "technical" or "humorous".
After creating the vocabularies, we can select them in the configuration of each functionality.
Each enabled functionality allows selecting an LLM model provided by the configured provider. In the case of OpenAI, it's possible to choose between models like gpt4o, gpt40-mini, or o1-preview, to mention a few.
Example of usage
Once we have our CKEditor correctly integrated with our AI provider, we can start using it. Below are a couple of videos showing how to use it: generating content, translating it, changing the tone, and reformatting the text:
Integration with Drupal translation system
While it is possible to translate texts from CKEditor as shown in the previous video, this is not ideal for automatically translating content. A Drupal content can have many fields and different texts, making the process tedious. However, we can integrate AI with the Drupal translation system, making this process much cleaner and faster.
Prerequisites
The first step is to enable the AI Translate submodule, either with Drush or the Drupal administration interface.
If we don't already have multiple languages enabled on our site, we must add them in Configuration > Regional and language > Languages. Similarly, if we do not have the content translation system active, we must activate it in the section. The multilingual configuration in Drupal is complex, but broadly speaking, we will need to enable the Multilingual: content translation module and then in Configuration > Regional and language > Content language and translation, choose which content and fields will be translatable.
Module configuration
Finally, we access the configuration of AI Translate from Configuration > AI > AI Translate Settings, where we can configure the translation options. For each language, we can set the following:
- OpenAI Model: AI model to be used for translating into the language (e.g., GPT-3.5).
- Prompt: since ultimately a prompt is sent to the AI provider, this prompt can be configured for each language. This is especially necessary given that each language has its own characteristics and we might want to specify certain uses (for example, indicating not to use title case when translating into Spanish).
Additionally, we can indicate whether we want referenced entities to be translated or not and which ones. An example would be translating Paragraphs, so that when an entity is translated, its paragraphs are also translated.
Translating content
To translate the content, just go to the translation tab of any content. An AI Translations column should appear with a link to translate the content using the model you've specified in the module configuration .
By clicking on a link, the AI translates the content, so you just need to review the translation afterward. The process can be seen in the following video:
Image generation
In addition to text, it is possible to generate images for our content. For this, we can use the module Image Genie AI, which uses OpenAI's DALL·E models to transform textual descriptions into images. We can choose between different versions of the model, like DALL·E 2 and DALL·E 3. The difference between them is that DALL·E3 is more advanced in its capabilities but also more expensive.
Installation and configuration
To start, we will install and activate the module Image Genie AI:
composer require 'drupal/ai_image_generation:^1.0';
drush en ai_image_generation
Before continuing, and specifically if OpenAI's API keys are used, it is necessary to apply two patch to fix two issues.
The first patch is necessary because OpenAI's current API keys are 164 characters long, but the module's configuration form only accepts 128 characters. The second second patch fixes an issue with module's configuration export.
Once the patches are applied, we access the module's configuration (/admin/content/ai_image_generation_settings), and add the organization ID and the API key from our OpenAI account.
Example of usage
With this, we will be able to start the module and generate images in our Drupal. Below is an example:
Permission configuration
It is possible to set who can access and use the different AI-based functionalities through the many permissions that the Drupal AI module declares. For example, we can allow only editors or administrators to access these advanced tools, which would be logical if we want to control the cost that intensive use of AI services can generate.
In other cases, for example, it might make the translation service available to all users. Let's consider a blog platform with subscription access so that the cost of using AI is covered.
Conclusion
The integration of artificial intelligence into Drupal opens up a world of possibilities for improving the management and creation of content. This integration not only optimizes the editorial workflow but also places the project that uses it at the technological forefront in terms of content management thanks to the new capabilities offered by AI-based solutions.
With the Drupal AI module, it's easy to integrate these capabilities, as demonstrated in this article. Although the modules used are not mature enough for production use with complete confidence, the reality is that they already offer very useful features. Our tests at Metadrop indicate that they do offer a reasonable degree of stability to be used in projects that are not highly critical. And we believe that they will soon be stable enough to be used in other projects.