I’m trying to use the API to summarize a 180 word paragraph down to 250 characters or less. But I’m getting a blank response.
For example, here is the payload that I’m sending:
{ prompt: 'Please provide a summary of the story in exactly 250 characters or less: "This All-American Deer is ready for the celebration of America\'s independence day! The deer is dressed in a full set of patriotic gear and a star-spangled top hat. After a full day of prepping, the deer is ready to set off and celebrate July 4th in style.The deer starts by marching in a parade, proudly waving an American flag and cheering for every float that passes by. After the parade, the deer meets up with friends for a picnic in the park. They all share stories about the history of the country, and the deer excitedly points out all the symbols of freedom that can be found in their surroundings.The day finishes with a fireworks display, and the deer takes a few moments to reflect on the greatness of America and all the people that have contributed to its success. The deer looks up at the night sky, takes a deep breath, and celebrates the independence of the United States of America."',
temperature: 0.7,
max_tokens: 375 }
And here is the response that I’m getting
{ id: '<id>',
object: 'text_completion',
created: 1687749379,
model: 'text-davinci-003',
choices: [ { text: '', index: 0, logprobs: null, finish_reason: 'stop' } ],
usage: { prompt_tokens: 203, total_tokens: 203 } }
Anyone got any tips on what I could do to fix this?
Update: Here’s a snippet of my javascript code. The only setup is the API key:
function generateShortDescriptionPrompt(longDescription){
return `Please provide a summary of the story in exactly 250 characters or less: "${removeWhiteSpaces(longDescription)}"`;
}
function getShortDescriptionFromOpenAI(longDescription){
var prompt = generateShortDescriptionPrompt(longDescription);
var response = sendOpenAIRequest_(prompt, 375);
return response.choices[0].text.trim();
}
function sendOpenAIRequest_(inputPrompt, inputMaxTokens) {
var configuration = {
apiKey: "<key>",
};
var openaiEndpoint = "https://api.openai.com/v1/engines/text-davinci-003/completions";
var payload = {
prompt: inputPrompt,
temperature: 0.2,
max_tokens: inputMaxTokens, // Set a higher value for maximum tokens
};
var headers = {
"Content-Type": "application/json",
"Authorization": "Bearer " + configuration.apiKey
};
var options = {
method: "post",
headers: headers,
payload: JSON.stringify(payload),
muteHttpExceptions: true
};
var response = UrlFetchApp.fetch(openaiEndpoint, options);
var completion = JSON.parse(response.getContentText());
return completion;
}