Create A ChatGPT Powered ChatBot With Access To A Local Knowledge Store
With ThinkAutomation you can create a 'Web Chat' message source type. This message source type operates in a similar way to the 'Web Form' message source type, except that request/response is shown in a conversation-style UI. Each time a user sends a chat message, your Automation will execute. Whatever value is returned by the Automation will be returned to the chat form.
We recently added a 'ChatGPT' action that you can use in Automations. This action simply sends a prompt to ChatGPT and returns the response. You can add this to an Automation to very quickly create a ChatGPT chat bot.
However, ChatGPT does not have up-to-date knowledge about your business (if any) and will not have any knowledge of internal documentation, or up-to-date knowledge about your products, services, recent support tickets, current service status or current customer-specific data etc.
This is where 'context' comes in.
Before your automation sends a request to ChatGPT to answer a question, you can add 'context'. With context we are simply giving ChatGPT information relating to the question asked. ChatGPT can then answer the question - based on the information you give it. This context isn't saved by ChatGPT or displayed in the chat - its only part of that specific prompt.
To make the process of adding relevant context easier, we added the Embedded Knowledge Store action. This action enables you to add 'articles' to a 'knowledge store'. You can build your knowledge store manually by using the Embedded Knowledge Store Browser (on the studio File menu) - this allows you to quickly import files & documents (PDF, Word, Markdown, text files). You can also use the Embedded Knowledge Store action within an Automation, if you want to automate the process of updating your knowledge store (for example, you could send emails to a specific address to add to the knowledge store, or a database pull or file pickup).
When adding articles to the knowledge store, ThinkAutomation automatically adds embeddings. Embeddings are a list of numbers (a 'vector') that are used to measure the relatedness of text strings. This enables a much more accurate list of relevant articles when doing a search, since the search is based on the meaning - not just on matching keywords.
Once your knowledge store is populated with articles you can then add another ChatGPT action to your Automation and set the 'Add Context To Conversation' option. Here you select the 'Search The Embedded Knowledge Store For Context' option. In the Search Text entry, you set the %variable% containing the incoming chat message. Now - when a chat message comes in your Automation will search your knowledge store for the top x most relevant articles and add these to the context that its going to include.
Responses from ChatGPT will then be much more accurate and up-to-date since you are giving it relevant information.
All you need to do is keep your knowledge store updated.
You can also add 'Static Context'. This can be any text, for example you could lookup information from a database, CRM or external knowledge base. So, for example: We can ask the user to enter their email address at the start of the chat. This is assigned to the %Msg_FromEmail% variable inside your Automation. You could use this to lookup recent orders, appointments, or recent support tickets from a database. This can be added as context too - so the user could ask about their recent orders, appointments etc.
You don't need to worry about adding the same context twice. If the context is already part of the current conversation, ThinkAutomation wont add it again.
Our automation would then look like this:
The incoming message from the Web Chat form will be in the %Msg_Body% field. We trim it and decode any HTML entities. This is then assigned to the %Prompt% variable.
On the Web Chat Message source there is the option Send Token On Chat Start. If this is enabled an auto-message set to
[webchatstart] will be sent to the Automation after the user has entered their name. We check for this and send back a welcome message.
Then we add the Default Context. This tells ChatGPT how to behave. This should be something like:
You are a very enthusiastic representative working at Parker Software. Given the provided sections from our documentation, answer the user's question using only that information, outputted in markdown format.
We then add context from the knowledge store - we search the knowledge store for the 5 most relevant articles relating to %Prompt%.
Finally, after adding the default and knowledge store context we ask ChatGPT to respond to the %Prompt%.
The response from ChatGPT is then returned by the Automation - which will be displayed in the Web Chat form.
That's it! A working bot using the full natural language processing of standard ChatGPT but using local/private knowledge store. All chat messages & responses will be stored in your Message Store like any other message.
Note: If you have entered your OpenAI API key into the ThinkAutomation Server Settings - and have created a Knowledge Store then the above Automation will be created automatically when you create a new Web Chat Message source.
Benefits Of Using ThinkAutomation To Create ChatGPT Powered Bots
- You don't need to train your own ChatGPT model. You can use standard ChatGPT without training. This is much more cost effective - and you don't have to keep re-training whenever your local knowledge changes.
- You can make use of local (on-premises) knowledge without paying for 3rd party services to do this (you only need an OpenAI account). Your knowledge store is maintained locally - and does not need to be uploaded to any external service. So in the long run the costs are much lower.
- You don't need to be concerned about uploading potentially confidential or sensitive information to an outside service. Your chat bot can still be hosted publicly via the ThinkAutomation Gateway - but this is just the HTML form. All of the ChatGPT calling and knowledge search is handled by your local ThinkAutomation server.
- You could use the same Automation to reply to incoming emails, SMS messages or it's API. ThinkAutomation itself doesn't care where the incoming message is from. So, creating automated first line support email replies is easy .
See the ThinkAutomation help: ChatGPT and Embedded Knowledge Store actions for more information.
Watch a demo here: