#API nodejs

25 messages · Page 1 of 1 (latest)

celest stag
#

Has anyone used the API and figured out how to get the entire text instead of just the first line in the response

burnt tusk
#

You can get the entire text response in response.data.choices[0].text

celest stag
#

i used the gpt-3 template given

#
  const configuration = new Configuration({
    
    apiKey: process.env.OPENAI_API_KEY,
  });
  
  const openai = new OpenAIApi(configuration);

  
    const completion = await openai.createCompletion({
      model: "text-davinci-002",
      prompt: generatePrompt(req.body.promptText),
      temperature: 0.6,
    });
 

 
   res.status(200).json({ result: completion.data.choices[0].text });
});```
#

this is the endpoint

#

i only ever get 1 phrase

#
    event.preventDefault();

    const response = await fetch("http://localhost:3001/api/generate", {
        method: "POST",
        headers: {
            "Content-Type": "application/json",
        },
        body: JSON.stringify({ promptText }),
    });
    const data = await response.json();

    setResponseText(data.result);
  

};```
this is my react side
burnt tusk
#

In your api, if you console.log completion.data.choices[0].text, did you het the whole text

celest stag
#

nope just one line

#

i noticed its a readable stream is it sent in chunks or something maybe thats why? @burnt tusk

#

@burnt tusk

sinful sparrow
celest stag
#

@sinful sparrow wdym what am I missing

sinful sparrow
# celest stag <@744099111925710850> wdym what am I missing
           model: "text-davinci-003", 
           max_tokens: 2000, 
           temperature: 0.6, 
           frequency_penalty: 0, 
           presence_penalty: 0.6,            prompt: generatePrompt(req.body.promptText), 
         }); ```
#

Test it now

celest stag
#

Oo

#

works now

celest stag
#

and what is the actual max we can use

sinful sparrow
celest stag
#

Thanks brotha