Giter VIP home page Giter VIP logo

streamed-chatgpt-api's People

Contributors

jddev273 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar

streamed-chatgpt-api's Issues

Feature Request: allow access to reader object in callback

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.

Error with require of node-fetch

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

Error fetching chat: Error: Timeout issue

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!

error while trying to get streamed api

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.