如果这看起来很简单,我很抱歉,我对这个相对来说是新手。
正如标题中所说,我得到了错误“等待只在异步函数和模块的顶级主体中有效”,尽管我很困惑,因为等待是在主体的顶部?
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:"],
});
2条答案
按热度按时间00jrzges1#
您可以将代码 Package 在异步
IIFE
中:62o28rlo2#
如果您可以将代码更改为python,这可能会有所帮助:https://pypi.org/project/openai-async/
只要做到:
然后例如: