django_ai_assistant.models¶
Thread
¶
Bases: Model
Thread model. A thread is a collection of messages between a user and the AI assistant. Also called conversation or session.
Source code in django_ai_assistant/models.py
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
|
name = models.CharField(max_length=255, blank=True)
class-attribute
instance-attribute
¶
Name of the thread. Can be blank.
created_by = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.SET_NULL, related_name='ai_assistant_threads', null=True)
class-attribute
instance-attribute
¶
User who created the thread. Can be null. Set to null/None when user is deleted.
created_at = models.DateTimeField(auto_now_add=True)
class-attribute
instance-attribute
¶
Date and time when the thread was created. Automatically set when the thread is created.
updated_at = models.DateTimeField(auto_now=True)
class-attribute
instance-attribute
¶
Date and time when the thread was last updated. Automatically set when the thread is updated.
__str__()
¶
Return the name of the thread as the string representation of the thread.
Source code in django_ai_assistant/models.py
36 37 38 |
|
__repr__()
¶
Return the string representation of the thread like '
Source code in django_ai_assistant/models.py
40 41 42 |
|
Message
¶
Bases: Model
Message model. A message is a text that is part of a thread. A message can be sent by a user or the AI assistant.
The message data is stored as a JSON field called message
.
Source code in django_ai_assistant/models.py
45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
|
thread = models.ForeignKey(Thread, on_delete=models.CASCADE, related_name='messages')
class-attribute
instance-attribute
¶
Thread to which the message belongs.
message = models.JSONField()
class-attribute
instance-attribute
¶
Message content. This is a serialized Langchain BaseMessage
that was serialized
with message_to_dict
and can be deserialized with messages_from_dict
.
created_at = models.DateTimeField(auto_now_add=True)
class-attribute
instance-attribute
¶
Date and time when the message was created. Automatically set when the message is created.
__str__()
¶
Return internal message data from message
attribute
as the string representation of the message.
Source code in django_ai_assistant/models.py
67 68 69 70 |
|
__repr__()
¶
Return the string representation of the message like '
Source code in django_ai_assistant/models.py
72 73 74 |
|