react-native-vercel-ai  by bidah

React Native package for Vercel AI integration in universal apps

created 1 year ago
278 stars

Top 94.3% on sourcepulse

GitHubView on GitHub
Project Summary

This package enables the use of Vercel AI's useChat and useCompletion hooks within React Native and Expo universal applications. It addresses the limitation of React Native's fetch API not supporting streaming, providing a workaround for mobile clients while maintaining full streaming functionality on the web.

How It Works

The library bridges Vercel AI's functionality to React Native by abstracting the streaming behavior. For web environments, it seamlessly integrates with the existing ai/react package. On React Native mobile platforms, it bypasses the streaming aspect of the API calls, returning the complete response directly. This is achieved by conditionally disabling streaming in the backend API based on the user agent.

Quick Start & Requirements

  • Install via npm: npm install react-native-vercel-ai
  • Requires Metro configuration: Add unstable_enablePackageExports = true to metro.config.js.
  • Backend API endpoint is required to handle requests and conditionally stream responses.
  • Example API endpoint provided using Next.js.

Highlighted Details

  • Enables Vercel AI hooks (useChat, useCompletion) in React Native.
  • Supports Expo universal apps for both mobile and web.
  • Handles non-streaming responses for React Native mobile clients.
  • Falls back to standard ai/react behavior on the web.

Maintenance & Community

  • Created by Rodrigo Figueroa (@bidah).
  • No explicit community links (Discord, Slack) or roadmap mentioned in the README.

Licensing & Compatibility

  • MIT License.
  • Compatible with commercial use and closed-source applications.

Limitations & Caveats

The primary limitation is the lack of streaming support on React Native mobile, which is a core feature of the Vercel AI package. The solution relies on a backend API to detect and serve non-streamed responses to mobile clients.

Health Check
Last commit

1 year ago

Responsiveness

1 week

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

Explore Similar Projects

Feedback? Help us improve.