Automate Customer Support with GPT Assistants and Airtable

Greg Vonf @ Business Automated
6 min readNov 21, 2023

Is this finally the time when your GPT assistant is able to know your company pricing and product features?

AI Assistant generated by AI DALL.E v3

Customer support teams often find themselves answering the same questions repeatedly. With the latest OpenAI Assistants API, you can now leverage GPT-3 to automatically generate support responses based on your company’s internal knowledge. In this post, I’ll walk you through how to build a custom GPT assistant, connect it to your knowledge base, use it to create conversation threads, generate accurate replies, and integrate everything with Airtable and Gmail. Let’s get started!

Set Up Your GPT Assistant

First, we need to set up a custom GPT assistant within the OpenAI Platform playground. Here are the steps:

  1. Create a new assistant and give it a name.
  2. Provide general instruction for the assistant. Know we will be overriding those later.
  3. Select the gpt-4-1106-preview model since it's the best for assistants right now.
  4. Enable the retrieval feature to connect your knowledge base.
  5. You may enable “Code Interpreter” if you expect some data analytical tasks
  6. Save the assistant and note down its ID (under the Name) — we’ll need this later.

Now we have an empty assistant ready to be configured.

Creating sample Assistant using the Open AI Platform backend

Add Your Knowledge Base

Next, we need to add our knowledge base documents that the assistant can reference when generating replies. For this demo, I’m using an Airtable base with pre-populated FAQs grouped into categories like pricing, features, etc.

Using Airtable as Knowledge Store

You can download the demo base from my Gumroad page.

To upload the FAQs into the OpenAI assistant knowledge store, I’m using a Make.com scenario with the following steps:

  1. Fetch all records from the Airtable FAQ table
  2. Aggregate the questions, types, and answers into a Markdown file
  3. Make an API call to OpenAI to upload the Markdown file and re-train the assistant on the new file
  4. Delete any old FAQ files and remove old file from the assistant
Upload file scenario in Make.com, download the ready made blueprints here

If you have not used Make.com it is an API integration and automation tool — similar to Zapier but more flexible and pleasant to use.

The key steps are handled by these Make modules:

  • create a new Markdown file
Using Text aggregator to create a mardown file (note that the output of Airtable for the field Answer is already in markdown format)
  • Upload assistant file to OpenAI
POST https://api.openai.com/v1/files

Header:
"Authorization: Bearer $OPENAI_API_KEY"
(Above authorization should be used in ALL API calls to open AI)

Body type "Multipart/form-data"

purpose="assistants"

file=@hereGoesTheRawFile

This translated to quite nice mapping in Make

Uploading file to assistant in OpenAPI
  • If old file exist - delete it from Open AI
DELETE https://api.openai.com/v1/files/{{file id here}}
Delete file from Open AI with HTTP module in Make
  • remove file association from old assistant
DELETE https://api.openai.com/v1/assistants/{{your assistant ID}}/files/{{file ID}}


Headers:
"Authorization: Bearer $OPENAI_API_KEY"
"OpenAI-Beta: assistants=v1"
#this header is needed for all assistants API
#operations, will likely change in the future
Remove association from the assistant
  • Add new file to the assistant
POST https://api.openai.com/v1/assistants/{{assistant id}}/files

Headers:
"Authorization: Bearer $OPENAI_API_KEY"
"OpenAI-Beta: assistants=v1"

Body:
"Content-Type: application/json"

{
"file_id": "{{3.data.id}}"
}
Select POST method
Make sure to select “Parse response” = “Yes”

Generate Reply Threads

With the knowledge base connected, we can start generating replies by:

  1. Creating a new thread when a form is submitted
  2. Adding the customer question as a message
  3. Running the thread through the assistant
  4. Repeatedly checking if processing is complete
  5. Retrieving the generated response

Here is what this looks like in the Make scenario:

Scenario to create Open AI Assistant responses in Make.com, download the ready made blueprints here

