Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

error while trying to get streamed api #9

Open
asifmai opened this issue Nov 8, 2023 · 5 comments
Open

error while trying to get streamed api #9

asifmai opened this issue Nov 8, 2023 · 5 comments

Comments

@asifmai
Copy link

asifmai commented Nov 8, 2023

Describe the bug
I am getting the following error:
Error reading stream: SyntaxError: Unexpected end of JSON input at JSON.parse (<anonymous>) at /Volumes/Work/Web Development Current/UAskMe/uaskme-backend/node_modules/streamed-chatgpt-api/index.js:14:38 at processStream (/Volumes/Work/Web Development Current/UAskMe/uaskme-backend/node_modules/streamed-chatgpt-api/index.js:128:17) at process.processTicksAndRejections (node:internal/process/task_queues:95:5) at async fetchStreamedChat (/Volumes/Work/Web Development Current/UAskMe/uaskme-backend/node_modules/streamed-chatgpt-api/index.js:183:5) at async fetchStreamedChatContent (/Volumes/Work/Web Development Current/UAskMe/uaskme-backend/node_modules/streamed-chatgpt-api/index.js:11:9)

To Reproduce
Steps to reproduce the behavior:
Here is how i send request to get streamed answer:

fetchStreamedChatContent( { apiKey: process.env.OPENAI_API_KEY, messageInput: messages, maxTokens, temperature, model, }, (content) => { successStream(content); completeResponse += content; }, () => { return resolve(completeResponse); }, (error) => { console.log("I'm sorry, there was an error processing your request."); console.log(error); return resolve(completeResponse); } );

Expected behavior
It is supposed to return answer in streamed format

Screenshots
image

Desktop (please complete the following information):

  • OS: Nodejs
  • Version 18
@GobindaSaha
Copy link

I'm having the same problem from yesterday night. Any solution please?

@GuiriDelNorte
Copy link

+1

@antoniobray
Copy link

Any luck finding a solution? This started happening around same time OpenAI reported possible DDoD attack. Could they have shut won something streamed-gpt was using?

@GuiriDelNorte
Copy link

Any luck finding a solution? This started happening around same time OpenAI reported possible DDoD attack. Could they have shut won something streamed-gpt was using?

With some research I noticed that the latest OpenAI API V4 update changed the way streamed answers come from the API endpoint. No longer it is needed to parse the response which makes this package obsolete. Now listening to stream is as easy as follows:

`import OpenAI from "openai";

const openai = new OpenAI();

const completion = await openai.chat.completions.create({
model: "gpt-3.5-turbo",
messages: [
{"role": "system", "content": "You are a helpful assistant."},
{"role": "user", "content": "Hello!"}
],
stream: true,
});

for await (const chunk of completion) {
console.log(chunk.choices[0].delta.content);
}
}

`

@antoniobray
Copy link

You rock. Thanks @GuiriDelNorte

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants