Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Poetry #67

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
.PHONY: start
start:
uvicorn main:app --reload --port 9000
poetry run uvicorn main:app --reload --port 9000

.PHONY: format
format:
black .
isort .
poetry run black .
poetry run isort .
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ Built with [LangChain](https://github.com/hwchase17/langchain/) and [FastAPI](ht
The app leverages LangChain's streaming support and async API to update the page in real time for multiple users.

## ✅ Running locally
1. Install dependencies: `pip install -r requirements.txt`
1. Install dependencies: `poetry install`
1. Run `ingest.sh` to ingest LangChain docs data into the 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. Export your OpenAPI key, eg `export OPENAI_API_KEY=sk-...`
1. Run the app: `make start`
1. To enable tracing, make sure `langchain-server` is running locally and pass `tracing=True` to `get_chain` in `main.py`. You can find more documentation [here](https://langchain.readthedocs.io/en/latest/tracing.html).
1. Open [localhost:9000](http://localhost:9000) in your browser.
Expand Down
2 changes: 1 addition & 1 deletion ingest.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@
# Error if any command fails
set -e
wget -r -A.html https://langchain.readthedocs.io/en/latest/
python3 ingest.py
poetry run python ingest.py
2,441 changes: 2,441 additions & 0 deletions poetry.lock

Large diffs are not rendered by default.

30 changes: 30 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
[tool.poetry]
name = "chat-langchain"
version = "0.1.0"
description = ""
authors = ["Your Name <[email protected]>"]
readme = "README.md"
packages = [{include = "chat_langchain"}]

[tool.poetry.dependencies]
python = "^3.11"
openai = "^0.27.5"
fastapi = "^0.95.1"
black = "^23.3.0"
isort = "^5.12.0"
websockets = "^11.0.2"
pydantic = "^1.10.7"
langchain = "^0.0.152"
uvicorn = "^0.22.0"
jinja2 = "^3.1.2"
faiss-cpu = "^1.7.4"
bs4 = "^0.0.1"
unstructured = "^0.6.2"
libmagic = "^1.0"
tiktoken = "^0.3.3"



[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
13 changes: 7 additions & 6 deletions query_data.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"""Create a ChatVectorDBChain for question/answering."""
from langchain.callbacks.base import AsyncCallbackManager
from langchain.callbacks.tracers import LangChainTracer
from langchain.chains import ChatVectorDBChain
from langchain.chains import ConversationalRetrievalChain
from langchain.chains.chat_vector_db.prompts import (CONDENSE_QUESTION_PROMPT,
QA_PROMPT)
from langchain.chains.llm import LLMChain
Expand All @@ -12,9 +12,9 @@

def get_chain(
vectorstore: VectorStore, question_handler, stream_handler, tracing: bool = False
) -> ChatVectorDBChain:
"""Create a ChatVectorDBChain for question/answering."""
# Construct a ChatVectorDBChain with a streaming llm for combine docs
) -> ConversationalRetrievalChain:
"""Create a ConversationalRetrievalChain for question/answering."""
# Construct a ConversationalRetrievalChain with a streaming llm for combine docs
# and a separate, non-streaming llm for question generation
manager = AsyncCallbackManager([])
question_manager = AsyncCallbackManager([question_handler])
Expand Down Expand Up @@ -45,10 +45,11 @@ def get_chain(
streaming_llm, chain_type="stuff", prompt=QA_PROMPT, callback_manager=manager
)

qa = ChatVectorDBChain(
vectorstore=vectorstore,
qa = ConversationalRetrievalChain(
retriever=vectorstore.as_retriever(),
combine_docs_chain=doc_chain,
question_generator=question_generator,
callback_manager=manager,
)

return qa
13 changes: 0 additions & 13 deletions requirements.txt

This file was deleted.