This project implements a mental health chatbot using advanced language models and various tools to provide empathetic, professional, and evidence-based support to users seeking help with their mental health and emotional well-being.
- Project Overview
- Features
- Prerequisites
- Installation
- Backend Setup
- Frontend Setup
- Usage
- Project Structure
- Configuration
- API Endpoints
- Contributing
The WellCareBot is designed to act as a virtual psychotherapist, utilizing a combination of cognitive-behavioral therapy (CBT), interpersonal therapy (IPT), psychodynamic therapy, and supportive therapy. It uses advanced language models and specialized tools to provide personalized support and information to users.
- Empathetic and professional responses to user queries
- Integration of multiple therapeutic approaches
- Use of specialized tools for retrieving mental health information and conducting web searches
- Flask-based API for easy integration into web applications
- Persistence of conversation threads
- Streaming responses for a more dynamic user experience
- Flutter-based mobile application for user interaction
- Integration with Twilio for WhatsApp communication
- Python 3.7+
- OpenAI API key
- Tavily API key
- Pinecone API key
- Groq API key (if using Groq models)
- Twilio Account SID, Auth Token, and Phone Number
- Flutter SDK
- Android Studio or VS Code with Flutter extension
- A device or emulator to run the application
-
Clone the repository:
git clone https://github.com/katendejericho5/mental-health-chatbot.git cd mental-health-chatbot/backend
-
Install the required packages:
pip install -r requirements.txt
-
Set up your environment variables by creating a
.env
file in thebackend
directory:OPENAI_API_KEY=your_openai_api_key TAVILY_API_KEY=your_tavily_api_key PINECONE_API_KEY=your_pinecone_api_key GROQ_API_KEY=your_groq_api_key TWILIO_PHONE_NUMBER=your_twilio_phone_number TWILIO_ACCOUNT_SID=your_twilio_account_sid TWILIO_AUTH_TOKEN=your_twilio_auth_token
-
To start the Flask server, run:
python main.py
The server will start on http://localhost:5000
by default.
-
Clone the repository (if not already done):
git clone https://github.com/katendejericho5/mental-health-chatbot.git cd mental-health-chatbot/frontend
-
Ensure you have the Flutter SDK installed. If not, follow the official installation guide.
-
Install the required dependencies:
flutter pub get
-
Run the application on an emulator or connected device:
flutter run
-
Link to the APK via Google Drive:
https://drive.google.com/drive/folders/1M1rfdRwTkqWhKcJbs5asiiVXlEfZZZ3o?usp=sharing
To start the Flask server:
python main.py
The server will start on http://localhost:5000
by default.
To run the Flutter application:
flutter run
backend/main.py
: Main Flask application with routes and logicbackend/graph.py
: Defines the conversation flow graphbackend/tools.py
: Implements specialized tools for information retrievalbackend/functions.py
: Utility functions for environment setup and message formattingbackend/agents.py
: Defines the AI assistant and language model setupbackend/retrieval.py
: Handles document retrieval from Pinecone
frontend/lib/
: Contains the Flutter application codefrontend/lib/screens/
: UI screens of the applicationfrontend/lib/widgets/
: Custom widgets used in the applicationfrontend/lib/services/
: Services for API calls and data handling
Ensure you have set up the following in your .env
file:
OPENAI_API_KEY
: Your OpenAI API keyTAVILY_API_KEY
: Your Tavily API key for web searchesPINECONE_API_KEY
: Your Pinecone API key for vector storageGROQ_API_KEY
: Your Groq API key (if using Groq models)TWILIO_PHONE_NUMBER
: Your Twilio phone numberTWILIO_ACCOUNT_SID
: Your Twilio Account SIDTWILIO_AUTH_TOKEN
: Your Twilio Auth Token
Ensure you have set up the following in your .env
file:
API_BASE_URL
: Base URL of the backend API (e.g.,http://localhost:5000
)
- URL:
/thread
- Method:
GET
- Response: JSON object with a
thread_id
- URL:
/chat/therapist
- Method:
POST
- Body:
{ "message": "User's message", "thread_id": "UUID of the conversation thread", "email": "User's email" }
- Response: JSON object with the AI's response
- URL:
/chat/companion
- Method:
POST
- Body:
{ "message": "User's message", "thread_id": "UUID of the conversation thread" }
- Response: JSON object with the AI's response
- URL:
/renew-rate-limit
- Method:
POST
- Response: JSON object with a success message
- URL:
/whatsapp
- Method:
POST
- Body: Form data with
Body
andFrom
- Response: Twilio MessagingResponse
Contributions are welcome! Please feel free to submit a Pull Request.