Giter Site home page Giter Site logo

langchain-app's Introduction

Deploying a chat bot

This project was used to learn how to deploy a language model, using mainly the following:

  • IaC (Terraform)
  • Docker
  • AWS Elastic Container Service
  • Langchain/Langserve
  • Ollama

The Web App

App is accessible at https://chat.felixcs.xyz (only when deployed, which is rarely to keep my aws bill to a minimum)

There are two modes corresponding to two different very simple langchain chains:

  • Chat - just pass user question straight to the model
  • Interview - wrap user question with a prompt template with info about me and encorage it to respond in a positive way
Chat mode Interview mode
alt text alt text

Architecture

The app is hosted on AWS, with two ECS services:

  • Backend service:
    • A container running the Ollama docker image. This holds the model for inference.
    • A container running a FastAPI app using langserve to easily create endpoints from langchain chains. The chains make calls to the ollama container to get model responses. On startup the app makes a pull request to the ollama container to download the model from Ollama model hub. This model is then persisted to EFS so this download does not need to happen when ECS tasks stop/start.
  • Front end - a container running nginx which serves the React app. This app makes calls to the FastAPI backend service.

https://miro.com/app/board/uXjVKaHvfVM=/

Some useful dev commands

Install pre-commit hooks

python -m venv venv
source venv/bin/activate
pip install pre-commit
pre-commit install

Run locally

docker-compose up

Build and push images to ECR

sh scripts/build-push.sh

Deploy all services

sh scripts/deploy-all.sh

Debugging

Access terminal in a task container

aws ecs execute-command \
--region eu-west-2 \
--cluster langserve-app-cluster \
--task <TASK ID> \
--container langserve-app-container \ # or ollama-container
--command "/bin/bash" \
--interactive

Infra

Infra not managed by terraform

  • The S3 bucket which holds the terraform state files
  • The Route 53 hosted zone

Todo

  • Use an API gateway to front the app
  • Manage ollama model loading with a lambda instead of fastAPI startup
  • Switch front end to use serverless
  • Should alb dns's be callable in browser over http?

Done

  • Switch Ollama container from fargate to provisioned ec2 with GPU enabled

langchain-app's People

Contributors

felixcs1 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.