├── .gitignore ├── LICENSE ├── README.md ├── chatbot ├── __init__.py ├── asgi.py ├── settings.py ├── urls.py └── wsgi.py ├── chatbotapp ├── __init__.py ├── admin.py ├── apps.py ├── migrations │ ├── 0001_initial.py │ └── __init__.py ├── models.py ├── tests.py ├── urls.py └── views.py ├── manage.py ├── requirements.txt └── templates └── chatbot └── list_messages.html /.gitignore: -------------------------------------------------------------------------------- 1 | __pycache__ 2 | db.sqlite3 3 | venv -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2024 André Gervásio 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # How to Develop an AI Chatbot Application with Python Django and Google Gemini API 2 | 3 | This guide equips you with the steps to bring your chatbot to life, empowering you to create engaging user experiences with a powerful AI chatbot built using Django and Google Gemini API. 4 | 5 | ## About the author - André Gervásio 6 | 7 | 20+ years of experience in software development. Bachelor's degree in Computer Science. Fullstack Software Engineer and Tech Lead in Java, Python, JS, PHP applications. Certified in Front-End, Back-End and DevOps technologies. Experienced in Scrum and Agile Methodologies. Solid knowledge in Databases and ORMs. Practical skills in Cloud Computing Services. 8 | 9 | [Visit my LinkedIn](https://www.linkedin.com/in/andregervasio/) 10 | 11 | 12 | ## 1. Install Python and Django 13 | 14 | Before diving into code, ensure you have the following tools: 15 | 16 | * Verify Python installation using the following command in your terminal: 17 | 18 | ``` 19 | python3 --version # or python --version 20 | ``` 21 | 22 | * If it is installed, you should see the version number. Otherwise, download it from [https://www.python.org/downloads/](https://www.python.org/downloads/). 23 | 24 | * Create a directory for your project. In this article, we'll use the name **chatbot-django-gemini**. Access it and create a virtual environment to isolate project dependencies: 25 | 26 | ``` 27 | mkdir chatbot-django-gemini 28 | cd chatbot-django-gemini 29 | python3 -m venv venv 30 | ``` 31 | 32 | * Activate the virtual environment: 33 | 34 | ``` 35 | source venv/bin/activate 36 | ``` 37 | 38 | * Install Django using pip: 39 | 40 | ``` 41 | pip install django 42 | ``` 43 | 44 | ## 2. Create a Django Project 45 | 46 | A Django project serves as the foundation for your chatbot application. 47 | 48 | * Open your terminal and navigate to your desired project directory. 49 | 50 | * Execute the following command to create a new Django project named **chatbot** in the current directory: 51 | 52 | ``` 53 | django-admin startproject chatbot . 54 | ``` 55 | 56 | ## 3. Create a Django App 57 | 58 | Django apps organize functionalities. We'll create one for our chatbot logic: 59 | 60 | * Within your **chatbot** project directory, run this command: 61 | 62 | ``` 63 | python3 manage.py startapp chatbotapp 64 | ``` 65 | 66 | ## 4. Integrate Google GenerativeAI Library 67 | 68 | The Google GenerativeAI library allows us to interact with the Gemini API for generating responses. 69 | 70 | * Use pip to install the library: 71 | 72 | ``` 73 | pip install google-generativeai 74 | ``` 75 | 76 | * An API key is required to use the GenerativeAI library. 77 | 78 | * Browse to [https://ai.google/](https://ai.google/) and create or select a project. 79 | 80 | * Go to the Get API Key page. 81 | 82 | * Click on Create API Key to obtain an API key. Store it securely (we'll use an environment variable later). 83 | 84 | ## 5. Configure Django Settings 85 | 86 | * Now, let's configure Django to work with our chatbot app and API key. 87 | 88 | Django projects are organized by individual applications, each focusing on specific functionalities. In step 3, you created a Django app named **chatbotapp** to encapsulate the logic behind your chatbot. Here's why we need to add it to **INSTALLED_APPS**: 89 | 90 | * Modular Project Structure: Django projects promote a modular approach. By creating separate apps, you can organize your codebase efficiently and maintain a clean separation of concerns. Each app can have its own models, views, templates, and other components specific to its functionality. 91 | * App Recognition: When you add **chatbotapp** to **INSTALLED_APPS**, you essentially tell Django: "Hey, this **chatbotapp** exists, and it's part of this project. Recognize it and include its functionalities when running the project." 92 | * Component Discovery: Including **chatbotapp** in **INSTALLED_APPS** allows Django to discover the components (models, views, templates) within your **chatbotapp**. These components are crucial for building the chatbot's features. 93 | 94 | * Open your project's **chatbot/settings.py** file. 95 | 96 | * Inside the **INSTALLED_APPS** list, add **'chatbotapp'**. 97 | 98 | * We'll use an environment variable for security. In your terminal, set the API key using a command like: 99 | 100 | ``` 101 | export GENERATIVE_AI_KEY="YOUR_API_KEY_HERE" 102 | ``` 103 | 104 | * Replace **YOUR_API_KEY_HERE** with your actual key. 105 | 106 | * In **settings.py**, add the following code to access the key securely: 107 | 108 | ```python 109 | GENERATIVE_AI_KEY = os.environ.get('GENERATIVE_AI_KEY') # Don't forget to import os package 110 | 111 | if not GENERATIVE_AI_KEY: 112 | raise ValueError('GENERATIVE_AI_KEY environment variable not set') 113 | ``` 114 | 115 | ## 6. Define the Chatbot Model 116 | 117 | This step allows you to store and manage chat interactions in your database. 118 | 119 | * In your **chatbotapp/models.py** file, define a model named **ChatMessage** using Python classes that inherit from Django's **Model** class. 120 | 121 | ```python 122 | from django.db import models 123 | 124 | class ChatMessage(models.Model): 125 | user_message = models.TextField() 126 | bot_response = models.TextField() 127 | created_at = models.DateTimeField(auto_now_add=True) 128 | 129 | def __str__(self): 130 | return f"User: {self.user_message}, Bot: {self.bot_response}" 131 | ``` 132 | 133 | * If you want to use the Django admin interface to manage chat history, register your model in **chatbotapp/admin.py**: 134 | 135 | ```python 136 | from django.contrib import admin 137 | from .models import ChatMessage 138 | 139 | admin.site.register(ChatMessage) 140 | ``` 141 | 142 | * To apply the model changes to your database, run the following commands in your terminal: 143 | 144 | ``` 145 | python3 manage.py makemigrations 146 | python3 manage.py migrate 147 | ``` 148 | 149 | ## 7. Create Views for User Interaction 150 | 151 | Now we'll delve into the heart of our chatbot's functionality - handling user interactions and managing conversation history. This is achieved by creating views in Django. Views are like controllers that handle user requests and generate responses. 152 | 153 | * Create a view in **chatbotapp/views.py**. 154 | 155 | * In our case, we'll define two views: 156 | 157 | 1. **send_message:** This view handles user messages submitted through a form. It retrieves the user's message, interacts with the Gemini API and generates a response. Additionally, it saves the conversation and redirects the user to another view displaying the chat messages. 158 | 2. **list_messages:** This view retrieves all stored chat messages from the database and renders them in a template (which you'll create in a further step). This allows users to see the conversation history and track their interactions with the chatbot. 159 | 160 | ```python 161 | from django.shortcuts import redirect, render 162 | from chatbot.settings import GENERATIVE_AI_KEY 163 | from chatbotapp.models import ChatMessage 164 | import google.generativeai as genai 165 | 166 | def send_message(request): 167 | if request.method == 'POST': 168 | genai.configure(api_key=GENERATIVE_AI_KEY) 169 | model = genai.GenerativeModel("gemini-pro") 170 | 171 | user_message = request.POST.get('user_message') 172 | bot_response = model.generate_content(user_message) 173 | 174 | ChatMessage.objects.create(user_message=user_message, bot_response=bot_response.text) 175 | 176 | return redirect('list_messages') 177 | 178 | def list_messages(request): 179 | messages = ChatMessage.objects.all() 180 | return render(request, 'chatbot/list_messages.html', { 'messages': messages }) 181 | ``` 182 | 183 | ## 8. Configure Routes 184 | 185 | In Django, URLs map user requests to specific views. This step involves defining routes within your chatbot app and including them in your main project's URL configuration. 186 | 187 | * Create a new file **chatbotapp/urls.py**. This file will define URL patterns specific to your chatbot app. 188 | 189 | ```python 190 | from django.urls import path 191 | from .views import send_message, list_messages 192 | 193 | urlpatterns = [ 194 | path('send', send_message, name='send_message'), 195 | path('', list_messages, name='list_messages'), 196 | ] 197 | ``` 198 | 199 | * Now, you need to include the chatbot app's URL patterns within your main project's URL configuration file **chatbot/urls.py**. 200 | 201 | ```python 202 | from django.urls import path, include # Don't forget to import include function 203 | from adminsite import admin 204 | 205 | urlpatterns = [ 206 | path('admin/', admin.site.urls), 207 | path('chatbot/', include('chatbotapp.urls')), # Include the chatbot app's URL patterns 208 | ] 209 | ``` 210 | 211 | ## 9. Build Templates for User Interface 212 | 213 | Templates define the structure and presentation of your chatbot's user interface. 214 | 215 | * Create a template in **templates/chatbot/list_messages.html**. 216 | 217 | * This template will likely include an input field for the user's message, a button to submit the message, and a space to display the chatbot's response. 218 | 219 | ```html 220 | 221 | 222 | 223 | 224 | Chatbot 225 | 226 | 227 | {% for message in messages %} 228 |
229 | User: {{ message.user_message }} 230 |
231 |
232 | Bot: {{ message.bot_response }} 233 |
234 | {% endfor %} 235 | 236 |
237 | {% csrf_token %} 238 | 239 | 240 |
241 | 242 | 243 | ``` 244 | 245 | * To ensure Django recognizes your template directory, you need to update the **TEMPLATES** setting in your **chatbot/settings.py** file. 246 | 247 | ```python 248 | TEMPLATES = [ 249 | { 250 | 'BACKEND': 'django.template.backends.django.DjangoTemplates', 251 | 'DIRS': [os.path.join(BASE_DIR, 'templates')], # Update DIRS path. Don't forget to include os package. 252 | 'APP_DIRS': True, 253 | 'OPTIONS': { 254 | 'context_processors': [], 255 | }, 256 | }, 257 | ] 258 | ``` 259 | 260 | ## 10. Run the Server and Test Your Chatbot 261 | 262 | * In your terminal, navigate to your project directory and start the Django development server using: 263 | 264 | ``` 265 | python3 manage.py runserver 266 | ``` 267 | 268 | * This will typically launch the server on port 8000 by default. 269 | 270 | * Open your web browser and visit the chatbot URL defined in your project's URL configuration (http://127.0.0.1:8000/chatbot). This should render your chatbot interface. 271 | 272 | ## Conclusion 273 | 274 | These are the essential steps to build a basic AI chatbot using Django and Gemini API. This provides a solid foundation for crafting interactive and informative chatbots that can engage with users. 275 | 276 | You can extend this functionality in various ways: 277 | 278 | * **User Authentication:** Implement user authentication to personalize the chatbot experience and potentially access user data for more tailored responses. 279 | * **Advanced Chat functionalities:** Explore integrating features like buttons, images, or links within the chatbot responses for a richer user interaction. 280 | * **Custom GenerativeAI Models:** Consider experimenting with different GenerativeAI models offered by Gemini to find the best fit for your specific use case. 281 | 282 | By leveraging the power of Django and Gemini API, you can create versatile AI chatbots that can streamline communication, answer questions, and provide valuable interactions for your users. Explore the possibilities! 283 | -------------------------------------------------------------------------------- /chatbot/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andreger/chatbot-django-gemini/17a7d4aecb3028f1af9df359f2e58ce5a121e2f4/chatbot/__init__.py -------------------------------------------------------------------------------- /chatbot/asgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | ASGI config for chatbot project. 3 | 4 | It exposes the ASGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/5.0/howto/deployment/asgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.asgi import get_asgi_application 13 | 14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'chatbot.settings') 15 | 16 | application = get_asgi_application() 17 | -------------------------------------------------------------------------------- /chatbot/settings.py: -------------------------------------------------------------------------------- 1 | """ 2 | Django settings for chatbot project. 3 | 4 | Generated by 'django-admin startproject' using Django 5.0.6. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/5.0/topics/settings/ 8 | 9 | For the full list of settings and their values, see 10 | https://docs.djangoproject.com/en/5.0/ref/settings/ 11 | """ 12 | 13 | from pathlib import Path 14 | import os 15 | 16 | # Build paths inside the project like this: BASE_DIR / 'subdir'. 17 | BASE_DIR = Path(__file__).resolve().parent.parent 18 | 19 | 20 | # Quick-start development settings - unsuitable for production 21 | # See https://docs.djangoproject.com/en/5.0/howto/deployment/checklist/ 22 | 23 | # SECURITY WARNING: keep the secret key used in production secret! 24 | SECRET_KEY = 'django-insecure-ds=ovb!y)*07(%9qo=h5md$=u-ne0fljg^sszei_*_1mr=x8j%' 25 | 26 | # SECURITY WARNING: don't run with debug turned on in production! 27 | DEBUG = True 28 | 29 | ALLOWED_HOSTS = [] 30 | 31 | 32 | # Application definition 33 | 34 | INSTALLED_APPS = [ 35 | 'django.contrib.admin', 36 | 'django.contrib.auth', 37 | 'django.contrib.contenttypes', 38 | 'django.contrib.sessions', 39 | 'django.contrib.messages', 40 | 'django.contrib.staticfiles', 41 | 'chatbotapp', 42 | ] 43 | 44 | MIDDLEWARE = [ 45 | 'django.middleware.security.SecurityMiddleware', 46 | 'django.contrib.sessions.middleware.SessionMiddleware', 47 | 'django.middleware.common.CommonMiddleware', 48 | 'django.middleware.csrf.CsrfViewMiddleware', 49 | 'django.contrib.auth.middleware.AuthenticationMiddleware', 50 | 'django.contrib.messages.middleware.MessageMiddleware', 51 | 'django.middleware.clickjacking.XFrameOptionsMiddleware', 52 | ] 53 | 54 | ROOT_URLCONF = 'chatbot.urls' 55 | 56 | TEMPLATES = [ 57 | { 58 | 'BACKEND': 'django.template.backends.django.DjangoTemplates', 59 | 'DIRS': [os.path.join(BASE_DIR, 'templates')], 60 | 'APP_DIRS': True, 61 | 'OPTIONS': { 62 | 'context_processors': [ 63 | 'django.template.context_processors.debug', 64 | 'django.template.context_processors.request', 65 | 'django.contrib.auth.context_processors.auth', 66 | 'django.contrib.messages.context_processors.messages', 67 | ], 68 | }, 69 | }, 70 | ] 71 | 72 | WSGI_APPLICATION = 'chatbot.wsgi.application' 73 | 74 | 75 | # Database 76 | # https://docs.djangoproject.com/en/5.0/ref/settings/#databases 77 | 78 | DATABASES = { 79 | 'default': { 80 | 'ENGINE': 'django.db.backends.sqlite3', 81 | 'NAME': BASE_DIR / 'db.sqlite3', 82 | } 83 | } 84 | 85 | 86 | # Password validation 87 | # https://docs.djangoproject.com/en/5.0/ref/settings/#auth-password-validators 88 | 89 | AUTH_PASSWORD_VALIDATORS = [ 90 | { 91 | 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', 92 | }, 93 | { 94 | 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', 95 | }, 96 | { 97 | 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', 98 | }, 99 | { 100 | 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', 101 | }, 102 | ] 103 | 104 | 105 | # Internationalization 106 | # https://docs.djangoproject.com/en/5.0/topics/i18n/ 107 | 108 | LANGUAGE_CODE = 'en-us' 109 | 110 | TIME_ZONE = 'UTC' 111 | 112 | USE_I18N = True 113 | 114 | USE_TZ = True 115 | 116 | 117 | # Static files (CSS, JavaScript, Images) 118 | # https://docs.djangoproject.com/en/5.0/howto/static-files/ 119 | 120 | STATIC_URL = 'static/' 121 | 122 | # Default primary key field type 123 | # https://docs.djangoproject.com/en/5.0/ref/settings/#default-auto-field 124 | 125 | DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField' 126 | 127 | GENERATIVE_AI_KEY = os.environ.get('GENERATIVE_AI_KEY') 128 | 129 | if not GENERATIVE_AI_KEY: 130 | raise ValueError('GENERATIVE_AI_KEY environment variable not set') -------------------------------------------------------------------------------- /chatbot/urls.py: -------------------------------------------------------------------------------- 1 | """ 2 | URL configuration for chatbot project. 3 | 4 | The `urlpatterns` list routes URLs to views. For more information please see: 5 | https://docs.djangoproject.com/en/5.0/topics/http/urls/ 6 | Examples: 7 | Function views 8 | 1. Add an import: from my_app import views 9 | 2. Add a URL to urlpatterns: path('', views.home, name='home') 10 | Class-based views 11 | 1. Add an import: from other_app.views import Home 12 | 2. Add a URL to urlpatterns: path('', Home.as_view(), name='home') 13 | Including another URLconf 14 | 1. Import the include() function: from django.urls import include, path 15 | 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) 16 | """ 17 | from django.contrib import admin 18 | from django.urls import path, include 19 | 20 | urlpatterns = [ 21 | path('admin/', admin.site.urls), 22 | path('chatbot/', include('chatbotapp.urls')), 23 | ] 24 | -------------------------------------------------------------------------------- /chatbot/wsgi.py: -------------------------------------------------------------------------------- 1 | """ 2 | WSGI config for chatbot project. 3 | 4 | It exposes the WSGI callable as a module-level variable named ``application``. 5 | 6 | For more information on this file, see 7 | https://docs.djangoproject.com/en/5.0/howto/deployment/wsgi/ 8 | """ 9 | 10 | import os 11 | 12 | from django.core.wsgi import get_wsgi_application 13 | 14 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'chatbot.settings') 15 | 16 | application = get_wsgi_application() 17 | -------------------------------------------------------------------------------- /chatbotapp/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andreger/chatbot-django-gemini/17a7d4aecb3028f1af9df359f2e58ce5a121e2f4/chatbotapp/__init__.py -------------------------------------------------------------------------------- /chatbotapp/admin.py: -------------------------------------------------------------------------------- 1 | from django.contrib import admin 2 | from .models import ChatMessage 3 | 4 | admin.site.register(ChatMessage) -------------------------------------------------------------------------------- /chatbotapp/apps.py: -------------------------------------------------------------------------------- 1 | from django.apps import AppConfig 2 | 3 | 4 | class ChatbotappConfig(AppConfig): 5 | default_auto_field = 'django.db.models.BigAutoField' 6 | name = 'chatbotapp' 7 | -------------------------------------------------------------------------------- /chatbotapp/migrations/0001_initial.py: -------------------------------------------------------------------------------- 1 | # Generated by Django 5.0.6 on 2024-05-17 20:37 2 | 3 | from django.db import migrations, models 4 | 5 | 6 | class Migration(migrations.Migration): 7 | 8 | initial = True 9 | 10 | dependencies = [ 11 | ] 12 | 13 | operations = [ 14 | migrations.CreateModel( 15 | name='ChatMessage', 16 | fields=[ 17 | ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), 18 | ('user_message', models.TextField()), 19 | ('bot_response', models.TextField()), 20 | ('created_at', models.DateTimeField(auto_now_add=True)), 21 | ], 22 | ), 23 | ] 24 | -------------------------------------------------------------------------------- /chatbotapp/migrations/__init__.py: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/andreger/chatbot-django-gemini/17a7d4aecb3028f1af9df359f2e58ce5a121e2f4/chatbotapp/migrations/__init__.py -------------------------------------------------------------------------------- /chatbotapp/models.py: -------------------------------------------------------------------------------- 1 | from django.db import models 2 | 3 | class ChatMessage(models.Model): 4 | user_message = models.TextField() 5 | bot_response = models.TextField() 6 | created_at = models.DateTimeField(auto_now_add=True) 7 | 8 | def __str__(self): 9 | return f"User: {self.user_message}, Bot: {self.bot_response}" -------------------------------------------------------------------------------- /chatbotapp/tests.py: -------------------------------------------------------------------------------- 1 | from django.test import TestCase 2 | 3 | # Create your tests here. 4 | -------------------------------------------------------------------------------- /chatbotapp/urls.py: -------------------------------------------------------------------------------- 1 | from django.urls import path 2 | from .views import send_message, list_messages 3 | 4 | urlpatterns = [ 5 | path('send', send_message, name='send_message'), 6 | path('', list_messages, name='list_messages'), 7 | ] -------------------------------------------------------------------------------- /chatbotapp/views.py: -------------------------------------------------------------------------------- 1 | from django.shortcuts import redirect, render 2 | from chatbot.settings import GENERATIVE_AI_KEY 3 | from chatbotapp.models import ChatMessage 4 | import google.generativeai as genai 5 | 6 | def send_message(request): 7 | if request.method == 'POST': 8 | genai.configure(api_key=GENERATIVE_AI_KEY) 9 | model = genai.GenerativeModel("gemini-pro") 10 | 11 | user_message = request.POST.get('user_message') 12 | bot_response = model.generate_content(user_message) 13 | 14 | ChatMessage.objects.create(user_message=user_message, bot_response=bot_response.text) 15 | 16 | return redirect('list_messages') 17 | 18 | def list_messages(request): 19 | messages = ChatMessage.objects.all() 20 | return render(request, 'chatbot/list_messages.html', { 'messages': messages }) -------------------------------------------------------------------------------- /manage.py: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env python 2 | """Django's command-line utility for administrative tasks.""" 3 | import os 4 | import sys 5 | 6 | 7 | def main(): 8 | """Run administrative tasks.""" 9 | os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'chatbot.settings') 10 | try: 11 | from django.core.management import execute_from_command_line 12 | except ImportError as exc: 13 | raise ImportError( 14 | "Couldn't import Django. Are you sure it's installed and " 15 | "available on your PYTHONPATH environment variable? Did you " 16 | "forget to activate a virtual environment?" 17 | ) from exc 18 | execute_from_command_line(sys.argv) 19 | 20 | 21 | if __name__ == '__main__': 22 | main() 23 | -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | annotated-types==0.6.0 2 | asgiref==3.8.1 3 | cachetools==5.3.3 4 | certifi==2024.2.2 5 | charset-normalizer==3.3.2 6 | Django==5.0.6 7 | google-ai-generativelanguage==0.6.4 8 | google-api-core==2.19.0 9 | google-api-python-client==2.129.0 10 | google-auth==2.29.0 11 | google-auth-httplib2==0.2.0 12 | google-generativeai==0.5.4 13 | googleapis-common-protos==1.63.0 14 | grpcio==1.63.0 15 | grpcio-status==1.62.2 16 | httplib2==0.22.0 17 | idna==3.7 18 | proto-plus==1.23.0 19 | protobuf==4.25.3 20 | pyasn1==0.6.0 21 | pyasn1_modules==0.4.0 22 | pydantic==2.7.1 23 | pydantic_core==2.18.2 24 | pyparsing==3.1.2 25 | requests==2.31.0 26 | rsa==4.9 27 | sqlparse==0.5.0 28 | tqdm==4.66.4 29 | typing_extensions==4.11.0 30 | uritemplate==4.1.1 31 | urllib3==2.2.1 32 | -------------------------------------------------------------------------------- /templates/chatbot/list_messages.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | 5 | Chatbot 6 | 7 | 8 | {% for message in messages %} 9 |
10 | User: {{ message.user_message }} 11 |
12 |
13 | Bot: {{ message.bot_response }} 14 |
15 | {% endfor %} 16 | 17 |
18 | {% csrf_token %} 19 | 20 | 21 |
22 | 23 | --------------------------------------------------------------------------------