This repository contains an AI-powered psychologist chatbot that uses advanced language models and retrieval-augmented generation (RAG) to provide empathetic and informative responses to users seeking psychological support. The chatbot utilizes the Meta's Llama 3.1 8B model for language processing and the Nomic Embed Text model for embeddings, both through Ollama.
.
├── data/
│ └── knowledge base files (pdf, doc, txt, md, etc)
├── notebooks/
│ └── db-populate.ipynb
├── src/
│ ├── chatbot.py
│ └── rag-chatbot.py
├── requirements.txt
└── README.md
This project is designed to run on an AWS g5.4xlarge instance using Miniconda with Python 3.12 and Docker. Follow these steps to set up the environment:
-
Clone this repository:
git clone https://github.com/your-username/ai-psychologist-chatbot.git cd ai-psychologist-chatbot -
Install Miniconda if you haven't already:
wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh bash Miniconda3-latest-Linux-x86_64.sh -
Install Docker if not already installed:
sudo apt-get update sudo apt-get install docker.io -
Start the Ollama Docker container:
docker run -d --gpus=all -v /home/ollama:/root/.ollama:z -p 11434:11434 --name ollama ollama/ollama -
Pull the required Ollama models:
docker exec -it ollama ollama pull llama3.1:8b docker exec -it ollama ollama pull nomic-embed-text -
Create and activate a new Conda environment:
conda create -n psychochat python=3.12 conda activate psychochat -
Install the required packages:
pip install -r requirements.txt
Before running the chatbot, you need to populate the knowledge base:
- Place your knowledge base files (PDF, DOC, TXT, MD, etc.) in the
data/directory. - Open and run the
notebooks/db-populate.ipynbJupyter notebook:This notebook will process the files in thejupyter notebook notebooks/db-populate.ipynbdata/directory and create a vector database for use with the RAG system.
There are two versions of the chatbot available:
-
Basic Chatbot:
python src/chatbot.pyThis version uses llama3.1:8b model's knowledge with prompt engineering without any RAG.
-
RAG-enhanced Chatbot:
python src/rag-chatbot.pyThis version uses Retrieval-Augmented Generation to provide responses based on the knowledge base in addition.
Both chatbots will start a Streamlit web application. Open the provided URL in your web browser to interact with the chatbot.
- Utilizes the Llama 3.1 8B model through Ollama for natural language processing
- Uses the Nomic Embed Text model for generating embeddings
- Classification of user input into various psychological categories (Using llama3.1:8b)
- Empathetic and supportive responses tailored to the user's needs via prompt engineering
- Retrieval-Augmented Generation for more informed and context-aware responses (in rag-chatbot.py)
- Streamlit-based user interface for easy interaction
- Source citation and display for transparency (in rag-chatbot.py)
We have several plans to improve and expand this project:
- Improve the knowledge base (KB) with more comprehensive and diverse psychological resources.
- Add summarization of the knowledge base and improve metadata to enhance retrieval accuracy.
- Apply hybrid search techniques to improve the match quality between user queries and KB content.
- Add reranking to further refine the relevance of retrieved information.
- Improve the prompts used for both classification and response generation to enhance the chatbot's effectiveness and empathy.
This Chatbot is not a substitute for professional medical advice, diagnosis, or treatment. Always seek the advice of your physician or other qualified health provider with any questions you may have regarding a medical condition.
MIT License