Search code examples
node.jsopenai-api

Open ai text-davinci-003 always returning one suggestion?


I am trying to get array of suggestions (multiple suggestions) for some prompt from nodejs. Here is what I have so far:

const completion = await openai.createCompletion({
            model: complitionModel,
            prompt: `${finalCommand}: ${text}`,
            max_tokens: 256,
            temperature: 0,
            top_p: 1,
            frequency_penalty: 0,
            presence_penalty: 0,
            user: user.id
        });

But it always return one suggestion (array with single element), no metter what prompt or text i send... Any idea why?


Solution

  • the documentation says a parameter n which is 1 by default

    How many completions to generate for each prompt.

    Note: Because this parameter generates many completions, it can quickly consume your token quota. Use carefully and ensure that you have reasonable settings for max_tokens and stop.

    const completion = await openai.createCompletion({
                model: complitionModel,
                prompt: `${finalCommand}: ${text}`,
                max_tokens: 256,
                temperature: 0,
                top_p: 1,
                frequency_penalty: 0,
                presence_penalty: 0,
                user: user.id,
                n: noOfCompletions //1 by default
            });
    

    Note
    you may get the same results even with a higher n with a temperature of 0. The docs say

    What sampling temperature to use, between 0 and 2. Higher values like 0.8 will make the output more random, while lower values like 0.2 will make it more focused and deterministic.

    Also this forum post addresses this issue