ai-sdk-preview-python-streaming  by vercel-labs

Stream chat completions from Python to Next.js

Created 1 year ago
366 stars

Top 76.8% on SourcePulse

GitHubView on GitHub
Project Summary

This repository provides a template for streaming chat completions from a Python backend (FastAPI) to a Next.js frontend using the Data Stream Protocol. It's designed for developers looking to integrate real-time AI chat experiences into their web applications, offering a practical example of how to leverage Vercel's AI SDK.

How It Works

The project utilizes FastAPI to create a Python backend that streams chat completions. This streaming capability is achieved through the Data Stream Protocol, enabling efficient, real-time data transfer. The Next.js frontend, using the useChat hook from the AI SDK, consumes these streams to display responses as they are generated, creating a dynamic chat interface.

Quick Start & Requirements

  • Installation: Bootstrap a Next.js app using npx create-next-app --example https://github.com/vercel-labs/ai-sdk-preview-python-streaming <your-app-name>.
  • Prerequisites: Accounts and API keys from AI providers (e.g., OpenAI, Anthropic), Node.js, Python 3.x, virtualenv.
  • Setup: Set environment variables (API keys) in a .env file. Install Node dependencies with pnpm install, Python dependencies with pip install -r requirements.txt within a virtual environment.
  • Running: Launch the development server with pnpm dev.
  • Learn More: AI SDK Documentation, Next.js Documentation.

Highlighted Details

  • Demonstrates real-time streaming of AI chat completions.
  • Integrates FastAPI backend with Next.js frontend via Data Stream Protocol.
  • Provides a practical, runnable example for developers.

Maintenance & Community

This is a Vercel Labs project, indicating potential backing and development by Vercel. Further community or maintenance details are not provided in the README.

Licensing & Compatibility

The license is not specified in the provided README. Compatibility for commercial use or closed-source linking would depend on the actual license file.

Limitations & Caveats

The project is presented as a "preview" and a "template," suggesting it may be experimental or subject to change. Specific AI providers require separate accounts and API keys, and environment variable setup is necessary for local execution.

Health Check
Last Commit

2 months ago

Responsiveness

Inactive

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

Explore Similar Projects

Feedback? Help us improve.