openai-node
openai-node copied to clipboard
I see the project was updated a few hours ago, does this support "gpt-3.5-turbo"
Describe the feature or improvement you're requesting
I tried the new "gpt-3.5-turbo" with my previous install and I get an 404 error on return. Has this been updated for the new "gpt-3.5-turbo" model?
Additional context
No response
You have to use the createChatCompletion()
method instead of the createCompletion()
method. Read the docs for more info.
You have to use the
createChatCompletion()
method instead of thecreateCompletion()
method. Read the docs for more info.
I just Homer Simpsoned.....
I got it working. Very excited. Thank you.
gpt-3.5-turbo , createChatCompletion How to use stream: true ?
according to the docs it should be like this
const completion = await openai.createChatCompletion({
model:"gpt-3.5-turbo",
messages: [{role: "user", content:"Hello"}],
});
@phusting you can try https://www.npmjs.com/package/gpt-node
Here is a simple overview of Node.js openai
usage changes between text-davinci-003
and gpt-3.5-turbo
models :
New code:
const completion = await openai.createChatCompletion({
model: "gpt-3.5-turbo",
messages: [{
role: "user",
content: prompt,
}],
});
console.log(completion.data.choices[0].message.content);
Git diff:
Here is more from the official docs
hi @shospodarets @dytra @adamk22
I have followed the instructions but I am getting openai.createChatCompletion is not a function
may I know why is that?
Here is my working GPT 3 Davinci:
And this is my GPT 3.5 Turbo:
Your guidance is highly appreciated 🙏
Regards, Abu
Did you update your openai
library version from npm?
Hi @robertbak,
Thanks allot for that! I've updated from version 3.1.0 to 3.2.1 and I'm able to get a response now.
I am getting the following error now however: TypeError: Cannot read properties of undefined (reading '0')
from the code console.log(completion.data.choices[0].message.content);
For reference, I've printed out the entire "completions" and this is what I get:
Issue has been resolved, just got rid of stream: true
.
Hi @robertbak,
Thanks allot for that! I've updated from version 3.1.0 to 3.2.1 and I'm able to get a response now.
I am getting the following error now however:
TypeError: Cannot read properties of undefined (reading '0')
from the codeconsole.log(completion.data.choices[0].message.content);
For reference, I've printed out the entire "completions" and this is what I get:
Hi, how can we use stream? Thank you.
Hello @jgui1129, Thank you for your great question, I did some research and I found out that we can do this to achieve streaming:
interface Stream extends CreateCompletionResponse {
on: (event: string, callback: (data: Buffer) => void) => void;
}
const response = await openai.createChatCompletion(
{
model,
prompt,
stream: true,
},
{ responseType: 'stream' }
);
const stream = response.data as Stream;
stream.on('data', (data: Buffer) => {
console.log(data.toString());
});
You can also achieve this using this package openai-streams
@jgui1129 @phusting Here you can find the working and supported example of latest ChatGPT API used with the streams: https://github.com/Nutlope/twitterbio/blob/main/utils/OpenAIStream.ts https://github.com/Nutlope/twitterbio/blob/main/pages/api/generate.ts
++ live demo https://www.twitterbio.com/ 😉