This article explains to to add to our S2B AI Assistant wordpress plugin content aware feature.
Our plugin allows to create two kinds of chatbot. First one is to use Assistant API from OpenAI. Second is to create chatbot using Chat Completions API . So, we are going to describe how to create content aware chatbot for both cases.
Setup content aware feature for AI chatbot.
Using OpenAI Assistant API.
OpenAI introduced new Assistant API which allows it automatically to parse and chunk uploaded documents, to create and to store the embeddings, and use both vector and keyword search to retrieve relevant content to answer user queries. We implemented File Search API feature in our pugin. Before using this on your website, you should remember some important tips:
- It is Beta feature and not yet tested carefully. Thus it can cause unpredicted behavior. Therefore, we cannot guarantee the chatbot’s responses.
- OpenAI charges additionally besides used conversational tokens. At the moment of release version 1.4.1 of this plugin it costs $0.10 / GB of vector-storage per day (1 GB free) + used tokens during conversation. Please observe OpenAI page to be informed about pricing updates.
- The effectiveness and accuracy of the bot’s responses depends on the system instructions provided and the models used in the prompts. We found that most accurate models by now (middel of july 2024) are gpt4-turbo, gpt-4-turbo-preview
There are two options to create Assistant API chatbots and use them in our plugin.
- Create automatically in our plugin on Assitant API tab
- Create manually on AI Assistants on OpenAI page and then add them to S2B AI Assistant wordpress plugin. Please read this article to find out how to do this.
To setup content aware chatbot using Assistant API you need to open page Chatbot and select Tab Assistant API.
After you need to perform 3 steps:
Step 1.Upload file that will be used as knowledge base by ChatGPT.
We conducted a test on creating a chatbot that should use articles from a DOCX file and answer visitors’ questions related to Bubble.io using information from the articles uploaded to the Assistant API. You can download the test file from here. Here is the list of test questions we asked the assistant.
- Which attributes of Order Item?
- How many fields Order data type has?
- How to Prepare Database?
- How to Prepare Design?
- How to Remove Order Item from the Cart?
- Please create 20 questions related to uploaded file.
List of supported file types by filesearch tool of OpenAI Assistant API:
File format |
MIME type |
.c |
text/x-c |
.cs |
text/x-csharp |
.cpp |
text/x-c++ |
.doc |
application/msword |
.docx |
application/vnd.openxmlformats-officedocument.wordprocessingml.document |
.html |
text/html |
.java |
text/x-java |
.json |
application/json |
.md |
text/markdown |
.pdf |
application/pdf |
.php |
text/x-php |
.pptx |
application/vnd.openxmlformats-officedocument.presentationml.presentation |
.py |
text/x-python |
.py |
text/x-script.python |
.rb |
text/x-ruby |
.tex |
text/x-tex |
.txt |
text/plain |
.css |
text/css |
.js |
text/javascript |
.sh |
application/x-sh |
.ts |
application/typescript |
See updated list of file types from OpenAI
Step 2.Create new Assistant by filling instruction and selecting model.
In this step, you need to identify two important parameters that impact your results. The first is the model. Not all models are suitable for the Assistant API. Only compatible models are listed here Although OpenAI accepts models such as gpt-3.5-turbo-1106 (and subsequent versions), our experiments have shown that the best choice is gpt-4-turbo-preview (and subsequent dated model releases). These are wiser and more content-aware.
Second factor that affects on results is instructions. You need input it into ‘Instructions’ field on Step2 .
In this field, you need to inform the chatbot about how to use the provided database. In our experiments, we tried using various values. The first version of the instructions was:
Please use uploaded files as a source when you respond to visitor queries. If you cannot find an answer, then use your knowledge database regarding Bubble.io.
When we tried to ask questions listed above then ChatGPT gave correct answers from uploaded file but it included reference to the uploaded file in them. For example: For more detailed instructions and insights, you can refer to the document “assistant_file2_1713207035_3957.docx. OR To prepare the design for implementing cart features in multi-vendor stores using Bubble.io, follow these steps outlined in the document “assistant_file2_1713207035_3957.docx”
So, we decided to remove mentioned file from answer by correcting Instruction: Use uploaded files as source when you respond to visitor queries. Do not mention uploaded document in the answer. Do not mention about source from where you take information for answer. When you can not find answer then use your knowledge database regarding Bubble.io. This helped us to achieve necessary result. But this approach worked only when we used gpt-4-turbo-preview model.
Step 3.Add [s2baia_chatbot bot_id=assistant] to any page.
Setup content aware feature using chat Completions API.
Another option is to use Completion API. If capacity of context is not too big, it makes sense to use this option, as it can be significantly cheaper than the Assistant API. Lets say you have a description of your product. So you can add following text to Context: field on Chatbots tab of Chatbot configuration page:
Speak like you’re an AI assistant. Respond to the query as truthfully as you can using the provided context. (PRODUCT DESRIPTION) Where you can replace (PRODUCT DESRIPTION) by actual description of your product.