#API nodejs
25 messages · Page 1 of 1 (latest)
You can get the entire text response in response.data.choices[0].text
that is what im doing rn actually
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
In your api, if you console.log completion.data.choices[0].text, did you het the whole text
nope just one line
i noticed its a readable stream is it sent in chunks or something maybe thats why? @burnt tusk
@burnt tusk
It's sends one line because your code is not complete
@sinful sparrow 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
is max tokens the number of tokens in the response?
and what is the actual max we can use
Yes
I think davinci is 2000 token
Thanks brotha