Make your first PR. A beginner friendly repository made specifically for open source beginners. Add any program under any language (it can be anything from a simple program to a complex data structure algorithm). Happy coding...
8
stars
51
forks
source link
Add Chatbot Project with LLM Integration and MySQL Database Support #19
This pull request introduces a chatbot application that interacts with users using an LLM (Large Language Model) service. The chatbot can store chat histories in a MySQL database and retrieve responses from various LLM services like Together and Groq. The project is modular and divided into separate components for easy maintenance, scalability, and future development.
### Features
- Connects with language models (LLMs) from services like Together and Groq to generate AI-driven conversations.
- Stores chat histories (both user and assistant messages) in a MySQL database.
- Automatically tracks the start and end of a conversation session.
- Modular design to separate database, chatbot logic, and LLM interaction.
- Efficient chat history handling (trimming older messages to improve performance during long conversations).
### Prerequisites
- Python 3.x
- MySQL
- pip (Python package manager)
- `dotenv` for environment variable management
- Together API key (if using Together LLM service)
- Groq API key (if using Groq LLM service)
### Installation
1. Clone the repository:
```bash
git clone https://github.com/Hacktoberfest2024_avi_1/ChatDB-LLM-Assistant/chatbot_project.git
cd chatbot_project
Install the required Python packages:
pip3 install -r requirements.txt
Set up environment variables in a .env file:
DB_USER=your_mysql_user
DB_PASSWORD=your_mysql_password
DB_HOST=your_mysql_host
DB_NAME=your_database_name
TOGETHER_API_KEY=your_together_api_key # Only required if using Together API
GROQ_API_KEY=your_groq_api_key # Only required if using Groq API
Set up MySQL database and ensure it is running.
Usage
To start the chatbot, run:
python main.py
Project Structure
chatbot_project/
│
├── db.py # Database handling logic (MySQL connection, data insertion, retrieval)
├── llm_service.py # Logic for interacting with LLM services (Together, Groq)
├── chatbot.py # Main chatbot logic (conversation flow management)
├── main.py # Entry point for the chatbot application
├── .env # Environment variables (API keys, DB credentials)
├── requirements.txt # Python dependencies
└── README.md # Project documentation
.env
file:Usage
To start the chatbot, run:
Project Structure