Git Product home page Git Product logo

chat-langchain's Introduction

๐Ÿฆœ๏ธ๐Ÿ”— Chat LangChain

This repo is an implementation of a locally hosted chatbot specifically focused on question answering over the LangChain documentation. Built with LangChain, FastAPI, and Next.js.

Deployed version: chat.langchain.com

The app leverages LangChain's streaming support and async API to update the page in real time for multiple users.

โœ… Running locally

  1. Install backend dependencies: poetry install.
  2. Make sure to enter your environment variables to configure the application:
export OPENAI_API_KEY=
export WEAVIATE_URL=
export WEAVIATE_API_KEY=
export RECORD_MANAGER_DB_URL=

# for tracing
export LANGCHAIN_TRACING_V2=true
export LANGCHAIN_ENDPOINT="https://api.smith.langchain.com"
export LANGCHAIN_API_KEY=
export LANGCHAIN_PROJECT=
  1. Run python ingest.py to ingest LangChain docs data into the Weaviate vectorstore (only needs to be done once).
    1. You can use other Document Loaders to load your own data into the vectorstore.
  2. Start the Python backend with poetry run make start.
  3. Install frontend dependencies by running cd chat-langchain, then yarn.
  4. Run the frontend with yarn dev for frontend.
  5. Open localhost:3000 in your browser.

โ˜• Running locally (JS backend)

  1. Follow the first three steps above to ingest LangChain docs data into the vectorstore.
  2. Install frontend dependencies by running cd chat-langchain, then yarn.
  3. Populate a chat-langchain/.env.local file with your own versions of keys from the chat-langchain/.env.example file, and set NEXT_PUBLIC_API_BASE_URL to "http://localhost:3000/api".
  4. Run the app with yarn dev.
  5. Open localhost:3000 in your browser.

๐Ÿ“š Technical description

There are two components: ingestion and question-answering.

Ingestion has the following steps:

  1. Pull html from documentation site as well as the Github Codebase
  2. Load html with LangChain's RecursiveURLLoader and SitemapLoader
  3. Split documents with LangChain's RecursiveCharacterTextSplitter
  4. Create a vectorstore of embeddings, using LangChain's Weaviate vectorstore wrapper (with OpenAI's embeddings).

Question-Answering has the following steps:

  1. Given the chat history and new user input, determine what a standalone question would be using GPT-3.5.
  2. Given that standalone question, look up relevant documents from the vectorstore.
  3. Pass the standalone question and relevant documents to the model to generate and stream the final answer.
  4. Generate a trace URL for the current chat session, as well as the endpoint to collect feedback.

๐Ÿš€ Deployment

Deploy the frontend Next.js app as a serverless Edge function on Vercel by clicking here. You'll need to populate the NEXT_PUBLIC_API_BASE_URL environment variable with the base URL you've deployed the backend under (no trailing slash!).

chat-langchain's People

Contributors

mcantillon21 avatar baskaryan avatar jacoblee93 avatar hinthornw avatar langchain-infra avatar hwchase17 avatar agola11 avatar raceronskis avatar efriis avatar eyurtsev avatar eltociear avatar jvelezmagic avatar nfcampos avatar samnoyes avatar sangyh avatar sid77x 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.