GithubHelp home page GithubHelp logo

clinejm / next-stream-gpt Goto Github PK

View Code? Open in Web Editor NEW
1.0 1.0 0.0 194 KB

simple example app using next edge functions to stream chatGPT responses

License: The Unlicense

JavaScript 1.81% TypeScript 98.19%

next-stream-gpt's Introduction

OpenAI Streaming Demo App

This repo demonstrates the use of OpenAI's streaming API with Next.js 13 and edge functions. The app directly fetches requests from OpenAI with streaming enabled, using the gpt-3.5-turbo chat completion model.

Features

  • Built with Next.js 13
  • Utilizes Vercel Edge functions for efficient API call processing
  • Direct fetch requests to OpenAI with streaming enabled
    • No overhead of the full openapi client package and its depedancies
  • Chat completion using gpt-3.5-turbo for good, fast and cheap replies.
  • Formats the responses using react-markdown

Demo of the streaming response to a simple prompt

Benefits

Edge functions only charge for processing time, while standard serverless functions charge for the total execution time. GPT API calls can take several seconds to complete the response, and in some cases exceed the free tier of Vercel. This project aims to reduce those costs.

Inspiration

The core edge function code is based on Building a GPT-3 app with Next.js and Vercel Edge Functions, but it's been updated to use chat completion API, and gpt-3.5-turbo.

Prerequisites

You will need to add a local .env file with the following keys:

OPENAI_API_KEY="..."

This example if deployed to vercel for testing would let anyone make requests with your API key so be careful.

This is a Next.js project bootstrapped with create-next-app.

Getting Started

First, run the development server:

npm install
npm run dev

Open http://localhost:3000/playground with your browser to see the result.

next-stream-gpt's People

Contributors

clinejm avatar

Stargazers

 avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.