GithubHelp home page GithubHelp logo

jphme / fastapi-async-langchain Goto Github PK

View Code? Open in Web Editor NEW

This project forked from ajndkr/lanarky

1.0 0.0 0.0 21.02 MB

๐Ÿšข Ship production-ready LangChain projects with FastAPI

License: MIT License

Python 100.00%

fastapi-async-langchain's Introduction

fastapi-async-langchain

License: MIT PyPI version

Ship production-ready LangChain projects with FastAPI.

๐Ÿš€ Features

  • supports token streaming over HTTP and Websocket
  • supports multiple langchain Chain types
  • simple gradio chatbot UI for fast prototyping
  • follows FastAPI responses naming convention

โ“ Why?

There are great low-code/no-code solutions in the open source to deploy your Langchain projects. However, most of them are opinionated in terms of cloud or deployment code. This project aims to provide FastAPI users with a cloud-agnostic and deployment-agnostic solution which can be easily integrated into existing backend infrastructures.

๐Ÿ’พ Installation

The library is available on PyPI and can be installed via pip.

pip install fastapi-async-langchain

๐Ÿ”ฅ Deploy in under 20 lines of code

from dotenv import load_dotenv
from fastapi import FastAPI
from langchain import ConversationChain
from langchain.chat_models import ChatOpenAI
from pydantic import BaseModel
from fastapi_async_langchain.responses import StreamingResponse

load_dotenv()
app = FastAPI()

class Request(BaseModel):
    query: str

@app.post("/chat")
async def chat(request: Request) -> StreamingResponse:
    chain = ConversationChain(llm=ChatOpenAI(temperature=0, streaming=True), verbose=True)
    return StreamingResponse.from_chain(chain, request.query, media_type="text/event-stream")

See examples/ for list of available demo examples.

Create a .env file using .env.sample and add your OpenAI API key to it before running the examples.

demo

๐Ÿค Contributing

Code check Publish

Contributions are more than welcome! If you have an idea for a new feature or want to help improve fastapi-async-langchain, please create an issue or submit a pull request on GitHub.

See CONTRIBUTING.md for more information.

โš–๏ธ License

The library is released under the MIT License.

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.