我正在使用node.js,并且希望使用openai API。
我刚刚从openai操场复制了代码,它看起来像这样
export const askOpenAi = async () => {
const response = await openai.createCompletion("text-davinci-001", {
prompt: "\ninput: What is human life expectancy in the United States?\n",
temperature: 0,
max_tokens: 100,
top_p: 1,
frequency_penalty: 0,
presence_penalty: 0,
stop: ["\n", "\ninput:"],
});
return response.data;
}openai返回的数据如下所示
{
id: '~~~',
object: 'text_completion',
created: ~~~,
model: 'text-davinci:001',
choices: [ { text: '', index: 0, logprobs: null, finish_reason: 'stop' } ]
}在操场上,这段代码工作得很好。

我怎样才能得到正确的回应?
发布于 2022-06-14 04:59:45
应该是这样的:
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;
}在这里,首先,从stop数组中删除\n,因为它将在每个换行符之后停止完成(任何答案都可以在多行中)。其次,不需要在输入前添加额外的\n:。其实并不重要。
最后,通过添加输出:在提示符的最后一个位置,记住给出一些关于预期完成的线索。
顺便说一句,这些类型的提问完成也可以通过openAI的新的指导模式来实现。
const prompt = `Answer the following question:
What is human life expectancy in the United States?
{}`
const response = await openai.createCompletion("text-davinci-001", {
prompt: prompt,
temperature: .7,
max_tokens: 100,
top_p: 1,
frequency_penalty: 0,
presence_penalty: 0,
stop: ["{}"],
});https://stackoverflow.com/questions/70893330
复制相似问题