-
Notifications
You must be signed in to change notification settings - Fork 381
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
dphuang2
committed
Apr 21, 2024
1 parent
ccb9550
commit 735aeec
Showing
13 changed files
with
288 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
# Generated by Django 5.0.4 on 2024-04-21 07:55 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("chatbot_app", "0001_initial"), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="Chat", | ||
fields=[ | ||
( | ||
"id", | ||
models.BigAutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
( | ||
"messages", | ||
models.ManyToManyField( | ||
related_name="chat", to="chatbot_app.message" | ||
), | ||
), | ||
], | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generated by Django 5.0.4 on 2024-04-21 07:57 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("chatbot_app", "0002_chat"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="chat", | ||
name="name", | ||
field=models.TextField(default="2024/04/21 00:00"), | ||
), | ||
] |
29 changes: 29 additions & 0 deletions
29
enterprise/chatbot_app/migrations/0004_remove_chat_messages_message_chat.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# Generated by Django 5.0.4 on 2024-04-21 08:37 | ||
|
||
import django.db.models.deletion | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("chatbot_app", "0003_chat_name"), | ||
] | ||
|
||
operations = [ | ||
migrations.RemoveField( | ||
model_name="chat", | ||
name="messages", | ||
), | ||
migrations.AddField( | ||
model_name="message", | ||
name="chat", | ||
field=models.ForeignKey( | ||
default=0, | ||
on_delete=django.db.models.deletion.CASCADE, | ||
related_name="messages", | ||
to="chatbot_app.chat", | ||
), | ||
preserve_default=False, | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
# Generated by Django 5.0.4 on 2024-04-21 08:58 | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("chatbot_app", "0004_remove_chat_messages_message_chat"), | ||
] | ||
|
||
operations = [ | ||
migrations.AlterField( | ||
model_name="chat", | ||
name="name", | ||
field=models.TextField(default="2024/04/21 00:00:00"), | ||
), | ||
] |
27 changes: 27 additions & 0 deletions
27
enterprise/chatbot_app/migrations/0006_chat_created_at_alter_chat_name.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
# Generated by Django 5.0.4 on 2024-04-21 09:02 | ||
|
||
import django.utils.timezone | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("chatbot_app", "0005_alter_chat_name"), | ||
] | ||
|
||
operations = [ | ||
migrations.AddField( | ||
model_name="chat", | ||
name="created_at", | ||
field=models.DateTimeField( | ||
auto_now_add=True, default=django.utils.timezone.now | ||
), | ||
preserve_default=False, | ||
), | ||
migrations.AlterField( | ||
model_name="chat", | ||
name="name", | ||
field=models.TextField(), | ||
), | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,17 @@ | ||
from django.db import models | ||
from datetime import datetime | ||
|
||
class Chat(models.Model): | ||
name = models.TextField() | ||
created_at = models.DateTimeField(auto_now_add=True) | ||
|
||
def save(self, *args, **kwargs): | ||
if not self.name: | ||
self.name = datetime.now().strftime("%Y/%m/%d %H:%M:%S") | ||
super(Chat, self).save(*args, **kwargs) | ||
|
||
class Message(models.Model): | ||
user_message = models.TextField() | ||
bot_message = models.TextField() | ||
timestamp = models.DateTimeField(auto_now_add=True) | ||
user_message = models.TextField() | ||
bot_message = models.TextField() | ||
timestamp = models.DateTimeField(auto_now_add=True) | ||
chat = models.ForeignKey(Chat, on_delete=models.CASCADE, related_name='messages') |
17 changes: 17 additions & 0 deletions
17
enterprise/chatbot_app/templates/_chat_container_inner.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
<div id="container"> | ||
{% include 'chat_select.html' %} {% include 'chatbox.html' %} | ||
|
||
<form | ||
hx-post="{% url 'chatbox_view' %}" | ||
hx-target="#chatbox" | ||
hx-swap="outerHTML" | ||
> | ||
{% csrf_token %} | ||
<input type="hidden" name="chat_id" value="{{ current_chat.id }}" /> | ||
<div class="my-indicator"></div> | ||
<div class="input-fields"> | ||
<input type="text" name="message" /> | ||
<button type="submit">Send</button> | ||
</div> | ||
</form> | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,65 +1,54 @@ | ||
<!DOCTYPE html> | ||
<html lang="en"> | ||
<head> | ||
<meta charset="UTF-8"> | ||
<head> | ||
<meta charset="UTF-8" /> | ||
<title>AI Chatbot</title> | ||
<script src="https://unpkg.com/[email protected]" integrity="sha384-zUfuhFKKZCbHTY6aRR46gxiqszMk5tcHjsVFxnUo8VMus4kHGVdIYVbOYYNlKmHV" crossorigin="anonymous"></script> | ||
<script | ||
src="https://unpkg.com/[email protected]" | ||
integrity="sha384-zUfuhFKKZCbHTY6aRR46gxiqszMk5tcHjsVFxnUo8VMus4kHGVdIYVbOYYNlKmHV" | ||
crossorigin="anonymous" | ||
></script> | ||
<style> | ||
.input-fields{ | ||
display: flex; | ||
flex-direction: row; | ||
} | ||
.input-fields { | ||
display: flex; | ||
flex-direction: row; | ||
} | ||
|
||
/* Style for the loading spinner */ | ||
.my-indicator { | ||
display: none; | ||
border: 2px solid #f3f3f3; | ||
border-top: 2px solid #3498db; | ||
border-radius: 50%; | ||
width: 20px; | ||
height: 20px; | ||
animation: spin .5s linear infinite; | ||
} | ||
.htmx-request .my-indicator { | ||
display: inline-block; | ||
} | ||
@keyframes spin { | ||
0% { transform: rotate(0deg); } | ||
100% { transform: rotate(360deg); } | ||
} | ||
.user-message{ | ||
color: #b83eff; | ||
padding: 5px; | ||
/* Style for the loading spinner */ | ||
.my-indicator { | ||
display: none; | ||
border: 2px solid #f3f3f3; | ||
border-top: 2px solid #3498db; | ||
border-radius: 50%; | ||
width: 20px; | ||
height: 20px; | ||
animation: spin 0.5s linear infinite; | ||
} | ||
.htmx-request .my-indicator { | ||
display: inline-block; | ||
} | ||
@keyframes spin { | ||
0% { | ||
transform: rotate(0deg); | ||
} | ||
.bot-message { | ||
padding: 5px; | ||
color: darkblue; | ||
100% { | ||
transform: rotate(360deg); | ||
} | ||
input[type=text] { | ||
width: 50%; | ||
} | ||
|
||
} | ||
.user-message { | ||
color: #b83eff; | ||
padding: 5px; | ||
} | ||
.bot-message { | ||
padding: 5px; | ||
color: darkblue; | ||
} | ||
input[type="text"] { | ||
width: 50%; | ||
} | ||
</style> | ||
</head> | ||
<body> | ||
<div id="container"> | ||
<div id="chatbox"> | ||
{% for message in messages %} | ||
<div>User: {{ message.user_message }}</div> | ||
<div>Bot: {{ message.bot_message }}</div> | ||
{% endfor %} | ||
</div> | ||
|
||
<form hx-post="{% url 'chat_view' %}" hx-target="#container" hx-swap="innerHTML" > | ||
{% csrf_token %} | ||
<div class="my-indicator"></div> | ||
<div class="input-fields"> | ||
<input type="text" name="message"> | ||
<button type="submit"> | ||
Send | ||
</button> | ||
</div> | ||
</form> | ||
</div> | ||
</body> | ||
</html> | ||
</head> | ||
<body> | ||
{% include 'chat_container.html' %} | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
{% include '_chat_container_inner.html' %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
<select name="chat_id" hx-get="{% url 'chat_select_view' %}" hx-target="#container"> | ||
{% for chat in chats %} | ||
<option value="{{ chat.id }}" {% if chat.id == current_chat.id %}selected{% endif %}>{{ chat.name }}</option> | ||
{% endfor %} | ||
</select> | ||
<form hx-post="{% url 'create_chat_view' %}" hx-target="#container"> | ||
{% csrf_token %} | ||
<button>Create Chat</button> | ||
</form> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<div id="chatbox"> | ||
{% for message in messages %} | ||
<div>User: {{ message.user_message }}</div> | ||
<div>Bot: {{ message.bot_message }}</div> | ||
{% endfor %} | ||
</div> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,14 @@ | ||
from django.urls import path | ||
from .views import chat_view | ||
from .views import ( | ||
chat_view, | ||
chatbox_view, | ||
create_chat_view, | ||
chat_select_view, | ||
) | ||
|
||
urlpatterns = [ | ||
path('', chat_view, name='chat_view'), | ||
] | ||
path("", chat_view, name="chat_view"), | ||
path("chatbox", chatbox_view, name="chatbox_view"), | ||
path("create_chat", create_chat_view, name="create_chat_view"), | ||
path("chat_select", chat_select_view, name="chat_select_view"), | ||
] |
Oops, something went wrong.