Ron I
Ron I

Reputation: 4250

Run OpenAI API document example in Node: where do I put sample code?

Objective: HTML input form that sends a prompt to openai's API and returns a message.

Completed Successfully:

Dev Environment:

Question: How do I call openai?

Per the documentation page: https://beta.openai.com/docs/api-reference/authentication

Step 1: npm install openai

Step 1 completed: The openai folder is in the node_modules folder, as expected.

Step 2 in docs:

import { Configuration, OpenAIApi } from "openai";
const configuration = new Configuration({
    organization: "org-sdfds34dsf",
    apiKey: process.env.OPENAI_API_KEY,
});
const openai = new OpenAIApi(configuration);
const response = await openai.listEngines();

Step 2 questions

Upvotes: 1

Views: 3979

Answers (1)

Faizan Ul Haq
Faizan Ul Haq

Reputation: 561

I think problem is how you are importing modules

Use

const { Configuration, OpenAIApi } = require("openai");

Instead of

import { Configuration, OpenAIApi } from "openai";

Upvotes: 2

Related Questions