Start of Main Content

By now you’ve probably heard of ChatGPT. It’s the conversational AI (Artificial Intelligence) that took the world by storm when it was released late last year by OpenAI. ChatGPT is the talk of the world right now from elementary schools to universities, hospitals to law offices, digital agencies to content marketers, developers to stock traders, and authors to broadcasters. It may be one of the few times in history that everyone is talking about a technology since the dawn of the internet itself, “Google it”, and “Facebook me.”

Like it or not, we’re witnessing a sea change in the way we use technology from here forward. We’ve seen various forms of AI in the past, but this is the first time where AI is a useful and almost human-like interaction that will only get better.

I’ve seen lots of doom and gloom posts about how certain jobs are over, or how you don’t need marketing teams now. I’ve also heard absurd claims that you need to fire all your developers or analysts. LinkedIn, for example, is awash in these kinds of posts. But instead of putting more fear out there, I spent some time investigating ways that OpenAI services can help, augment, or assist users in their day-to-day content management tasks in Drupal 10.

Full disclaimer: this article was written by me, and no parts were taken from or generated by AI services.

Who is OpenAI?

ChatGPT is just one of the AGI (artificial generational intelligence) use-cases built by OpenAI. OpenAI is a research laboratory in California that is exploring and developing artificial intelligence for real world use. Their current AGI efforts have done large language model training (LLM) in various areas, powering applications like GitHub Copilot, DALL-E (image generation), MuseNet (music generation), and more. Their efforts are ushering in a new era of AI based applications and has a lot of financial investment backing from large organizations, including Microsoft.

Over time, you can expect to see more integrations from OpenAI throughout applications beyond chatbots. Perhaps Clippy can make a strong comeback in Word! Joking aside, that assistive “helping hand” style tool is where I see AI being most useful.

While OpenAI provides several products that use their generative AI services, they also provide an API (Application Program Interface) to interact with the foundational parts of their software that makes the generative AI work. Integrating with a good API is easy in Drupal, so here we go!

OpenAI API Services and Drupal

How can OpenAI services fit in and benefit users of a content management system like Drupal? This is the question I’ve set out to answer. I paired up with some people in the Drupal community to kick off an integration module and explore several options that could prove useful for content management.

OpenAI provides a handful of services to integrate with via its API. Right now, they allow you to generate text, generate images, analyze text (embeddings), run moderation scoring on text, and fine tune models.

We added five (yes, five!) features to start off with.


Find out more about how OpenAI can transform Drupal content management.

Our Triple Certified Drupal Expert can show you new and exciting ways to augment content management in Drupal with the OpenAI/ChatGPT integration module he helped create.

Feature One: Prompt / Text Generation Explorer

Installing this module allows an administrator to test OpenAI using prompts. Prompts are how humans “talk” to artificial intelligence. If you have used ChatGPT, you were “prompting” the AI to respond to your input.

This is a similar interface. You can prompt and get an answer back from OpenAI. It is not literally ChatGPT, but it is the same underlying foundation that makes ChatGPT possible. You can experiment with OpenAI, change the data model used, change the temperature (influence/randomness/variance), and change the max tokens to see what kind of text it will generate.

Below, I asked OpenAI to tell me about Drupal:

A screenshot from OpenAI that says, “Drupal is an open-source content management system (CMS) written in PHP and distributed under the GNU General Public License. It is used as a back-end system for many different types of websites, ranging from small personal blogs to large corporate and political sites. Drupal provides a web-based interface for managing content, user accounts, and other features of a website. It also provides a framework for developing custom applications and modules. Drupal is highly extensible and can be customized to meet the needs of a wide variety of websites.”

OpenAI will add a ChatGPT Plus subscription option and API for that this year. We'll be able to evolve this UI at that point and make it more “conversational.”

Feature Two: Content Generation

The module can generate content for any content type that has a title and body field as well as generate images for detected image fields. Generating random content could be useful for teams who want to see more than lorem ipsum text content on pages and fill it with real text to see how those pages lay out with real content. For years, developers in Drupal have used the Devel module “Generate” function to generate tons of random text and images, but this can be hard to view because it is entirely gibberish text. I can foresee a time soon when generating real enough looking placeholder content is preferred to unreadable garbled text and images or lorem ipsum text.

Feature Three: CKEditor Integration

We added a button in the CKEditor that lets you ask OpenAI (like ChatGPT) a question and retrieve text back. This can be a boon for content editing when you want to have a quick one-liner or introductory ideas to start writing content with. Writing is hard, but OpenAI can be a nice assistant to help you write and tune your content. We have many more plans around enhancing the text editor experience.

Check out the video below of this in action:

That’s it! There are many possibilities here beyond just text generation. We hope to share more progress on editor integration this year.

Feature Four: Log Analysis

We added to the log viewer in Drupal that uses OpenAI to attempt to “explain” the error you’re looking at. This proof of concept is geared toward non-technical site users or novices who just may not understand what an error message means. Sometimes errors are logged from core or contributed modules or thrown by PHP itself. From that perspective, it can be hard to decipher why you are receiving an error unless you have years of development experience. I see this all the time on sites like Drupal StackExchange where I have answered questions for many years about errors themselves.

Here are just a few examples of what OpenAI provided when viewing sample logs:

A screenshot from Drupal with an error explanation powered by OpenAI.

As the explanation from OpenAI states in plain language, this error can be common if you make custom controllers or service classes and do not implement the instance construction right. Also, it could be because you did that, but have a typo in the file. Finally, and the most common cause, you added a new class file and did not clear the application cache. OpenAI is generally right on in this case and gives the reader a decent start at diagnosing what happened, which is easier to understand than the stated, literal exception message.

A second screenshot from Drupal with an error explanation powered by OpenAI.

In this case, the directory for private keys did not exist on the web server, and the server was not able to generate that directory for the user. OpenAI explains the issue and possible solution in plain, easy to understand English.

One last example. This time, I changed the underlying prompt to also provide a few helpful links from Drupal.org as next steps:

A third screenshot from Drupal with an error explanation powered by OpenAI that includes helpful links.

While it provided some links as asked, unfortunately the AI basically invented them—meaning, the links do not go anywhere on Drupal.org—they all generate 404 page not found errors. This is because the AI is trying to “guess” what a link is, not that it knows of hyperlinks, because it’s not a search engine like Google or Bing. Not yet. Boy, wouldn’t that be something? The technology is new, but impressive.

In each case I looked at, OpenAI was pretty good at providing a plainly worded explanation of what the log message means. Logs don’t have to be scary—we can humanize them, and this tool helps us get closer to that goal. This is similar to the reasoning I had for implementing the Ignition library for Drupal last year—making errors friendlier for developers and more useful. Hopefully someday a combination of the two ideas will exist thanks to AI.

Feature Five: Text Embeddings

Lastly, we added functionality that when content is published, it’s analyzed by OpenAI and has a series of vector data returned. Essentially, the “embeddings” feature measures the relatedness of strings. Running these calculations will enable other features to augment the system, like:

  • Search (where results are ranked by relevance to a query string)
  • Clustering (where text strings are grouped by similarity)
  • Recommendations (where items with related text strings are recommended)
  • Classification (where text strings are classified by their most similar label)

We envision this as a means of bolstering search and relevancy in addition to using alongside popular modules like Search API. These four points are very powerful features that aren’t easy to get today, especially a good recommendation engine. Imagine having that right in your system! Generating relevancy models and/or analysis is not possible today without having additional services like Solr, Algolia, Coveo, Meili Search, etc.

Embeddings is a complex topic, but this video breaks it down nicely:

One limitation is that common databases like MySQL, MariaDB, and PostgresSQL (where all your CMS data and content are stored) don’t have a way to search and compare vectors. We had to find a solution to make that possible and could perform at scale and under load. While those databases are great and power most of the internet, this is an area they just cannot do (currently).

We’re currently working on adding integration with Pinecone to facilitate the above ideas. Pinecone is a database that specializes in searching through vector-based data and is extremely performant. When users query, input, or ask something of Drupal, we’ll be able to pull back the most relevant items for them to augment the experience in question. That could be search, content personalization, “related content,” suggested taxonomy for content you’re editing, and more.

Where Can We Go from Here?

So far, we’ve seen a few ways OpenAI can augment and change the day-to-day content management experience in Drupal. We have many ideas for proofs of concept in the module this year, like:

  • Adapting fields and field widgets to receive generated text
  • Translating content and fields into other languages
  • Building content moderation tools for comments or other content screening
  • Adding a Webform handler to check if a form submission is technically spam, junk, or hateful
  • Integrating with Views and Search API to augment ranking and scoring of search results
  • Suggesting relevant existing taxonomy or new taxonomy to classify content
  • Integrating ChatGPT Plus API to bring ChatGPT to your website

These are just a few ideas we’re considering. We have a few people pitching in with the module so far, but welcome anyone in the community to join in and develop features and demos using OpenAI.

The OpenAI/ChatGPT integration module can be downloaded and viewed on its project page on Drupal.org so you can start using it and demo these features today.

Are you using OpenAI? Do you have an idea for your site that could be powered by AI? Contact us at Velir to discuss how we can make it happen.

Published:

Latest Ideas

Take advantage of our expertise with your next project.