Hi there
Trying to call chatGPT from a selected line in a note, this is the code I got from … GPT (must say I am not a developper at all).
I have entered my API Key (not displayed here).
Using iPad with iOS 16 latest release, Drafts latest release.
I get the displayed error in the screenshot.
Any help will be appreciated.
// Get the selected line from the Drafts note
const input = draft.getSelectedText();
// Replace this with your own API key
const apiKey = “your_api_key_here”;
const endpoint = “https://api.openai.com/v1/completions”;
const payload = {
“prompt”: input,
“model”: “text-davinci-002”,
“max_tokens”: 2048,
“top_p”: 1,
“frequency_penalty”: 0,
“presence_penalty”: 0
};
const options = {
“method”: “POST”,
“headers”: {
“Content-Type”: “application/json”,
“Authorization”: Bearer ${apiKey}
},
“payload”: JSON.stringify(payload)
};
const response = UrlFetchApp.fetch(endpoint, options);
const output = response.getContentText();
// Replace the selected line with the generated text from GPT
draft.setSelectedText(output);