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.
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
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':
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.
Create another field called 'Introduction (formatted)' with type 'Formula' and copy and paste this formula:
(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.
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'.
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.
Under Application, select 'OpenAI'.
Under Authorization, copy and paste your OpenAI API key.
Under Endpoint select 'Create chat message completion'.
It's also helpful to give your request a name. We'll call ours 'Create Blog Introductions'.
Click 'Save and Continue.'
On the next sreen, set the Model to '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.
Select your output Table, 'Prompt' for Field and 'Needs Intro' for Run for every record in view.
Your parameters should now look like this. Click 'Save & Run'.
On the Response field mapping modal that opens up, set the 'Message' field to map to the 'Social post' field and click 'Save & Run'.
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.
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'.
Select a plan that suits your requirements and enter your payment information.
In Data Fetcher, click 'I've done this'.
Under Schedule click '+ Authorize'.
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'.
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'.
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.