Some key points:

  • What triggers sending of the mails and generating replies is an automation that sends record ID to Make.com:
Trigger based on “Generate reply” and “Send email”
Make sure to send ID of the record as “recordId” to Make

Read more below how to create script to send triggers from Airtable

  • NEW! Create a new thread for each conversation. This is a new approach used by Assistants — different from completion API
POST https://api.openai.com/v1/threads

Headers:
"Authorization: Bearer $OPENAI_API_KEY"
"OpenAI-Beta: assistants=v1"
Initiate new thread

Make sure to enable parse response to get the details of the response object and ID of newly created thread

  • We construct a detailed user message prompt with instructions for the assistant
User message prompt
Assistant instructions
  • We need to add the user message to the thread
POST https://api.openai.com/v1/threads/{{thread ID}}/messages

Headers:
"Authorization: Bearer $OPENAI_API_KEY"
"OpenAI-Beta: assistants=v1"

Body:
"Content-Type: application/json"

{
"role": "user",
"content": {{23.json}}
}
Adding message to a thread
including previously encoded JSON
  • Run Assistant on your thread
POST https://api.openai.com/v1/threads/{{thread ID}}/runs

Headers:
"Authorization: Bearer $OPENAI_API_KEY"
"OpenAI-Beta: assistants=v1"

Body:
"Content-Type: application/json"

{
"assistant_id": "Assistant ID",
"instructions": {{34.json}}
}
Include ID of your assistant and instructions
  • The response doesn’t come immediately — we need to poll until processing completes
GET https://api.openai.com/v1/threads/{{thread ID}}/runs/{{run ID}}

Headers:
"Authorization: Bearer $OPENAI_API_KEY"
"OpenAI-Beta: assistants=v1"
We keep polling the run endpoint untill we get status=complete
  • We extract the text from the returned message
GET https://api.openai.com/v1/threads/{{thread ID}}/runs/{{run ID}}

Headers:
"Authorization: Bearer $OPENAI_API_KEY"
"OpenAI-Beta: assistants=v1"
Once the thread has finished running you are able to download all messages associated with the thread.

The response of the Assistant will be on the top of the content array in the data object.

{{33.data.data[].content[].text.value}}

Now we can take form submissions, create threads, and get automated responses!

Connect Airtable and Gmail

The last step is connecting everything to Airtable forms and Gmail.

When the “Send Email” button is clicked, record ID is passed via the trigger to the scenario that constructs a reply email using Gmail and sends it to the customer.

Final step is connecting Gmail. Note that we use Markdown component to convert Airtable markdown (rich field text) to HTML that can be accepted by Gmail

Settings for Gmail module in Make

Now when a customer fills out the form, everything is handled automatically — from getting the generated response to sending a personalized email reply!

Conclusion

With the new GPT assistant API, you can easily create AI-powered customer support bots personalized to your business knowledge. Connecting it to Airtable and Gmail transforms the entire customer inquiry process — from submission to response.

Let me know if you have any other ideas for automating customer support with GPT! I’m excited to see all the new use cases as the assistant API matures.

Get the Airtable base starter and ready made blueprints here.

Watch the full walk through tutorial here:

Useful readings:

  1. Open AI API docshttps://platform.openai.com/docs/api-reference/assistants
  2. Assistants API documentationhttps://platform.openai.com/docs/assistants/how-it-works

Visit our Gumroad store for a ready made blueprints and as always do not forget to checkout our Youtube Channel for all things related to automating your business!

Business Automated is an independent automation consultancy. If you would like to request custom automation for your business, visit us at https://www.business-automated.com

If you like our tutorials — buy us a coffee☕: https://www.buymeacoffee.com/business

Follow us on Twitter🐦: https://twitter.com/BAutomated

Watch more on YouTube ️📺: https://www.youtube.com/c/BusinessAutomatedTutorials

--

--

Greg Vonf @ Business Automated

Greg is the founder of Business Automated, an agency helping small businesses streamline and simplify their processes. For more visit www.business-automated.com