Reputation: 4250
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
SyntaxError: Cannot use import statement outside a module
errorUpvotes: 1
Views: 3979
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