Skip to content

Commit

Permalink
update readme
Browse files Browse the repository at this point in the history
  • Loading branch information
bracesproul committed Feb 13, 2024
1 parent 5ad8a97 commit 29d9ef4
Show file tree
Hide file tree
Showing 4 changed files with 42 additions and 49 deletions.
54 changes: 19 additions & 35 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,40 +1,25 @@
# 🦜️🔗 Chat LangChain

This repo is an implementation of a locally hosted chatbot specifically focused on question answering over the [LangChain documentation](https://langchain.readthedocs.io/en/latest/).
Built with [LangChain](https://github.com/hwchase17/langchain/), [FastAPI](https://fastapi.tiangolo.com/), and [Next.js](https://nextjs.org).
Built with [LangChain](https://github.com/langchain-ai/langchainjs/), and [Next.js](https://nextjs.org).

Deployed version: [chat.langchain.com](https://chat.langchain.com)
Deployed version: [chatjs.langchain.com](https://chatjs.langchain.com)

The app leverages LangChain's streaming support and async API to update the page in real time for multiple users.
> Looking for the Python? Click [here](https://chat.langchain.com)
The app leverages LangChain's streaming API to update the page in real time for multiple users.

## ✅ Running locally
1. Install backend dependencies: `poetry install`.
1. 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](https://langchain.readthedocs.io/en/latest/modules/document_loaders.html) to load your own data into the vectorstore.
1. Start the Python backend with `poetry run make start`.
1. Install frontend dependencies by running `cd chat-langchain`, then `yarn`.
1. Run the frontend with `yarn dev` for frontend.
1. Open [localhost:3000](http://localhost:3000) in your browser.

## ☕ Running locally (JS backend)
1. Follow the first three steps above to ingest LangChain docs data into the vectorstore.
1. Install frontend dependencies by running `cd chat-langchain`, then `yarn`.
1. 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"`.
1. Run the app with `yarn dev`.
1. Open [localhost:3000](http://localhost:3000) in your browser.
1. Install dependencies via: `yarn.install`.
2. Set the required environment variables listed inside [`backend/.env.example`](backend/.env.example) for the backend, and [`frontend/.env.example`](frontend/.env.example) for the frontend.

### Ingest
1. Build the backend via `yarn build --filter=backend` (from root).
2. Run the ingestion script by navigating into `./backend` and running `yarn ingest`.

### Frontend
1. Navigate into `./frontend` and run `yarn dev` to start the frontend.
2. Open [localhost:3000](http://localhost:3000) in your browser.

## 📚 Technical description

Expand All @@ -43,9 +28,9 @@ 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](https://python.langchain.com/docs/integrations/document_loaders/recursive_url_loader) and [SitemapLoader](https://python.langchain.com/docs/integrations/document_loaders/sitemap)
3. Split documents with LangChain's [RecursiveCharacterTextSplitter](https://api.python.langchain.com/en/latest/text_splitter/langchain.text_splitter.RecursiveCharacterTextSplitter.html)
4. Create a vectorstore of embeddings, using LangChain's [Weaviate vectorstore wrapper](https://python.langchain.com/docs/integrations/vectorstores/weaviate) (with OpenAI's embeddings).
2. Load html with LangChain's [RecursiveUrlLoader](https://api.js.langchain.com/classes/langchain_document_loaders_web_recursive_url.RecursiveUrlLoader.html) and [SitemapLoader](https://js.langchain.com/docs/integrations/document_loaders/web_loaders/sitemap)
3. Split documents with LangChain's [RecursiveCharacterTextSplitter](https://js.langchain.com/docs/modules/data_connection/document_transformers/recursive_text_splitter)
4. Create a vectorstore of embeddings, using LangChain's [Weaviate vectorstore wrapper](https://js.langchain.com/docs/integrations/vectorstores/weaviate) (with OpenAI's embeddings).

Question-Answering has the following steps:

Expand All @@ -56,5 +41,4 @@ Question-Answering has the following steps:

## 🚀 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!).
Deploy the frontend Next.js app as a serverless Edge function on Vercel.
10 changes: 9 additions & 1 deletion backend/.env.example
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
# ------------------LangSmith tracing------------------
LANGCHAIN_TRACING_V2=true
LANGCHAIN_ENDPOINT="https://api.smith.langchain.com"
LANGCHAIN_API_KEY=
LANGCHAIN_PROJECT=
# -----------------------------------------------------

WEAVIATE_API_KEY=
WEAVIATE_HOST=
WEAVIATE_URL=
WEAVIATE_INDEX_NAME=
FORCE_UPDATE=true
RECORD_MANAGER_DB_URL=
OPENAI_API_KEY=
22 changes: 12 additions & 10 deletions frontend/.env.example
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
## For JS backend:
# ------------------LangSmith tracing------------------
LANGCHAIN_TRACING_V2=true
LANGCHAIN_ENDPOINT="https://api.smith.langchain.com"
LANGCHAIN_API_KEY=
LANGCHAIN_PROJECT=
# -----------------------------------------------------

# LANGCHAIN_TRACING_V2=true
# LANGCHAIN_ENDPOINT="https://api.smith.langchain.com"
# LANGCHAIN_API_KEY="YOUR_LANGSMITH_KEY"
# LANGCHAIN_PROJECT="YOUR_PROJECT_NAME"
WEAVIATE_API_KEY=
WEAVIATE_URL=
WEAVIATE_INDEX_NAME=

# NEXT_PUBLIC_API_BASE_URL="http://localhost:3000/api"
# OPENAI_API_KEY="YOUR_OPENAI_API_KEY"
# WEAVIATE_HOST="YOUR_WEAVIATE_HOST"
# WEAVIATE_API_KEY="YOUR_WEAVIATE_API_KEY"
# WEAVIATE_INDEX_NAME="YOUR_WEAVIATE_INDEX_NAME"
FIREWORKS_API_KEY=

OPENAI_API_KEY=
5 changes: 2 additions & 3 deletions frontend/app/utils/constants.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export const apiBaseUrl =
process.env.NEXT_PUBLIC_API_BASE_URL ??
`https://${process.env.VERCEL_URL}/api`;
const apiBasePath = process.env.VERCEL_URL ? `https://${process.env.VERCEL_URL}` : `http://localhost:3000`
export const apiBaseUrl = `${apiBasePath}/api`;

0 comments on commit 29d9ef4

Please sign in to comment.