OpenAI not returning a result?

Viewed 435

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 (https://www.npmjs.com/package/openai-api). 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.

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?

1 Answers

don't use openai-api anymore, it's not supported officially. use npm i openai instead.

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