Awesome
Chatbot with Langchain, LangSmith.
Requirement
- Python version >= 3.9. Because langchainhub package require it
Description
- This is a chatbot implementation with Langchain framework.
- Base LLM: Vertex AI or OpenAI API
- Memory: MongoDB
- UI:
- Gradio
- Langchain UI: Chat Langchain
- Use it to leverages LangChain's streaming support.
- Prompt versioning and tracing: LangSmith
- User can custom bot's personality by setting bot information like gender, age, ...
- Demo UI:
PII for chatbot
- Data anonymization with Microsoft Presidio
- To protect personally identifiable information (PII), we add
PresidioAnonymizer
to my bot to replace PIIs before pass to LLM api. View code in Anonymizer - Steps when using it:
-
User message after anonymize:
-
Anonymized prompt before input to LLM:
-
De-anonymized response to user after LLM call:
-
How to use
- You need Google Cloud credentials to call Vertex API or OPENAI API KEY to call OpenAI API
- You need create MongoDB database and collection to use as Langchain memory
Setup tracing with Langsmith
- Langsmith docs: LangSmith
- Configure environment to connect to LangSmith.
export LANGCHAIN_TRACING_V2=true export LANGCHAIN_ENDPOINT="https://api.smith.langchain.com" export LANGCHAIN_API_KEY="<your-api-key>" export LANGCHAIN_PROJECT="chatbot-with-langchain"
Running
- Download the models for the languages to use in anonymizer. PII support.
python -m spacy download en_core_web_md
- RUN backend
- Clone repo:
git clone https://github.com/btrcm00/chatbot-with-langchain.git
- Add google-cloud-platform credential file to
secure/vertexai.json
cd chatbot
- Install required packages:
pip install -r requirements.txt
- Create MongoDB database and config environment variables to connect Mongo.
- Run:
python app.py
- Clone repo:
- RUN frontend
cd chatbot_frontend
- Install packages:
npm i
- Start frontend:
npm start dev