Nov 14, 2024

A Dead Simple RAG Setup for WordPress: AI Chatbots for Small Websites

There are plenty of small websites, especially small businesses, containing just 5-6 pages with some basic information. Often, users struggle (or may just be too lazy) to find relevant information. But what if they could simply ask what they need? Convoworks enables you to do exactly that, deploying an AI-powered chatbot in a matter of minutes.

Base Concepts

Modern LLMs are now much cheaper and offer much larger context windows—large enough that we can easily inject content from 5-6, or even up to 10, web pages from your website into it. This way, the bot has all the information in front of it and can easily answer user questions. WordPress pages (or posts, if you prefer) are loaded using the get_posts() function, making it familiar and easy for you to customize according to your needs.

Installation and Setup

Follow these simple steps to enable and try it on your own WordPress installation:

  1. Download and activate Convoworks WP (available through the plugin installer).
  2. Download and activate the Convoworks GPT package (available at GitHub).
  3. In your WordPress admin, navigate to Convoworks WP and create a new service from the template GPT Example Chat.
  4. Set the GPT_API_KEY (OpenAI API key) in the service's Variables view and save.
  5. Navigate to the Test view in your newly created service and try it!

The full process can be seen in the video below.

Service Walkthrough

Navigate to the Editor view in your Convoworks service. By default, the Home step is selected, and you can see its contents in the middle panel. The upper part of the step (Read Phase) is executed only once at the beginning of the conversation. Here, we check if the service is set up correctly and generate a welcome message, and then the service waits for user input.

Each message that the user types goes through the lower section – Process phase. First, we trigger moderation, and we save the user message in the messages array to maintain history through the session. Finally, we include a fragment that contains GPT components, where all the magic happens.

You can click on the Chat Completion element in the "Include Read Fragment" to see its content.

GPT API

The "GPT Chat Completion API v2" element serves as a bridge to the OpenAI Chat Completion API. When selected, you can see the properties in the right panel, which correspond to the OpenAI API specifications. It has several sub-flows:

  • messages – where you build the system prompt, define functions, and load chat history messages
  • new message flow – triggers after each new message, which can be a function call, function result, or assistant message
  • OK flow – executes once we have the final assistant response

When you open the messages flow, you can see that we have separated our prompt into logical sections:

  • main prompt – defines the chatbot’s role
  • system information – adds time information, basic site information, and current user info
  • load pages – loads pages from the website and adds them to the prompt, creating a mini knowledge base
  • functions – includes a single example function as a simple showcase
  • conversation messages – provides the chat history

Loading Posts

In the "Load Pages" fragment, you can see how we use the get_posts() function inside Convoworks to fetch required data, and how you can use other functions, control flow with IF/THEN, and iterate through arrays. Note how we transform post content to markdown and remove any tags to save space in context.

Find more about functions and expression language in our Core Package documentation and the WordPress Package documentation.

Enabling Chat on the Frontend

To enable chat on your website's front end, just follow these two steps:

  1. Navigate to the Configuration view in your service and enable the Convo Chat platform – no additional settings required.
  2. Add the shortcode [convo_chat service_id="gpt-example-chat" title="Example Chat"] somewhere on your website.

Conclusion

This service provides a solid base for creating your own tailored chat, with additional information and features. Currently, the service contains one function, which serves only as an example. It’s also a great way to understand how GPT-based chats work and how we can manipulate their behavior to create more customized interactions. You could easily add functionality to allow users to send contact messages through the chat or dynamically toggle parts of the prompt based on user roles.
Be sure to stay tuned for more updates!

Tihomir Dmitrović

Tihomir Dmitrović

Full stack developer with 20+ years of professional experience, specialized in solving complex problems in a scalable manner. Founded Convoworks, which is a GUI based tool for creating voice and chatbot applications through WordPress.

Oct 31, 2023  | 

The GPT Site Admin: A New Era of AI Integration with WordPress

We are already witnessing various AI integrations with WordPress, primarily in terms of generating content or other limited application…

VIEW FULL POST

Sep 8, 2023  |  ,

Step-by-Step: Building a GPT-Enhanced Twitter Bot with WordPress and Convoworks

In our previous article, we introduced you to the basic usage of the Twitter API in conjunction with Convoworks….

VIEW FULL POST