Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
const got = require('got');
exports.handler = function(context, event, callback) {
let message = "";
let twiml = new Twilio.twiml.MessagingResponse();
const prompt = event.Body !== undefined ? event.Body.trim() : event["prompt"]
got.post('https://api.openai.com/v1/engines/davinci/completions', {
json: {
"prompt": prompt,
"max_tokens": 50,
"temperature": 0.9,
"top_p": 1,
"presence_penalty": 0.4,
"frequency_penalty": 0.75,
"stop": "\n",
},
headers: {
'Authorization': `Bearer ${context.OPENAI_SECRET_KEY}`,
}
})
.json()
.then(response => {
message = response.choices[0].text
})
.catch(error => {
console.log(error);
message = "Oops! Something went wrong.";
})
.finally(() => {
twiml.message(message);
callback(null, twiml);
});
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.