jddev273 / streamed-chatgpt-api Goto Github PK
View Code? Open in Web Editor NEWA node module for streaming API responses from the ChatGPT APi.
License: MIT License
A node module for streaming API responses from the ChatGPT APi.
License: MIT License
Describe the solution you'd like
I think it would be nice if reader object can be accessed within the response callback.
I made change for myself since I wanted to cancel the stream in the middle.
shrft@60bbdc1
I use it like this.
fetchStreamedChat({
apiKey,
messageInput: 'Hello, how are you?',
}, (responseChunk, reader) => {
if(xxxx){
reader.cancel();
}
// get the actual content from the JSON
const content = JSON.parse(responseChunk).choices[0].delta.content;
if (content) {
process.stdout.write(content);
}
});
Additional context
thank you for your work. I use your library for my personal chatgpt command line tool.
I am getting the following error when I run the demo app. I have an implementation that cannot use import statements.
internal/modules/cjs/loader.js:1131
throw new ERR_REQUIRE_ESM(filename, parentPath, packageJsonPath);
^
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /Users/me/Downloads/simple-chatgpt-chat-streaming-demo-master/node_modules/node-fetch/src/index.js
require() of ES modules is not supported.
require() of /Users/me/Downloads/simple-chatgpt-chat-streaming-demo-master/node_modules/node-fetch/src/index.js from /Users/me/Downloads/simple-chatgpt-chat-streaming-demo-master/node_modules/streamed-chatgpt-api/index.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename /Users/me/Downloads/simple-chatgpt-chat-streaming-demo-master/node_modules/node-fetch/src/index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /Users/me/Downloads/simple-chatgpt-chat-streaming-demo-master/node_modules/node-fetch/package.json.
at new NodeError (internal/errors.js:322:7)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1131:13)
at Module.load (internal/modules/cjs/loader.js:979:32)
at Function.Module._load (internal/modules/cjs/loader.js:819:12)
at Module.require (internal/modules/cjs/loader.js:1003:19)
at require (internal/modules/cjs/helpers.js:107:18)
at Object.<anonymous> (/Users/me/Downloads/simple-chatgpt-chat-streaming-demo-master/node_modules/streamed-chatgpt-api/index.js:1:35)
at Module._compile (internal/modules/cjs/loader.js:1114:14)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1143:10)
at Module.load (internal/modules/cjs/loader.js:979:32) {
code: 'ERR_REQUIRE_ESM'
}
Process finished with exit code 1
I can not use import module. This needs to be fixed immediately
Hi,
I'm getting the following timeout error once in a while:
Error fetching chat: Error: Timeout
Is there anyway to catch this error and attempt again or someway to mitigate this issue?
Thank You!
Describe the bug
When fetch
uses node-fetch, and because of https://stackoverflow.com/a/57664622/21644773, the getReader function does not exist in response.body.
To Reproduce
Steps to reproduce the behavior:
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
Desktop (please complete the following information):
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.