抱歉,如果这看起来很简单的话,我对这件事还是比较陌生的。
正如标题中所说的,“等待仅在异步函数和模块的顶层主体中有效”,但我感到困惑,因为等待是在主体的顶部吗?
const { Configuration, OpenAIApi } = require("openai");
const configuration = new Configuration({
apiKey: 'Api Key Go Brrrrrr',
});
const openai = new OpenAIApi(configuration);
const response = await openai.createCompletion("text-davinci-002", {
prompt: "You: What have you been up to?\nFriend: Watching old movies.\nYou: Did you watch anything interesting?\nFriend:",
temperature: 0.5,
max_tokens: 60,
top_p: 1.0,
frequency_penalty: 0.5,
presence_penalty: 0.0,
stop: ["You:"],
});发布于 2022-04-27 11:58:43
您可以将代码包装在异步IIFE中。
// add ; at the start to be safe, this is one of the very few cases where semicolons matter in JS
;(async ()=>{
const response = await openai.createCompletion("text-davinci-002", {
prompt: "You: What have you been up to?\nFriend: Watching old movies.\nYou: Did you watch anything interesting?\nFriend:",
temperature: 0.5,
max_tokens: 60,
top_p: 1.0,
frequency_penalty: 0.5,
presence_penalty: 0.0,
stop: ["You:"],
});
})();https://stackoverflow.com/questions/72028213
复制相似问题