openai-node icon indicating copy to clipboard operation
openai-node copied to clipboard

I see the project was updated a few hours ago, does this support "gpt-3.5-turbo"

Open phusting opened this issue 1 year ago • 11 comments

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

phusting avatar Mar 01 '23 21:03 phusting

You have to use the createChatCompletion() method instead of the createCompletion() method. Read the docs for more info.

adamk22 avatar Mar 01 '23 21:03 adamk22

You have to use the createChatCompletion() method instead of the createCompletion() method. Read the docs for more info.

I just Homer Simpsoned.....

I got it working. Very excited. Thank you.

phusting avatar Mar 01 '23 23:03 phusting

gpt-3.5-turbo , createChatCompletion How to use stream: true ?

NoirVoider avatar Mar 02 '23 01:03 NoirVoider

according to the docs it should be like this

const completion = await openai.createChatCompletion({
        model:"gpt-3.5-turbo",
        messages: [{role: "user", content:"Hello"}],
});
      

dytra avatar Mar 02 '23 02:03 dytra

@phusting you can try https://www.npmjs.com/package/gpt-node

cumt-robin avatar Mar 02 '23 03:03 cumt-robin

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: image Here is more from the official docs

shospodarets avatar Mar 02 '23 08:03 shospodarets

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: image

And this is my GPT 3.5 Turbo: image

Your guidance is highly appreciated 🙏

Regards, Abu

abuelgasimsaadeldin avatar Mar 02 '23 11:03 abuelgasimsaadeldin

Did you update your openai library version from npm?

robertbak avatar Mar 02 '23 11:03 robertbak

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: image

abuelgasimsaadeldin avatar Mar 02 '23 11:03 abuelgasimsaadeldin

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 code console.log(completion.data.choices[0].message.content);

For reference, I've printed out the entire "completions" and this is what I get: image

abuelgasimsaadeldin avatar Mar 02 '23 14:03 abuelgasimsaadeldin

Hi, how can we use stream? Thank you.

jgui1129 avatar Mar 06 '23 09:03 jgui1129

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

mbukeRepo avatar Mar 17 '23 15:03 mbukeRepo

@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/ 😉

shospodarets avatar Mar 20 '23 17:03 shospodarets