Ask Your Question
1

In HTML, what is the process for using JS to load the openai api configuration?

asked 2021-04-08 11:00:00 +0000

bukephalos gravatar image

edit retag flag offensive close merge delete

1 Answer

Sort by ยป oldest newest most voted
3

answered 2022-06-12 18:00:00 +0000

qstack gravatar image
  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.
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account. This space is reserved only for answers. If you would like to engage in a discussion, please instead post a comment under the question or an answer that you would like to discuss

Add Answer


Question Tools

Stats

Asked: 2021-04-08 11:00:00 +0000

Seen: 11 times

Last updated: Jun 12 '22