This requires js knowledge but asking here because I have this same code working in a nodejs console app on my computer, but for some reason it’s giving me an error when trying to run from a Bubble plugin.
Here’s the code:
async function(properties, context) {
const OpenAI = require('openai');
const fs = require('fs');
const { Readable } = require('stream');
const fileID = properties.selection_id
try {
const openai = new OpenAI({ "apiKey": context.keys["OPENAI API KEY"] });
const thread = await openai.beta.threads.create();
return {
success: true,
message: "Created empty thread"
}
} catch (err) {
return {
success: false,
message: "Message: " + err
}
}
}
The error happens on the openai.beta.threads.create()
:
TypeError: Cannot read properties of undefined (reading 'create')
I’m fairly certain openai
is defined at that point since I’ve run a test, and I’m not sure what else could be undefined. Also not sure why this would give an error in Bubble and not in nodejs locally.
Any ideas what the issue could be?