1.1.2 • Published 2 years ago

fetch-stream-observable v1.1.2

Weekly downloads
-
License
ISC
Repository
-
Last release
2 years ago

fetch-stream-observable

Coverage Status npm version npm bundle size

Fetch API which returns an observable.

  • OpenAI stream parsing supported out of the box.
  • Gracefully degrades to calling subscription only once for non streaming response (json and text for eg).
  • Typescript
  • Lightweight (3.7kb min+gzip)

Installation

$ npm i fetch-stream-observable

Usage

import { fetchObservable } from 'fetch-stream-observable';

fetchObservable("https://api.openai.com/v1/chat/completions", {
    headers: {
        "Content-Type": "application/json",
        Authorization: `Bearer <OPEN_AI_API_KEY>`,
    },
    method: "POST",
    body: JSON.stringify({
        /*
            OpenAI body payload.
        */
        // Tells openAI to send streaming response.
        stream: true, 
    }),
    // This disables automatic parsing of open ai response.
    doNotParseOpenAIStream: false, 
    // This will disable returning an additive complete response string.
    doNotConcatTextStream: false, 
})
    .subscribe((data: string) => {
        // Logs the complete string with each event, 
        // helpful with React `setState`.
        console.log(data); 
    });
1.1.2

2 years ago

1.1.1

2 years ago

1.1.0

2 years ago

1.0.6

2 years ago

1.0.5

2 years ago

1.0.4

2 years ago

1.0.3

2 years ago

1.0.2

2 years ago

1.0.1

2 years ago

1.0.0

2 years ago