Help

Re: chatGPT for Airtable automation.

34147 0
cancel
Showing results for 
Search instead for 
Did you mean: 
chrisbyrne
5 - Automation Enthusiast
5 - Automation Enthusiast

Using chatGPT in an Airtable automation. 

In my use case, the automation triggers on when an Airtable record matches conditions,
then follows with 2 actions, run script and update record. Adjust the first part of the prompt
with your own use case. Tip: Use chatGPT to help you write a prompt for chatGPT (!)

 

let inputConfig = input.config();
text = `${inputConfig.text}`;

var key = "openai-api-key";

var url = "https://api.openai.com/v1/completions";

prompt = "Reword this text to grade 9 reading level: " + text;

var gpt = {
model : "text-davinci-003",
prompt : prompt,
temperature : 0,
max_tokens : 1024
};

response = await fetch(url, {
method: 'POST',
body: JSON.stringify(gpt),
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + key,
}
});

answer= await response.json();

data=answer.choices[0].text;

output.set('your-airtable-field',data);

 

16 Replies 16
Scott_Gould
6 - Interface Innovator
6 - Interface Innovator

BOOM.

Aaron_Hanson
4 - Data Explorer
4 - Data Explorer

this is awesome - though davinci isn't quiet the same or as good as chatgpt though right?  

chrisbyrne
5 - Automation Enthusiast
5 - Automation Enthusiast

chatGPT isn't a model though.

MaxValle
4 - Data Explorer
4 - Data Explorer

Hi Guys,

where can I find the ChatGPT API?
It seems they can no longer be activated. I have a Pro account.

Thank you 🙂

 

Karl_L
6 - Interface Innovator
6 - Interface Innovator

Hi @chrisbyrne 
and thank you for this show and tell!

I'm trying to do basically the same thing, but get only "undefined" responses. I might be doing some simple mistake, any idea what it is? Posting my edited script below

 

let inputConfig = input.config();
text = `${inputConfig.textToMakeShorter}`;

var key = "XXXXX";

var url = "https://api.openai.com/v1/completions";

prompt = "Summarize this text: " + text;

var gpt = {
model : "text-davinci-003",
prompt : prompt,
temperature : 0,
max_tokens : 1024
};

response = await fetch(url, {
method: 'POST',
body: JSON.stringify(gpt),
headers: {
'Content-Type': 'application/json',
'Authorization': 'Bearer ' + key,
}
});

answer= await response.json();

data=answer.choices[0].text;

output.set('shortenedText',data);

 

chrisbyrne
5 - Automation Enthusiast
5 - Automation Enthusiast

It's at capacity rn so could be that, it's something you will have to allow for.
In my app I have a retry number field that gets incremented if it fails.
 
What I would do now, is test the step before the prompt with
console.log(key) and console.log(url) to make sure these are correct.

The code I provided is bare bones without error checking, to make it clear what's happening.

You could add this before the answer= await response.json();

if (!response.ok) {
  console.error(`Error:  ${response.status}`);

This should cough up whatever is going on.

Jean-Philippe_E
7 - App Architect
7 - App Architect

Hello,
I wondering if it would be possible to perform ChatGPT summerisation when the WebClipper perform the capture of the page ?

Good or Bad idea ?

  • It would avoid capturing and storing all the junk of a full webpage
  • On the other hand as a "function" we could play it again and again

How do you handle to long article ? Did you try the GPT 3.5 with it's lower fees ?

Thanks

To handle long articles you will need to strip the text so it's less than 1,500 words (GPT limit)
text = text.substring(0,2048); 

Though with GPT4 it's expanded to 32k, a gamechanger!

Jean-Philippe_E
7 - App Architect
7 - App Architect

Yes playing with it 32k is interesting but I think expensive at scale.
Are you sure token = word ? What does it means for an html content ?

@jeanyh Good point, not exactly equal but seems a rule of thumb?Screen Shot 2023-03-28 at 15.45.35.png

 

Karl_L
6 - Interface Innovator
6 - Interface Innovator

As a late update on my own issue posted above:

I had not understood that the ChatGPT API is not included in the ChatGPT Plus subscription. 

After having signed up for the API service this worked beautifully. 

Again, big thanks to @chrisbyrne for this script

christopher_so1
4 - Data Explorer
4 - Data Explorer

Is anyone having issues now. This use to work perfectly then all of a sudden starting yesterday it is now giving this error: 

TypeError: Cannot read properties of undefined (reading '0') at main on line 27
 

 

Further exploration is coming down to a HTTP 429 Error code. ?????

dan2
4 - Data Explorer
4 - Data Explorer
 I've been using this script below quite a bit, and it's a game changer. It lets you take a record column and feed that as a prompt into a gpt chat model and then output the response. I've used it quite a bit to enrich data and do specific tasks.

How do I use it? You'll need to add the script airtable extension and add the following code. If it's in ALL_CAPS you would put unique information related to your table in the script. In this case you need to put the table, view, a field for the system prompt, a field for the user prompt and a field for the output response that you get from gpt. You can adjust the Chat Model and Temperature. There are other parameters you can add to it as well. And don't forget your openai api key.

 

 

let table = base.getTable("TABLE_NAME");
let view = table.getView("VIEW_NAME");
let records = await view.selectRecordsAsync({fields: table.fields});
const apiKey = 'OPENAI-API-KEY';
const url = 'https://api.openai.com/v1/chat/completions';

for (let record of records.records) {
let messages = [
{ role: "system", content: record.getCellValue("FIELD_NAME") },{ role: "user", content: record.getCellValue("FIELD_NAME1") }
];
let data = {
messages: messages,
model: 'gpt-3.5-turbo',
temperature: 0.3,
};
let options = {
headers: {
'Content-Type': 'application/json',
'Authorization': `Bearer ${apiKey}`
},
method: 'POST',
body: JSON.stringify(data)
};
console.log(options)
let response = await fetch(url, options);
console.log(response)
let json = await response.json();
let AIResponse = json.choices[0].message;
await table.updateRecordAsync(record.id, {OUTPUT_FIELD: AIResponse.content});
}

 

 

For those of you who don't want to write Javascript code — but would love to integrate Airtable and ChatGPT in a no-code/low-code way — it's great to know that Make supports ChatGPT, DALL-E, and Whisper!

I give a brief overview of how to use Airtable with ChatGPT on this episode of the BuiltOnAir podcast.

If you're just getting started with Make, there is a small learning curve. To help, I created this basic navigation video. In that thread, I also provide the links to a few other Make training resources there as well.

p.s. If anybody would like to hire an expert Airtable consultant to help them with any of this, please feel free to contact me through my website: Airtable consultant — ScottWorld

kathlyn
5 - Automation Enthusiast
5 - Automation Enthusiast

What is the role of ChatGPT in automating processes within Airtable?