openai-streams  by SpellcraftAI

Node.js/TS library for OpenAI API stream handling

created 2 years ago
291 stars

Top 91.6% on sourcepulse

GitHubView on GitHub
1 Expert Loves This Project
Project Summary

This library provides tools for working with OpenAI API responses as streams in Node.js and TypeScript, prioritizing efficient display of completions as they arrive. It targets developers building applications that require real-time text generation, such as chatbots or content creation tools, enabling a more responsive user experience.

How It Works

The core of the library is a single OpenAI function that accepts an endpoint, parameters, and options. It abstracts the complexity of handling OpenAI API responses, returning them as ReadableStream by default for browser and modern Node.js environments, with a specific Node.js stream implementation available. This approach simplifies integration and allows for immediate display of generated content without waiting for the entire response.

Quick Start & Requirements

  • Install: yarn add openai-streams or npm i --save openai-streams
  • Requirements: OPENAI_API_KEY environment variable or passed via options.
  • Usage: await OpenAI(ENDPOINT, PARAMS, OPTIONS)
  • Docs: OpenAI Streams GitHub

Highlighted Details

  • Supports OpenAI API endpoints like 'completions' and 'chat'.
  • Parameter types are inferred based on the selected endpoint.
  • Offers 'tokens' (default) and 'raw' modes for stream consumption.
  • Compatible with Next.js Edge Runtime and Node.js environments.

Maintenance & Community

  • Active development indicated by recent updates and feature additions (e.g., ChatGPT API support).
  • Links to GitHub for code and potential community interaction.

Licensing & Compatibility

  • The README does not explicitly state a license.

Limitations & Caveats

The library currently lacks support for the Whisper API, though it is listed as "coming soon." The README does not specify compatibility with older Node.js versions or provide details on potential rate limiting or error handling beyond API key validation.

Health Check
Last commit

2 years ago

Responsiveness

1 day

Pull Requests (30d)
0
Issues (30d)
0
Star History
2 stars in the last 90 days

Explore Similar Projects

Feedback? Help us improve.