LegalChat
LegalChat copied to clipboard
Building a chatbot for legal banking documents using Langchain and OpenAI API
🔗 Chat with Legal Documents
This repo is an implementation of a locally hosted chatbot specifically focused on question answering over the European Banking Authority. Built with LangChain and FastAPI. The app leverages LangChain's streaming support and async API to update the page in real time for multiple users.
UI/UX
- The app is built with basic HTML template with JinJa2 templating engine. The app is served by FastAPI.
Running locally
- Install dependencies:
pip install -r requirements.txtandexport OPENAI_API_KEY=YOUR_OPENAI_KEYfor the app to work. - Add your documents in excel files with consistent format in folder
eba_documents/ - Run
python3 ingest_eba.pyto ingest EBA docs data into the vectorstore (only needs to be done once), if you want to update, just add new docs and run it again. - Run the app:
make start- To enable tracing, make sure
langchain-serveris running locally and passtracing=Truetoget_chaininmain.py. You can find more documentation here.
- To enable tracing, make sure
- Open localhost:9000 in your browser.
Details on Implementation
- The app is built with basic HTML template with JinJa2 templating engine. The app is served by FastAPI.
- The app uses LangChain to connect vectorstore with OpenAI API
text-davinci-003to generate text. - The vectorstore is indexed using
embedding-ada-002with very cheap price per 1k tokens and saved in vectorstore.pkl pickle file using FAISS. - The prompt is a Few-shot examples containing 2 question-answer pairs and 4 retrieved documents.
- Input Aggregator currently is quite simple. Just concatenate additional fields with the prompt (followed by the name of each meta-data field).