Connect to the GPT-4 API in Airtable with No-Code

May 11, 2023Rosie Threlfall

In this guide, we'll show you how to connect the GPT-4 API to Airtable and use this to create a series of introduction paragraphs for various financial blog posts.

GPT-4 is the latest AI language model developed by OpenAI. GPT-4 is currently only available as an API for developers to build applications and services.

The GPT-4 API is now generally available. You will need to have a payment card set up for the OpenAI API. This is a different thing from ChatGPT Plus.

The current version of GPT-4 is also limited to 8,192 tokens. If your prompt is too large, you can use the GPT-4-32K model, which has a limit of 32,768 tokens.

We'll be using Data Fetcher to connect to the GPT-4 API in Airtable. Data Fetcher is an Airtable extension for connecting Airtable to any application or API with no-code.

Create Blog Posts Table

To begin setting up the Airtable GPT-4 integration, create a table called 'Blog Posts' in a new Airtable base.

In the default 'Name' field, enter some blog titles for GPT-4 to create intros for. Here are some suggestions (or you can use your own):

  • Understanding Stock Buybacks: Why Companies Choose to Repurchase Shares

  • Capital Budgeting 101: A Guide to the Process and its Mechanics

  • Exploring Reverse Stock Splits: Reasons Why Companies Use This Strategy

Connect-GPT4-to-Airtable.jpg

Next, copy and paste the following formula:

CONCATENATE("user:write the introduction paragraph for a blog post with the title '",Name, "''. Do not include the blog post title.")

Paste it into a new field called 'Prompt' with type 'Formula':

Connect-GPT4-to-Airtable-02.jpg

Please note: if you are not familiar with writing prompts for AI, we recommend reading these basic tips and instructions for writing good prompts for OpenAI

Next, create a new field called 'Introduction' and set the type to 'Long text'. We'll be populating this field with the blog post intro paragraphs that we create with the Airtable GPT-4 integration.

Connect-GPT4-to-Airtable-03.jpg

Create another field called 'Introduction (formatted)' with type 'Formula' and copy and paste this formula:

 SUBSTITUTE({Introduction},'"','')

(Occasionally the output from GPT-4 may start with a speech mark which can cause errors. By adding this formula we can solve this issue.)

Create a new Grid view called 'Needs intro' and add these conditions (Set the conditions using the 'Filter' menu);

  • The 'Name' field is not empty.

  • The 'Introduction' field is empty.

Connect-GPT4-to-Airtable-04.jpg

Install Data Fetcher

Install Data Fetcher from the Airtable marketplace. After it launches, sign up for a free Data Fetcher account by entering a password and clicking 'Sign up for free'.

Connect to the GPT-4 API in Airtable

To begin, click 'Create your first request' on the home screen of the extension. By creating Data Fetcher requests, we can set specific parameters that enable us to fetch data from various sources such as websites or APIs.

Create your first request in Data Fetcher

Under Application, select 'OpenAI'.

Generate Company Descriptions with GPT3

Under Authorization, copy and paste your OpenAI API key.

Generate Company Descriptions with GPT3

Under Endpoint select 'Create chat message completion'.

ChatGPT-Airtable-Integration5.jpg

It's also helpful to give your request a name. We'll call ours 'Create Blog Introductions'.

Click 'Save and Continue.'

Connect-GPT4-to-Airtable-05.jpg

On the next screen, set the Model to 'gpt-4o'. This is the latest model from OpenAI, and is cheaper and faster than gpt-4.

gpt-4o model from openai.png

Create an Input Message for GPT-4

GPT-4 takes a series of messages as input. These messages provide guidance to ChatGPT on how to generate responses that align with the specified context. For this example, the messages we set will help the blog post introduction paragraphs to be relevant and sound human-like.

Messages are an array of objects and each object has a role ('system', 'user', or 'assistant') and content (the content of the message).

The 'system' message helps set the behavior of the assistant. For example:

System: "You are a chef who provides cooking tips and recipes." or System: "You are a travel agent assisting with vacation planning."

The 'user' message helps set the behavior of the supposed user. For example:

User: "I would like some healthy dinner ideas" or
User: "I'm interested in beach destinations in Southeast Asia."

The 'assistant' input messages set the initial tone and purpose of the AI assistant. For example:

Assistant: "I can help you with a wide range of topics. How can I assist you today?"

Assistant: "I'm here to provide information and answer your questions. Feel free to ask me anything!"

We'll also set 'content' to send to the AI assistant.

In Data Fetcher, you can specify the messages in the following format: ⁠role:content ⁠⁠(The default is the 'user' role which will be used if no role is specified.)

Please read more about how OpenAI messages work here.

In this tutorial we are giving the AI assistant the role of expert financial copywriter. Copy and paste this line into the Messages box and press return:

system:You are an expert financial copywriter

Next, click the + button to add a reference to the output table.

Connect-GPT4-to-Airtable-06.jpg

Select your output Table, 'Prompt' for Field and 'Needs Intro' for Run for every record in view.

Connect-GPT4-to-Airtable-07.jpg

Your parameters should now look like this. Click 'Save & Run'.

Connect-GPT4-to-Airtable-08.jpg

On the Response field mapping modal that opens up, set the 'Message' field to map to the 'Social post' field and click 'Save & Run'.

Connect-GPT4-to-Airtable-09.jpg

The GPT-4 Airtable integration will now run. The AI generated blog introductions will be created and added to your 'Introduction' field in your output table. These introductions will be relevant to the blog post title and sound like they could have been written by an expert financial copywriter.

Automatically Run the GPT-4 Airtable Integration

By following these steps, creating new blog post introductions will require a manual run of the Data Fetcher request each time. However, with the help of Data Fetcher's paid scheduling feature, you can automate the GPT-4 Airtable integration to run on a regular schedule.

To upgrade your Data Fetcher account under Schedule click 'Upgrade'.

schedule options

Select a plan that suits your requirements and enter your payment information.

data fetcher upgrade pricing plans.png

In Data Fetcher, click 'I've done this'.

Schedule Data Fetcher

Under Schedule click '+ Authorize'.

Schedule Data Fetcher

A new window will appear, prompting you to authorize Data Fetcher's access to your Airtable bases. We recommend selecting 'All current and future bases in all current and future workspaces' to avoid the need to re-authorize access for individual bases in the future.

Click on 'Grant access'.

schedule-authorize-bases.jpg

Within Data Fetcher, you will notice that 'Schedule this request' is now enabled.

Select a schedule for the GPT-4 Airtable integration to run. You can choose intervals of 'Minutes', 'Hours', 'Days' or 'Months', then click 'Save'.

Schedule this request

From now on, whenever you add new blog post titles to your table, GPT-4 will automatically connect to Airtable, generate introduction paragraphs and import them into Airtable based on your chosen schedule.

Related Posts

How to Extract Data from Images in Airtable using AI

How to Extract Data from Images in Airtable using AI

Jul 25, 2024

Zayyad Muhammad Sani

OpenAI
Extract Data from PDFs to Airtable using OpenAI

Extract Data from PDFs to Airtable using OpenAI

Jul 18, 2024

Zayyad Muhammad Sani

OpenAIPDF
How to Use Airtable Generative AI

How to Use Airtable Generative AI

Jul 5, 2024

Andy Cloke

OpenAI