Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version
  1. First, you need to get an OpenAI API key from the OpenAI website.
  2. In your HTML file, you'll need to include a script tag that references the OpenAI API endpoint. This can be done by adding the following code to the head section of your HTML file:
<script src="https://cdn.jsdelivr.net/npm/@openai/api@0.4.5/browser.js"></script>
  1. After that, you can use the following JavaScript code to configure your OpenAI API:
const openai = require('openai');

const apikey = "YOUR_SECRET_API_KEY";
const modelengine = "davinci";
const prompt = "Hello, OpenAI!";

openai.apiKey = apikey;

openai.complete({
  engine: modelengine,
  prompt: prompt,
  maxTokens: 5,
  n: 1,
  stop: "\n",
}).then(console.log);
  1. Replace the placeholder YOUR_SECRET_API_KEY with your actual OpenAI API key.
  2. Customize the modelengine and prompt variables to suit your needs.
  3. Run the code and test the OpenAI API integration.