How I Created a GPT Chat Bot Focused on My WordPress Website

How I Created a GPT Chat Bot Focused on My WordPress Website

Key Ideas:

Is It Possible to Use ChatGPT Against Your WordPress Site?

Recently I decided to explore what I could about artificial intelligence. I haven’t really thought about the subject since my college days thirty years ago, when I took an artificial intelligence class and learned the LISP programming language. Fast forward to 2023, and AI is already the next big revolution in technology.

So here I am, playing catch-up in a way. As I learned about OpenAI and their models, I naturally wondered if I could leverage my blogging website as a source for AI chat and content creation. I have to date over 375 articles on my website ComputerLookingUp spanning almost a decade, plus a repository of archived blog posts from my early writing days. Could AI be used to synthesize and remake all of my data into something useful?

The short answer is yes, it is possible to leverage existing website content, and specifically your WordPress site’s content, as an input to an AI model. Of course, we see it all the time when visiting websites. Try to find a car dealership’s site that doesn’t have an AI chat bot name Lisa willing to help you at all hours of the day. But getting to the destination of an AI model that ingests your own data is not as easy as installing a plugin. You first should understand how AI models read data to learn how your articles can go from digital prose to chat bot source material.

How accurate and useful my chat bot is will be covered in another article. The intent of this one is to explain step-by-step how I added Cassie, my GPT-powered chat bot, to my website. Subsequent articles will focus on topics around the chat bot, like real examples of what the bot can and cannot do. But for now, let’s just walk through my simple setup, which perhaps you can leverage for your own WordPress site.

Which WordPress AI Plugin to Use?

If you search the WordPress plugin list for AI, you will find many offering some form of AI function. Most as of today, as far as I can tell, are “merely” leveraging the AI models at large without any focus to specific data. However, one plugin named AI Power does offer a means to funnel your own data to an AI model via what are known as embeddings.

The AI Power WordPress plugin

After you install and activate the AI Power plugin, you will see the AI Power menu available on your admin dashboard. To start, click on the Settings option.

All the main menu choices for AI Power

Under Settings, as of the plugin’s version today, there are a variety of good instructions in a wiki-like format for how to get started and use the plugin’s AI features. Scroll down to the section titled How to use Embeddings for Chat bot.

AI Power’s instructions for embeddings

The video tutorial is very good and a great place to learn how the chat bot can use your data, going through all of the key steps. I have linked the video here for reference:


Enabling AI on WordPress is Not “Plug ‘N Play” But Requires Some Work

You will notice references in the video and the plugin’s instructions to Pinecone. It it worth pausing for a moment to explain what Pinecone is and why it is important to what we are trying to accomplish. Pinecone is effectively a service that allows you to create vector databases. What is a vector database? We could ask ChatGPT, but let’s go the old fashion route and pull a definition from Wikipedia:

A Vector Database is a type of specialized database designed to handle vector embeddings. These embeddings are a form of data representation that conveys crucial semantic information for a variety of applications, including large language models, generative AI, and semantic search.

If you were trained in anything related to computer science, you likely at least heard of vector databases. Most of us are familiar with relational databases, such as Excel spreadsheets, or MS SQL or Oracle databases. You may recall from computer science training that relational databases, though widely used, are horribly inefficient for computers compared to other database types. But humans (usually) think relationally, so we gravitate to data models that we can comprehend, even though computers are better at other database structures.

And if you haven’t already, whether your are technically inclined or not, I highly recommend learning the basics of AI modeling. It is through that initial understanding of how AI models work that you can immediately appreciate why ChatGPT and other models leverage vector databases, because they put data into a format that the AI models can understand. AI modelling was designed with the intent of vectors in mind.

In other words, an AI model cannot simply “read” your entire website like a search engine crawler. Instead, every page and post of your WordPress site (that you want to use with AI) must be indexed into a vector database first. I realize search engines likely store their data in some form of non-relational database as well.

Setting up my Pinecone account and the needed index was easy. I am using the “free” service from Pinecone, which does not offer much control over where the database is stored (in Singapore?) or how I could tweak the index if I was really serious about optimization. Here is a snapshot of my Pinecone index’s stats after all of my website’s posts and pages were indexed:

My pinecone index

After you set up your Pinecone account and index, go back to the AI Power plugin on your website can choose Embeddings. Add your Pinecone API key, Pinecone Environment, and whatever your named your Pinecone Index. I found that you must state the correct environment e.g. if I selected a US environment, it could not find my API key. Click Save at the bottom of the page when done.

Copy your Pinecone API key to this AI Power page

