Help

Can't updateRecordAsync - Long Text Field

482 0
cancel
Showing results for 
Search instead for 
Did you mean: 
clayc210
4 - Data Explorer
4 - Data Explorer

I'm trying to generate some content using OpenAi's new ChatGPT API and I'm having an issue with updating the record field in my table with the response from their API. I have no idea why but for some reason I can't update the Long Text Field with the string in their response payload. 

Here is my script. Weirdly, it will work if I do a regex search using `exec` on the response first and then try to update the record... but it's only the first paragraph.

 

 

// generates blog post content
let table = base.getTable('Blog Posts');

let openaiUrl = "https://api.openai.com/v1/completions"

let record = await input.recordAsync('select a record to use', table);

if (record) {

    // construct the body
    let body = {
        "prompt": "Write a 1,000 word blog post about how to become a " + record.getCellValue("Trade") + ".",
        "temperature": 0.7,
        "max_tokens": 1024,
        "model": "text-davinci-003",
        "top_p": 1.0,
        "frequency_penalty": 0.0,
        "presence_penalty": 0.0
    }

    let response = await fetch(openaiUrl, {
        method: 'POST',
        body: JSON.stringify(body),
        headers: {
            'Content-Type': 'application/json',
            'Authorization': 'Bearer xx',
        }
    });
    let data = await response.json();

    console.log(data)

    /* this works for some reason but it only has the first paragraph */

    let str = /[^A-Za-z0-9](.+)/.exec(data.choices[0].text)

    table.updateRecordAsync(record,
    {
        "Blog Content": str
    });

    /* this does not work and i have no idea why. it will correctly log 
    all the text to the console but will not update the record

    let data = await response.json();

    let content = data.choices[0].text;

    console.log(content)

    table.updateRecordAsync(record,
    {
        "Blog Content": content
    })
    */
}​

 

And here is the response from the OpenAI API

 

 

{id: "cmpl-6MniOmlp6iMMynnByCHBsuXhWTIge", object: "text_completion", created: 1670892340, model: "text-davinci-003", choices: Array(1)…}
id: "cmpl-6MniOmlp6iMMynnByCHBsuXhWTIge"
object: "text_completion"
created: 1670892340
model: "text-davinci-003"
choices: Array(1)
0: Object
text: "

Becoming a carpenter is a great way to put your skills to work, earn a good living, and build something you can be proud of. The carpentry trade has been around for centuries and is still an important part of the construction industry today. Whether you want to become a professional carpenter or just do some carpentry work as a hobby, this guide will help you get started. 

First, you’ll need to decide what type of carpenter you want to be. There are two main types of carpenters: residential and commercial. Residential carpenters typically work on projects like building decks, framing houses, and installing cabinets. Commercial carpenters, on the other hand, typically work on larger projects like building office buildings, shopping malls, and other commercial structures. Depending on what type of carpentry you want to do, you may need to obtain additional certifications or training.

Once you’ve decided what type of carpenter you want to be, it’s time to start learning the trade. You can learn carpentry skills through an apprenticeship program, on-the-job training, or through a trade school. An apprenticeship program is a great way to get hands-on experience and learn from an experienced carpenter. On-the-job training involves working with an established carpenter and learning the trade as you go. Trade schools are another option for those who want to learn more about carpentry.

You’ll also need to become familiar with the tools of the trade. A good carpenter has a wide variety of tools, and it’s important to know how to use them correctly and safely. Common tools include saws, hammers, drills, and other power tools. It’s a good idea to practice using these tools before taking on any major projects.

In addition to the tools of the trade, you’ll also need to become familiar with the construction materials used in carpentry. Common materials include wood, nails, screws, and other hardware. You’ll need to understand how to use these materials properly and safely to ensure the highest quality results.

Finally, it’s important to stay up to date on the latest techniques and safety standards in carpentry. The carpentry industry is constantly changing, and it’s important to stay informed. You can do this by reading industry publications, attending trade shows, or taking classes to stay ahead of the curve.

Becoming a carpenter is a great way to make a living and build something you can be proud of. With the right training, tools, and safety knowledge, you can start making your mark in the carpentry trade. Good luck!"
index: 0
logprobs: null
finish_reason: "stop"
usage: Object
prompt_tokens: 15
completion_tokens: 560
total_tokens: 575

 

0 Replies 0