【问题标题】:OPENAI API Completion not returning textOPENAI API 完成不返回文本
【发布时间】:2022-06-14 12:59:45
【问题描述】:

我正在使用 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' } ]
}

在操场上,这段代码运行良好。

我怎样才能得到正确的回应?

【问题讨论】:

  • 哦.. 我刚刚修复了 将提示更改为 -> 提示:\n\nQ: ${question}\nA:,

标签: node.js openai


【解决方案1】:

应该是这样的:

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;
}

在这里,首先,从停止数组中删除 \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: ["{}"],
});

【讨论】:

    猜你喜欢
    • 2022-10-07
    • 2022-11-10
    • 2023-01-17
    • 2020-04-24
    • 2018-04-23
    • 1970-01-01
    • 1970-01-01
    • 2018-05-26
    • 2016-11-03
    相关资源
    最近更新 更多