How to Generate Content using Artificial Intelligence in Drupal with OpenAI

Don’t forget to subscribe to our YouTube channel to stay up-to-date.

The OpenAI/ChatGPT module allows you to integrate OpenAI’s artificial intelligence technology into your Drupal website. This can generate, translate, summarize content, answer questions, and more.

To use the module, you must create an OpenAI account and obtain an API key. Once you have your API key, you can install the OpenAI module on your website.

The module’s functionality is broken down into separate sub-modules. Just install the module that you plan to use.

In this tutorial, we’ll look at the following modules:

  • OpenAI CKEditor integration
  • OpenAI Content Tools

What is OpenAI?

OpenAI is a leading AI research organization dedicated to advancing artificial intelligence while emphasizing openness and collaboration. They are known for developing advanced language models like GPT-3, capable of understanding and generating human-like text. With a focus on ethical AI development, OpenAI aims to ensure the widespread benefits of AI technology for society’s betterment. Their groundbreaking work sets new standards in responsible AI innovation, fostering discussions about AI’s significant impact on our world.

Getting Started

Before we begin, download the OpenAI/ChatGPT module.

Run the following command using Composer:

$ composer require drupal/openai

Go to Extend and search for OpenAI and install the following modules:

  1. OpenAI CKEditor integration
  2. OpenAI Content Tools
OpenAI modules for Drupal

Configure OpenAI/ChatGPT API Keys

1. Once you’ve installed the modules go to Configuration and click on Settings in the OpenAI section (/admin/config/openai/settings).

OpenAI settings

2. You must generate an API Key and get the Organisation Name from the OpenAI website.

OpenAI Settings

3. Go to https://openai.com/api or click the OpenAI website link within Drupal.

4. Register an account on OpenAI, click on your profile in the top right corner, then click Manage account.

5. Copy the Organization ID from here and paste it into your Drupal site.

6. Click on the API keys on the left-hand side.

7. Click on “Create new secret key”, enter “Drupal test” (you can add any name) into Name and click on “Create secret key”.

8. Copy the generated key and paste it into your Drupal site.

OpenAI/ChatGPT in CKEditor

The “OpenAI CKEditor integration” sub-module allows you to interact directly with OpenAI through the editor in Drupal.

Configure Text Format

Before we can use OpenAI in the editor we need to enable it on a text editor.

1. Go to Configuration, “Text formats and editors”, and click on Configure on the text format you plan to use.

2. Move the OpenAI button to the Active toolbar.

NOTE: If you can’t see the button, ensure you’ve installed the “OpenAI CKEditor integration” sub-module.

3. Scroll down to “CKEditor 5 plugin settings” click on OpenAI tools, and enable it by checking Enabled.

4. Select the Default model you want to use.

5. Adjust the Temperature and Max tokens as required.

Scroll down and click on “Save configuration”.

OpenAI CKEditor Drop-down

You should see an OpenAI dropdown with the following options:

Text Completion

This option allows you to generate text using a prompt.

Adjust tone/voice

Select text and adjust the voice or tone.

Summarize

This option allows you to summerize any selected text.

Translate

This option allows you to translate selected text into other languages.

Reformat/correct HTML

This option allows you to fix and reformat incorrect HTML code.

From this:

To this:

Permission

You can control which role sees this drop-down by adjusting the sub-modules permission.

Go to People, Permissions and assign “Permit access to using the OpenAI CKEditor plugin.” to a role.

OpenAI/ChatGPT on Content Forms

The “OpenAI Content Tools” sub-module adds elements to entity forms, allowing you to analyze text, adjust tone, summarize, and more.

You can access these elements from the right-hand side of the content edit form.

A big difference between this functionality and the CKEditor plugin is that you can analyze text from a standard text field such as the title.

Analyze text

This option allows you to analyze and moderate the tone of your text.

Adjust content tone

This option will rewrite and adjust the tone of your text.

Summarize text

This option will summarize your text.

Suggest content title

This option will suggest a title for your content.

Suggest taxonomy

This option suggests possible taxonomy terms for your content.

Permissions

You can control which role sees these form elements by adjusting the sub-modules permission.

Go to People, Permissions and assign “Permit access to using content tools provided by the OpenAI Content module.” to a role.

Summary

If you need to add AI functionality into your Drupal site, take a serious look at using the OpenAI module. By enabling “OpenAI CKEditor integration” and “OpenAI Content Tools”, you can add fairly decent text generation tools for your editors.

Drupal AI Modules

Here’s a list of Drupal AI modules:
OpenAI / ChatGPT / AI Search Integration
Augmentor AI
Open AI Metadata
OpenAI Client

Can’t See OpenAI Drop-down in CKEditor?

If you can’t see the OpenAI drop-down in CKEditor, check the following:

1. Ensure you have installed the “OpenAI CKEditor integration” sub-module.
2. Add the button to the active toolbar from the text format section in Drupal.
3. If you’ve given role permission to access the button, ensure your role has the correct permission.

How to Generate an OpenAI API Key

Below are the stops to generate an OpenAI API key.

1. Go to the OpenAI website: https://openai.com/.
2. Click on the “Sign up” button.
3. Enter your email address and create a password.
4. Click on the “Create account” button.
5. You will receive an email from OpenAI. Click on the link in the email to verify your account.
6. Once your account is verified, you can create an API key. Click on the “API keys” tab.
7. Click on the “Create new key” button.
8. Enter a name for your key and select a scope. The scope determines what you can do with your API key. For example, you can select the “Playground” scope to use your key in the OpenAI Playground.
9. Click on the “Create key” button.
10. Your API key will be displayed. Copy the key and save it in a safe place. You will need it to use the OpenAI API.

About The Author

Leave a Comment

Your email address will not be published. Required fields are marked *

Scroll to Top