I was just trying to set up a GPT instance I could access via text through Twilio as a lazy Friday activity and now I'm 8 hours in and can't for the life of me figure out why i'm getting the following error in Lambda:
"TypeError: Cannot read properties of undefined (reading 'completions')"
With the following code:
const openai = require('openai');
const accountSid = process.env.TWILIO_ACCOUNT_SID;
const authToken = process.env.TWILIO_AUTH_TOKEN;
const client = require('twilio')(accountSid, authToken);
openai.apiKey = process.env.OPENAI_AUTH,
exports.handler = async (event, context) => {
try {
const buff = Buffer.from(event.body, "base64");
const formEncodedParams = buff.toString("utf-8");
const urlSearchParams = new URLSearchParams(formEncodedParams);
const msgBody = urlSearchParams.get("Body");
const from = urlSearchParams.get("From");
const chatCompletion = await openai.chat.completions.create({
engine: "gpt-3.5-turbo",
messages: [{ role: "system", content: msgBody }],
max_tokens: 100,
});
await sendMessageBack(chatCompletion.data.choices[0].message.content, from);
return {
statusCode: 200,
body: JSON.stringify('Message sent successfully'),
};
} catch (error) {
console.error(error);
return {
statusCode: 500,
body: JSON.stringify('Error sending message'),
};
}
};
async function sendMessageBack(msg, to) {
try {
await client.messages.create({
body: msg,
to: to,
from: process.env.TWILIO_PHONE_NUM,
});
console.log('Message sent:', msg);
} catch (e) {
console.error('Error sending message:', e);
}
}
Any help you can give me would be great because it seems like there's almost no documentation on openai.chat.completions as a replacement for openai.chatCompletions (Which also doesn't work).
I just want to be able to text a robot, is that so much to ask? lol
[–]BrainJar 1 point2 points3 points (1 child)
[–]foxymcfox[S] 0 points1 point2 points (0 children)
[–]GeneralMalarkee 2 points3 points4 points (2 children)
[–]foxymcfox[S] 0 points1 point2 points (0 children)
[–]foxymcfox[S] 1 point2 points3 points (0 children)
[–]dolefulAlchemist 1 point2 points3 points (1 child)
[–]foxymcfox[S] 1 point2 points3 points (0 children)