0

When using createCompletion I get a response but it doesn't have the actual text response. In textPayload it has "text: 'package com.example.demo.controller;',"

Below is my code

const openai = new OpenAIApi(configuration);

  async function step1() {
  currentResponse = await openai.createCompletion({
    model: "text-davinci-003",
    prompt: currentMessage,
    temperature: 0,
    max_tokens: 2292,
    top_p: 1,
    frequency_penalty: 0,
    presence_penalty: 0,
    stop: ["\n\n"],
  });

} //end step1

return step1().then(function(response) {

    var currentResponseNew = currentResponse.data
    //this is where I get the text payload value
    console.log(currentResponseNew)
    res.send("done")


})
Steven
  • 149
  • 1
  • 10

1 Answers1

0

Based on your code above, when accessing the response data you need to access the choices parameter from the currentResponse object.

Here is how you should fix your code:

const openai = new OpenAIApi(configuration);

  async function step1() {
  currentResponse = await openai.createCompletion({
    model: "text-davinci-003",
    prompt: currentMessage,
    temperature: 0,
    max_tokens: 2292,
    top_p: 1,
    frequency_penalty: 0,
    presence_penalty: 0,
    stop: ["\n\n"],
  });

} //end step1

return step1().then(function(response) {

    //this is where I get the text payload value
    console.log(currentResponse.data.choices[0].text)
    res.send("done")
})

When I run this code I get a valid response from GPT.

Kane Hooper
  • 1,531
  • 1
  • 9
  • 21