Chatbot Project using [Django + Postgresql + Ollama] for beginner
This guide will help you set up the Chatbot project using Django and Ollama's qwen2:1.5b model.
- Recommended to use Python 3.12.1 for a smooth experience.
- Ensure you have PostgreSQL installed and running.
Make sure you can run Ollama by following the instructions on the Ollama installation page.
python -m venv venv- Windows:
.\venv\Scripts\activate
- macOS/Linux:
source venv/bin/activate
Install the requirements:
pip install -r requirements.txtdjango-admin startproject chatbot
cd chatbot
django-admin startapp messagingEdit the DATABASES setting in chatbot/settings.py to configure your PostgreSQL database:
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql',
'NAME': 'chatbot',
'USER': 'your_db_user',
'PASSWORD': 'your_db_password',
'HOST': 'your_db_host',
'PORT': 'your_db_port',
}
}python manage.py makemigrations
python manage.py migratepython manage.py runserverYou can test the API using Postman or curl.
- URL:
http://localhost:8000/api/messages/ask - Method:
POST - Body (JSON):
{ "question": "kenapa langit biru?" }
curl -X POST http://localhost:8000/api/messages/ask -H "Content-Type: application/json" -d '{"question":"kenapa langit biru?"}'This should return a response from the chatbot model.
- This example uses the
qwen2:1.5bmodel, which is a lightweight model that performs adequately in Bahasa Indonesia.
- add param to change language model
- add streaming capability, for streams the answer
- saved the answer to database
- optimzation
