GithubHelp home page GithubHelp logo

serverless-openai-chatgpt-stream's Introduction

Serverless OpenAI ChatGPT Stream

API Gateway doesn't support streaming, so this is a workaround to stream data from OpenAI ChatGPT.

Lambda offers function urls which allows you to call Lambda function via http. Lambda function urls support streaming, so you can stream data from OpenAI ChatGPT.

Setup and deployment

You need to copy .env.example to .env and fill in the OPENAI_API_KEY environment variable.

  • Run npm install to install all the necessary dependencies.

Deploy on AWS, simply run:

$ npm run deploy

# or

$ serverless deploy

This will deploy your function and print your lambda function's url like below:

endpoint: https://XXXXXXXXXXXXXX.lambda-url.eu-west-2.on.aws/

Usage

You can test your endpoint like below

curl --location 'https://XXXXXXXXXXXXXX.lambda-url.eu-west-2.on.aws/' \
--header 'Content-Type: application/json' \
--data '{"chatLog": [{ "role": "user",  "content": "Write me a blog post about London." }]}'

serverless-openai-chatgpt-stream's People

Stargazers

 avatar Austen  avatar

Watchers

 avatar

Forkers

wooodhead

serverless-openai-chatgpt-stream's Issues

Unable to use the project

Hi there,

I've been trying to get this working, but keep running into the issue below.

Issue:

2023-07-30T08:49:26.179Z d6bf5a4e-c18e-4b84-b526-fa1416f1566c ERROR TypeError: The "streams" argument must be specified at new NodeError (node:internal/errors:399:5) at pipelineImpl (node:internal/streams/pipeline:193:11) at node:stream/promises:31:5 at new Promise (<anonymous>) at pipeline (node:stream/promises:20:10) at /var/src/handlers/chat.ts:73:9 at Generator.next (<anonymous>) at fulfilled (/var/task/src/handlers/chat.js:5:58) at processTicksAndRejections (node:internal/process/task_queues:95:5) { code: 'ERR_MISSING_ARGS' }

I run and populate:

cp .env.example .env

Followed by:

npm install
npm run deploy

I added the environment variables into Serverless too, and everything seems to go well and logs the event body correctly up until the issue above.

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.