Help with Node-red and openai integration

with reference to this.

I’m pretty new to all this and hoping someone can help…
GPT tried but to no avail :slight_smile:
This is my text in the openai node.

const { Configuration, OpenAIApi } = openai;
const configuration = new Configuration ({ apiKey: “sk-kfgjskdhn48kgfkjsngi” });
const openaiApi = new OpenAIApi(configuration);
openaiApi.createCompletion({
model: “text-davinci-003”,
prompt: msg.prompt,
temperature: 0.7,
max_tokens: 1200,
top_p: 1,
frequency_penalty: 0,
presence_penalty: 0,
}).then(answer => {
msg.answer = answer
node.send(msg);
node.done();
});
return

i keep getting the error, “TypeError: Configuration is not a constructor” any ideas? i am using Node-red in Home assistant Supervisor. Thanks

did you add openai as a module in the function node?

https://nodered.org/docs/user-guide/writing-functions#using-the-functionexternalmodules-option

Hi! I think you’re trying to create a bot to talk to Home Assistant with a Telegram Bot and ChatGPT? After the recent updates in Home Assistant I found an easy solution with a single blueprint: Telegram Bot: Conversation with Assist (and others like OpenAI)

I hope it helps!