jddev273 / streamed-chatgpt-api

A node module for streaming API responses from the ChatGPT APi.
MIT License
30 stars 7 forks source link

error while trying to get streamed api #9

Open asifmai opened 9 months ago

asifmai commented 9 months ago

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

GobindaSaha commented 9 months ago

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

GuiriDelNorte commented 9 months ago

+1

antoniobray commented 9 months ago

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 commented 9 months ago

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 commented 9 months ago

You rock. Thanks @GuiriDelNorte