Before going further, I should mention I am assuming you already set up your OpenAI account and created an API key. The API key must be added to the AI Power’s main settings. OpenAI is the entity that runs all things ChatGPT-related, and GPT-related interfaces with their AI models via your OpenAI API key. Never share or expose your API key! Using OpenAI costs money, but they do provide a $5 US “allowance” so you can try the API out. If you want to continue using OpenAI’s API, you will have to investigate their pricing and pricing structures. I will discuss pricing in a later article, but for now, just know you must have already set up your API key and copied it into the AI Power plugin for the rest of this to work!

You have now created your Pinecone index and saved it to the AI Power plugin. Now, you must index your site’s content. AI Power’s instructions continually recommend setting up a Cron job on your WordPress server. How you do that is up to you and your specific type of server. For me, it was very easy to set up the requested Cron jobs on my Ubuntu server. Follow the instructions offered by AI Power.

But you don’t need the Cron/schedule setup if you don’t want it. You could manually index your content. Go to AI Power -> Embeddings -> Index Builder. While I did not manually index since I set up the Cron job (which does one article per schedule interval), you can see the progress of the indexing to Pinecone. Below shows my Index Builder after two Cron runs. It was all automatic.

AI Power starting to index my site!

Progress continued every 10 minutes, the interval I set up in Cron. Eventually, I temporarily set the Cron jobs to run at one-minute intervals so that the entire site would be indexed by morning.

The gradual and slow index process

Even with only a partial indexing complete, that was enough to start using ChatGPT against my website data! Go to AI Power -> ChatGPT. This section can be a little confusing at first because there are multiple ways to set up chat bots:

  • Shortcode is the chat bot you can insert directly into a page or post on your WordPress site
  • Widget is the popup icon you see at the bottom of the page. If you are reading this article on my site, you should see Cassie’s icon in the lower left corner of this page!
  • The Chat Bots tab allows you to create even more bots, though I haven’t gotten this to work

With no changes to a chat bot’s settings, the bot will not use your website’s data.

Chat bot shortcode interface page

For my site, I focused on the Widget tab for setting up Cassie. Here is the location highlighted for reference:

Widget setup area for my chat bot Cassie

Before we get to linking embeddings, let’s review the key settings for the bot that you can change. Make sure to “enable” the chat bot under the Enable / Disable section. Then, under Style you can change a variety of look-and-feel features, and they should be self-explanatory.

My Style options for Cassie

The next section you want to pay attention to is Parameters, specifically the Model option. If you have not already, do some research on the different Chat models, and their pricings. The costs for each model will be very important if you want to continue using OpenAI beyond your trial period. I will discuss pricing in a future article. To summarize, I started with davinci but now use gpt 3.5 turbo16k, since I found this functions the best. davinci is very expensive and all pre-davinci model are, well, terrible from my test observations. GPT-4, OpenAI’s newest model, is way too expensive for my needs. I recommend trying them all, but your safest starting point is perhaps the non-16k version of gpt 3.5 turbo.

The models will make your chat bot behave differently

Last, we get to the heart of the matter, linking your Pinecone-indexed embeddings to this chat bot. This is down in the Context section.

This is where my website’s content is linked to the chat bot via the Pinecone index

I am going to talk about the Context box in a separate post, because it deserves its own attention. Context is where I spent 95%+ of my setup time. But carrying on, to link your data, you must check Use Embeddings, select your Pinecone index, and use Embeddings + Completion for the Method. I also recommend Nearest answers be set to 3. When set to 1, for example, the chat bot had difficulty finding any information on my website. 5 might be too expensive for my personal website’s needs, so 3 seemed like a good compromise.

And that’s it! Save the settings and you can start playing around with the chat bot widget on your WordPress website!

A Rapidly-Changing Technology

It is worth noting that the world of artificial intelligence is evolving very quickly, and so better methods to link WordPress sites may be out there, or be out soon. But at the least, hopefully this article provides you with a foundational explanation for the process.

The Cost of Running a Chat Bot

As mentioned earlier, there are costs to leveraging AI. Already there are “all in one” solutions that you can pay for that offer much of the above automatically. But those services, I think, are geared to professionals and large user bases. For a tiny website like my personal blog, how I have set up and use this chat bot is more than adequate.

I will discuss the price setup in a separate article, but a key takeaway from this experience is that when using the GPT 3.5 turbo 16k model, each inquiry costs a penny (US) or two. I have set up my daily user limit to be able to ask Cassie 10 or 12 questions before reaching the token allowance, which I think should be more than sufficient for users looking for information on my website.

Next Articles on my WordPress Chat Bot and AI

Check back to my blog later for more article on my chat bot and AI. I plan to cover at least the following topics:

Thank you for taking the time to read my article.

Paul

Paul

I write frequently about astrophotography, technology advice, and my other interests like science fiction. I have over 30 years of experience in computer programming, information technology, and project management.

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.