Welcome to the LLM Based Project of Software Studio! This project is a Django-based chatbot that integrates Ollama (to use deepseek-r1 locally). It is containerized using Docker for easy deployment and follows a microservices architecture with a Service Registry for dynamic service discovery and communication.
- LLM-Project: Software Studio
- Assignment 2: Service Discovery
Before running the project, ensure you have the following installed:
- Python 3.8.10
- pip (Python package manager)
- Docker (for containerized deployment)
- Ollama (for the AI interaction)
Ensure:
- Ollama is running on your machine (
http://localhost:11434)
git clone https://github.com/Hasan-Saju/LLM-Project-Studio
cd LLM-Project-Studiopython -m venv venv
source venv/bin/activate # For macOS/Linux
venv\Scripts\activate # For Windowspip install -r requirements.txtcd llm_project
python manage.py makemigrations
python manage.py migratepython manage.py runserver- The application will be available at http://127.0.0.1:8000/
docker build -t my-django-app .docker run -p 8000:8000 my-django-app- The application will be accessible at http://localhost:8000/
To configure Ollama API URL, create a .env file in the llm_project directory with:
ENVIRONMENT=development # or 'production'
# Ollama API URL
OLLAMA_API_DEV=http://localhost:11434
OLLAMA_API_PROD=http://host.docker.internal:11434 The Service Registry is a microservice that allows dynamic discovery, registration, and communication between different microservices in a distributed architecture. It enables microservices to register themselves, send heartbeats to indicate their availability, and communicate with each other.
- Service Registration: Microservices register themselves with the registry upon startup.
- Heartbeat Monitoring: Services send a heartbeat every 2 minutes to indicate they are alive.
- Service Discovery: Any service can request a list of available services.
- Message Forwarding: Allows a service to send a message to another service.
- Auto Deregistration: If a service fails to send a heartbeat within 5 minutes, it is removed from the registry.
- Python (Flask for the Service Registry, Requests for HTTP communication)
- Django (For the chatbot)
- Threading (For background monitoring of inactive services)
Run the service registry to allow microservices to register:
python service_registrar.py- Endpoint:
POST /register - Request Body:
{ "service_name": "grammar_service", "service_address": "http://localhost:5002/process" } - Response:
{"message": "Service grammar_service registered successfully"}
- Endpoint:
GET /list - Response:
{ "grammar_service": "http://localhost:5002/process" }
- Endpoint:
POST /heartbeat - Request Body:
{"service_name": "grammar_service"} - Response:
{"message": "Heartbeat received from grammar_service"}
- Endpoint:
POST /forward - Request Body:
{ "target_service": "grammar_service", "payload": {"message": "r u fine"} } - Response:
{"fixed_message": "are you fine"}
- A background thread runs every 60 seconds to check for inactive services.
- If a service does not send a heartbeat for 5 minutes, it is automatically removed.
- Endpoint:
GET /microservices/list/ - Chatbot Request:
response = requests.get("http://localhost:5001/list") available_services = response.json()
- Example Response:
{ "grammar_service": "http://localhost:5002/process" }
- Endpoint:
POST /microservices/forward/ - Chatbot Request:
response = requests.post("http://localhost:5001/forward", json={ "target_service": "grammar_service", "payload": {"message": "r u fine"} }) fixed_message = response.json()["fixed_message"]
- Example Response:
{"fixed_message": "are you fine"}
python grammar_service.pypython manage.py runserverThe Service Registry ensures seamless communication between microservices by dynamically managing service discovery and request forwarding.

