A chat application that leverages Langchain, Langgraph, Langsmith and Neo4j knowledge graph.
- π€ Doctor assistant AI chat for patients
- π Chat summarization to reduce long context window cost and time
- πΈοΈ Knowledge Graph utilization for RAG techniques using Neo4j
- π§ Function calling for external systems and APIs (appointment scheduling, medication changes)
- π Comprehensive chat summarization for patients
- π©Ί Medical history insights based on patient preferences, diet, and diagnostics
- π LLM agnostic design
π Patient_chat
π home
π constants
π langchains
π function_tools
π models
π notebooks
π static
π templates
Follow these instructions to set up the project locally:
Tested on Python 3.12.6
and above. We can't guarantee compatibility with earlier versions.
- Create a virtual environment named
venv
:python -m venv venv
- Activate it:
source venv/bin/activate
pip install -r requirements.txt
Create a .env
file at the project root. See env.example
for reference. Required variables:
ANTHROPIC_API_KEY=your-api-key
GOOGLE_API_KEY=your-api-key
OPENAI_API_KEY=your-api-key
LANGCHAIN_API_KEY=your-api-key
LANGCHAIN_TRACING_V2=true
LANGCHAIN_ENDPOINT=your-langchain-endpoint
LANGCHAIN_PROJECT=your-langchain-project-name
NEO4J_URI=your-neo4j-url
NEO4J_USERNAME=your-neo4j-user-name
NEO4J_PASSWORD=your-neo4j-user-password
We use PostgreSQL for storing patient information and chat history. Two main tables:
patient
: Patient bio and medical informationchat_history
: Chat history, thread_id, and summarized chat history
Setup steps:
- Install PostgreSQL from postgresql.org
- Navigate to the
db_scripts
folder:cd db_scripts
- Make scripts executable:
chmod +x create_db_tables.sh insert_data.sh
- Run scripts:
./create_db_tables.sh
./insert_data.sh
- Configure database connection in
settings.py
:DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql_psycopg2', 'NAME': 'patient_db', 'USER': '', 'PASSWORD': '', 'HOST': '127.0.0.1', 'PORT': '5432' } }
- Install Neo4j or use the server version
- Set environment variables in
.env
:NEO4J_URI=your-neo4j-url NEO4J_USERNAME=your-neo4j-user-name NEO4J_PASSWORD=your-neo4j-user-password
- Note: We start with an empty knowledge graph and load data gradually with each user chat.
If you are still in db_scripts
folder, switch back to root project directory.
Start the server:
python manage.py runserver
The server should start running at http://127.0.0.1:8000/
Run tests:
python manage.py test
Below we provide overall project architectural details.
To reduce the cost and time from long chat input-output context, we are using the summarization technique.
We filter and summarize chat history in the backend, storing summaries in the database using a unique thread_id
in Langsmith.
Support for OpenAI, Anthropic, and Google Gemini is included. For other langchain AI libraries:
- Add the model's langchain dependency in
requirements.txt
- Add the API Key environment variable in
settings.py
- (Optional) Add an entry in
constants.py
- Add the actual API Key to the
.env
file
- Change appointment date
- Medication change request
- π Streaming chat
- β‘ Parallel API calls to reduce interaction time
- π Display previous chat threads in the UI (already in the database)