Skip to content

A lightweight and extensible chatbot web application built with Django and OpenAI API. This project demonstrates how to integrate a conversational AI model into a Django-based web interface.

Notifications You must be signed in to change notification settings

X-astro/django-ai-chatbot

Repository files navigation

🧠 Simple Chatbot (Django)

A lightweight and extensible chatbot web application built with Django and OpenAI API.
This project demonstrates how to integrate a conversational AI model into a Django-based web interface.


🚀 Features

  • 💬 Real-time chat interface powered by Django views and AJAX (or Fetch API)
  • 🔑 Secure integration with OpenAI API
  • 🗂️ Modular app structure for easy extension
  • ⚙️ Environment variable support for API keys
  • 🧪 Ready for local development or cloud deployment

🧩 Tech Stack

  • Backend: Django 5.x / Python 3.10+
  • Frontend: HTML5, CSS3, JavaScript (Fetch API)
  • AI Engine: OpenAI API (ChatGPT-style model)
  • Environment: .env file via python-dotenv or Django settings


⚙️ Installation & Setup

1️⃣ Clone the repository

git clone https://github.com/X-astro/simple-chatbot-django.git
cd simple-chatbot-django

2️⃣ Create a virtual environment

python -m venv venv
source venv/bin/activate  # On Windows use venv\Scripts\activate

3️⃣ Install dependencies

pip install -r requirements.txt

4️⃣ Set your OpenAI API key

Create a .env file in the project root:

OPENAI_API_KEY=your_api_key_here

Or add it directly to your Django settings (not recommended for production).

6️⃣ Start the server

python manage.py runserver

Then open your browser at:

http://127.0.0.1:8000/

💡 Usage

  1. Open the main chat page.
  2. Type your question or message.
  3. The chatbot responds using the configured OpenAI model.
  4. You can customize prompts and logic inside chatbot/views.py.

🧰 Configuration

Variable Description Example
OPENAI_API_KEY Your OpenAI API key sk-abc123...
DEBUG Django debug mode True
ALLOWED_HOSTS Hosts allowed to serve the app ["localhost", "127.0.0.1"]

🧪 Example API Integration (Snippet)

import openai
from django.conf import settings

openai.api_key = settings.OPENAI_API_KEY

def ask_openai(prompt):
    response = openai.ChatCompletion.create(
        model="gpt-3.5-turbo",
        messages=[{"role": "user", "content": prompt}],
    )
    return response['choices'][0]['message']['content']

🛠️ Development Notes

  • You can extend the chat logic for memory, database logging, or multi-user support.
  • Integrate WebSocket (Django Channels) for real-time responses.
  • Style the frontend using Bootstrap, Tailwind, or your preferred framework.

📜 License

This project is licensed under the MIT License — free for personal and commercial use.


🤝 Contributing

Contributions are welcome!

  1. Fork the repo
  2. Create your feature branch
  3. Submit a pull request

🌟 Author

Astro X
“Learning by doing — one project at a time.”


Chatbot Demo

Enjoy building your AI-powered Django chatbot! 🚀

About

A lightweight and extensible chatbot web application built with Django and OpenAI API. This project demonstrates how to integrate a conversational AI model into a Django-based web interface.

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published