题意:OpenAI 没有返回结果吗?
问题背景:
I'm trying to use the OpenAI beta but I can't seem to get a result. I'm accessing the API via an NPM package (openai-api - npm). I have that setup and working but when I make a request the response I'm getting is missing any content in the response object.
我正在尝试使用 OpenAI 的 beta 版本,但似乎无法获得结果。我是通过 NPM 包(openai-api - npm)来访问 API 的。我已经设置好了并且它正在工作,但当我发起请求时,我得到的响应对象中没有包含任何内容。
Here's my code 这是我的代码
const suggestedDescription = await openai.complete( {
engine: 'davinci',
prompt: metadata.description,
maxTokens: 20,
temperature: 0,
topP: 1,
presencePenalty: 0,
frequencyPenalty: 0,
stop: ['...']
} );
The resulting object looks like this: 生成的对象看起来像这样:
suggestedDescription { text: '', index: 0, logprobs: null, finish_reason: 'stop' }
Any thoughts? 你怎么看?
问题解决:
don't use openai-api anymore, it's not supported officially. use npm i openai instead.
不要再使用 openai-api 了,因为它不是官方支持的。请使用 npm i openai
来安装。
Code example would be something like this:
代码示例大致如下:
export const askOpenAi = async () => {
const prompt = `input: What is human life expectancy in the United States?
output:`
const response = await openai.createCompletion("text-davinci-001", {
prompt: prompt,
temperature: 0,
max_tokens: 100,
top_p: 1,
frequency_penalty: 0,
presence_penalty: 0,
stop: ["input:"],
});
return response.data;
}