Historic messages model
Base
Bases: DeclarativeBase
Base class for SQLAlchemy models, defining default table configurations.
Attributes:
Name | Type | Description |
---|---|---|
__table_args__ |
dict
|
Specifies the default schema ('public') for all tables. |
Source code in api/models/historic_messages_model.py
9 10 11 12 13 14 15 16 17 18 |
|
MessageDB
Bases: Base
Represents an individual chat message stored in the database.
Attributes:
Name | Type | Description |
---|---|---|
__tablename__ |
str
|
The name of the database table ("message"). |
id |
int
|
The primary key identifier for the message. |
role |
str
|
The role of the sender (e.g., "human", "assistant", "system"). |
content |
str
|
The actual message content. |
message_history_id |
int
|
The foreign key linking this message to a chat history. |
message_history |
MessageHistoryDB
|
The associated chat history. |
Methods:
Name | Description |
---|---|
to_dict |
Converts the message into a dictionary format. |
Source code in api/models/historic_messages_model.py
81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 |
|
to_dict()
Converts the message into a dictionary format.
Returns:
Name | Type | Description |
---|---|---|
dict |
dict
|
A dictionary containing the |
Source code in api/models/historic_messages_model.py
114 115 116 117 118 119 120 121 122 |
|
MessageHistoryDB
Bases: Base
Represents a chat history stored in the database.
Attributes:
Name | Type | Description |
---|---|---|
__tablename__ |
str
|
The name of the database table ("message_history"). |
id |
int
|
The primary key identifier for the chat history. |
messages |
List[MessageDB]
|
A list of messages related to this chat history. |
Methods:
Name | Description |
---|---|
to_message_history |
Converts the database object into a |
to_list |
Converts the stored messages into a list of dictionaries. |
Source code in api/models/historic_messages_model.py
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 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 75 76 77 78 |
|
to_list()
Converts the stored messages into a list of dictionaries.
Returns:
Name | Type | Description |
---|---|---|
list |
list
|
A list containing message dictionaries with |
Source code in api/models/historic_messages_model.py
66 67 68 69 70 71 72 73 74 75 76 77 78 |
|
to_message_history()
Converts the stored messages into a MessageHistory
object.
Returns:
Name | Type | Description |
---|---|---|
MessageHistory |
MessageHistory
|
A |
Source code in api/models/historic_messages_model.py
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 |
|