DEV Community

Cover image for Include ChatGPT on your WordPress website
Thomas Hansen
Thomas Hansen

Posted on • Updated on

Include ChatGPT on your WordPress website

If you have an API account with OpenAI, you can easily access ChatGPT using their API. If you've got an Aista Magic Cloud account, you can easily include a JavaScript file on your website that allows your users to chat with ChatGPT using your Aista Magic Cloudlet as a gateway, providing dozens of additional features. If you have a WordPress website, you can include a JavaScript file allowing you to have your own version of ChatGPT3 on your WordPress blog or site. The combination of these three systems becomes the following.

Include ChatGPT on your WordPress site

You can try it out here if you wish.

It requires zero coding, but it does require some understanding of how Aista Magic works. I go through most of the points in the following video, but please continue reading after having watched it, since I didn't go through everything you need to know.

In addition to following the recipe in the above video, you also have to turn off roles authentication and authorisation. By default, our prompt API will require users to be authenticated as "root" users. If you want everybody to be able to access your ChatGPT chatbot, you'll have to turn this off. In the screenshot below you can see it says "Roles". Expand this thing, remove "root", and click save. This ensures everybody visiting your website can use ChatGPT.

Configuring your ChatGPT API

Preventing bots from accessing your bot (PUN!)

In addition we would encourage you to register a Google reCAPTCHA account. This prevents bots from accessing your bot (pun!). If you do, change the reCAPTCHA value shown in the above screenshot to 0.3 or 0.5 to prevent bots from using your account. This ensures only human beings visiting your website can actually use your chatbot.

If you turn on bot protection by using reCAPTCHA (which we highly recommend you do), you will need to add your site-key and secret to your server's configuration. You can find this in the "Misc/Configuration" parts, inside your auth section. Make sure you copy and paste your site-key and secret exactly as given you by Google.

Notice, this is a service we are charging for. However, we allow people to play with it for a month before deciding if they want to buy a professional plan or not. If you're a bit JavaScript savvy, you can also probably figure out how to create your own JavaScript file, by "forking" the existing one. Notice, if you do this, you need to include your file in your Magic Cloudlet's "/etc/system/openai/js/" folder. When our backend is looking for JavaScript files to include, it will use the "file" query parameter, and first look in this folder to see if it can find a file - And only if it does not find a "xyz.js" file in this folder, traverse into its default JavaScript folder to try to resolve which JavaScript file to actually use.

By default, our API will also log all questions and answers. You might want to turn this off, and if not you might want to periodically purge your cache, to avoid having your cloudlet crash due to having exhausted its storage space. You can do this with the above "Supervised" checkbox. If it's on, you will find all requests (anonymised) in the "Cache" tab control. And you can in fact turn on caching such that the same questions given multiple times returns instantly the same answer it returned previously. The last parts preserves some bandwidth, and also makes your thing more responsive and fast.

Purchasing a professional account

Notice, the demo cloudlet only comes with some 20GB of bandwidth. Once you see your website starts getting a lot of visitors due to this thing, you might want to immediately purchase a professional cloudlet, to ensure your bot continues working. For security reasons, all requests to OpenAI has to go through your cloudlet. Hence, every byte going towards OpenAI also becomes a byte consuming bandwidth from your cloudlet. You can update your cloudlet to a professional cloudlet from our hub.

You are also responsible for your own OpenAI API account, and you need an API account with OpenAI. However, in the beta period OpenAI gives access to "text-davinci_003" for free, so this shouldn't cost you anything, at least not for the moment. However, this might cost you additional money later if OpenAI decides to charge for access to their ChatGPT3 model.

Exchanging the default JavaScript ChatBot file

The latest release of Magic has one annoying bug, which is that it keeps on "blinking" the question. If you've got some skills, you can probably copy and paste the contents of this file using Hyper IDE beneath "Create", and replace the content of your current file with the content of the file from the link above. See in the screenshot below how to edit the JavaScript file that renders the chatbot.

Editing your ChatBot JavaScript file

We have fixed the blink bug, but we're not scheduled for another release for another week or two. At which point the blinking will simply disappear, since we automatically upgrade all cloudlets when we create a release. However, for now, you can follow the above steps to fix the blinking bug yourself. You have to turn on the "System files" checkbox to find this file though.

This file can also be copied and pasted into your "/etc/system/openai/js/" folder by copying its content, create a new file, and name it e.g. "foo.js", at which point when you include your chatbot on your WordPress site, you need to exchange the "file" query argument to "foo" allowing you to include your own custom JavaScript file, to accommodate for your own profile, design, whatever. If you've got some CSS and JavaScript skills, you'll probably figure it out.

Notice, this works with any CMS system out there that allows you to include custom HTML tags, and not only WordPress of course. Anyways, that was it for today. If you want to include ChatGPT on your own WordPress website, you can register below.

Top comments (0)