diff --git a/core/__pycache__/views.cpython-311.pyc b/core/__pycache__/views.cpython-311.pyc index 63db3ad..4722135 100644 Binary files a/core/__pycache__/views.cpython-311.pyc and b/core/__pycache__/views.cpython-311.pyc differ diff --git a/core/templates/core/chat.html b/core/templates/core/chat.html index 48f2b91..e75bdf1 100644 --- a/core/templates/core/chat.html +++ b/core/templates/core/chat.html @@ -58,6 +58,9 @@ {% endif %} +
@@ -78,6 +81,15 @@ const chatTextarea = document.getElementById('chat-textarea'); const chatForm = document.getElementById('chat-form'); + const loaderOverlay = document.getElementById('loader-overlay'); + + if (chatForm) { + chatForm.addEventListener('submit', function() { + if (loaderOverlay) { + loaderOverlay.style.display = 'flex'; + } + }); + } if (chatTextarea && chatForm) { chatTextarea.addEventListener('keydown', function(e) { diff --git a/core/views.py b/core/views.py index 7567fc5..667fdc5 100644 --- a/core/views.py +++ b/core/views.py @@ -80,9 +80,26 @@ def chat_view(request, conversation_id=None): history.append({"role": role, "content": msg.content}) try: + system_message = { + "role": "system", + "content": "You are a helpful assistant for a project management application. Your purpose is to assist users with their tasks and provide information about the application. The application manages articles and a to-do list." + } + + tasks = TodoItem.objects.all().order_by('created_at') + task_list_str = "\n".join([ + f"- {task.title} (Status: {task.get_status_display()}, Tags: {task.tags or 'None'})" + for task in tasks + ]) + + tasks_context = { + "role": "system", + "content": f"Here is the current list of tasks:\n{task_list_str}" + } + response = LocalAIApi.create_response({ "input": [ - {"role": "system", "content": "You are a helpful assistant."}, + system_message, + tasks_context, *history ] }) diff --git a/static/css/custom.css b/static/css/custom.css index 3cccea4..742ef2f 100644 --- a/static/css/custom.css +++ b/static/css/custom.css @@ -79,6 +79,7 @@ body { display: flex; flex-direction: column; background-color: #ffffff; + position: relative; /* Needed for loader overlay */ } /* Chat Header */ @@ -170,3 +171,31 @@ body { height: 100%; color: #6c757d; } + +/* Loader Styles */ +.loader-overlay { + position: absolute; + top: 0; + left: 0; + right: 0; + bottom: 0; + background-color: rgba(255, 255, 255, 0.8); + display: flex; + justify-content: center; + align-items: center; + z-index: 10; +} + +.loader { + border: 5px solid #f3f3f3; /* Light grey */ + border-top: 5px solid #0d6efd; /* Blue */ + border-radius: 50%; + width: 50px; + height: 50px; + animation: spin 1s linear infinite; +} + +@keyframes spin { + 0% { transform: rotate(0deg); } + 100% { transform: rotate(360deg); } +} \ No newline at end of file diff --git a/staticfiles/css/custom.css b/staticfiles/css/custom.css index 3cccea4..742ef2f 100644 --- a/staticfiles/css/custom.css +++ b/staticfiles/css/custom.css @@ -79,6 +79,7 @@ body { display: flex; flex-direction: column; background-color: #ffffff; + position: relative; /* Needed for loader overlay */ } /* Chat Header */ @@ -170,3 +171,31 @@ body { height: 100%; color: #6c757d; } + +/* Loader Styles */ +.loader-overlay { + position: absolute; + top: 0; + left: 0; + right: 0; + bottom: 0; + background-color: rgba(255, 255, 255, 0.8); + display: flex; + justify-content: center; + align-items: center; + z-index: 10; +} + +.loader { + border: 5px solid #f3f3f3; /* Light grey */ + border-top: 5px solid #0d6efd; /* Blue */ + border-radius: 50%; + width: 50px; + height: 50px; + animation: spin 1s linear infinite; +} + +@keyframes spin { + 0% { transform: rotate(0deg); } + 100% { transform: rotate(360deg); } +} \ No newline at end of file