0

In the OpenAI API, I would like to run 3 prompts, add the results to a variable called text, and display them all at once. Right now, the problem is that I can only do 1 prompt at a time. Is there a way to run 3 prompts at once? If so, please add some example codes for me to use. Thanks.

import { Configuration, OpenAIApi } from "openai";

const configuration = new Configuration({
  apiKey: process.env.OPENAI_API_KEY,
});
const openai = new OpenAIApi(configuration);

export default async function (req, res) {

const completion = await openai.createCompletion({
model: "text-davinci-002",
temperature: 1,
max_tokens: 3000,
top_p: 1,
frequency_penalty: 2,
presence_penalty: 2,
prompt: "tell me about one. tell me about two. tell me about three.",
});
res.status(200).json({ result: completion.data.choices[0].text  });

}
frosty
  • 2,559
  • 8
  • 37
  • 73
  • perhaps with 3 API calls in parallel? or does OpenAI not allow that? – user253751 Oct 26 '22 at 04:48
  • @user253751 I don't think it allows it. When I tried to use the entire export default async function again, it says I can only export it once. – frosty Oct 26 '22 at 04:56
  • That's because you don't understand what this code does and what words like `export` mean. Can I suggest learning Javascript? – user253751 Oct 26 '22 at 04:57

1 Answers1

0

Put the prompt into an array:

prompt: ["tell me about one.", "tell me about two.", "tell me about three."]
mikecpl
  • 68
  • 8
  • 1
    Your answer could be improved with additional supporting information. Please [edit] to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Mar 05 '23 at 19:56