Hello. I would like to run this Node.js script in a function node (used in this article).
import OpenAI from "openai";
const openai = new OpenAI({apiKey: '...'});
async function main() {
const response = await openai.chat.completions.create({
model: "gpt-4-vision-preview",
messages: [
{
role: "user",
content: [
{ type: "text", text: "What’s in this image?" },
{
type: "image_url",
image_url:
"https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg",
},
],
},
],
});
console.log(response.choices[0]);
}
main();
I copied the above (and inserted my API key) and put return msg;
as the last line of code.
I then wired the output of the above function node to an http request node with these settings
(seems odd to have to pass my API key again as bearer authentication, but am pretty sure that URL requires it).
Doing the above yields nothing in the debug screen. I also wired a separate debug node after the function node and still get nothing, indicating my function node is not doing anything. I have a feeling that I am missing something obvious here. Should the above node.js script work in Node-RED, or do I need to do something else?
Here is the URL that I was trying to use:
https://upload.wikimedia.org/wikipedia/commons/thumb/d/dd/Gfp-wisconsin-madison-the-nature-boardwalk.jpg/2560px-Gfp-wisconsin-madison-the-nature-boardwalk.jpg