cp .env.example .env
- Add your chatgpt API key
- Install dependencies
npm install
/pnpm i
- Run
node src/stream-demo.mjs
ornode src/chatgpt-demo.mjs
src/stream-demo.mjs
A quick demo showcasing ways to work with HTTP streams in node with two endpoints.
/streams
accepts a GET parametermsg
and returns that text as a stream with 500ms delay between the words./keepalive
keeps the connection open and returns values from the local filestreamdata
. You can play with it by pushing more lines to the file (echo "Lorem ipsum" >> streamdata
). The new lines will be streamed to the connected client(s).
Easiest to test using cURL, e.g. curl --get --data-urlencode "msg=Hai there, I heard you like streams" localhost:3000/streams
or curl localhost:3000/keepalive
but works in the browser too.
src/chatgpt-demo.mjs
Another demo showcasing a way to forward received tokens to a stream.
/joke
accept a GET parameter topic
and returns a joke considering the provided or default topic. The next step would be to forward either the whole text or passages to a text 2 speech service. The demo is using langchain (https://js.langchain.com/docs/get_started/quickstart).