message
ChatMessage
Bases: BaseModel
Represents a chat message with role, content, and metadata.
Attributes:
Name | Type | Description |
---|---|---|
role |
MessageRole
|
Message role (system/user/assistant/function) |
name |
Optional[str]
|
Optional name associated with the message |
content |
Optional[Any]
|
Main content of the message |
reasoning_content |
Optional[Any]
|
Internal reasoning information |
tool_calls |
Optional[List[ChatTool]]
|
List of tools called in this message |
additional_kwargs |
dict
|
Extra metadata dictionary |
time_created |
datetime
|
Timestamp of message creation |
Source code in rm_gallery/core/model/message.py
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 79 80 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 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
|
__add__(other)
Concatenates message content with another message delta.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other
|
Any
|
Message to merge with current one |
required |
Returns:
Type | Description |
---|---|
ChatMessage
|
New ChatMessage instance with merged content |
Raises:
Type | Description |
---|---|
TypeError
|
If other is not None or ChatMessage |
Source code in rm_gallery/core/model/message.py
61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
|
__str__()
Returns formatted string representation with timestamp and role.
Source code in rm_gallery/core/model/message.py
57 58 59 |
|
convert_from_strings(messages, system_message)
staticmethod
Converts string list to structured ChatMessage list for debugging.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
messages
|
List[str]
|
List of alternating user/assistant messages |
required |
system_message
|
str
|
Initial system message content |
required |
Returns:
Type | Description |
---|---|
str
|
List of structured ChatMessage objects |
Source code in rm_gallery/core/model/message.py
91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 |
|
convert_to_strings(messages)
staticmethod
Converts structured ChatMessages to plain strings for debugging.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
messages
|
List[ChatMessage]
|
List of ChatMessage objects |
required |
Returns:
Type | Description |
---|---|
List[str]
|
Tuple containing: |
str
|
|
Tuple[List[str], str]
|
|
Source code in rm_gallery/core/model/message.py
115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 |
|
ChatResponse
Bases: BaseModel
Represents a chat response with message and metadata.
Attributes:
Name | Type | Description |
---|---|---|
message |
ChatMessage
|
Main chat message content |
raw |
Optional[dict]
|
Raw response dictionary from API |
delta |
Optional[ChatMessage]
|
Incremental update message |
error_message |
Optional[str]
|
Error description if any |
additional_kwargs |
dict
|
Extra metadata dictionary |
Source code in rm_gallery/core/model/message.py
140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
|
__add__(other)
Combines response with another response delta.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
other
|
Any
|
Response to merge with current one |
required |
Returns:
Type | Description |
---|---|
ChatResponse
|
New ChatResponse instance with merged content |
Raises:
Type | Description |
---|---|
TypeError
|
If other is not None or ChatResponse |
Source code in rm_gallery/core/model/message.py
167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 |
|
__str__()
Returns error message if present, otherwise string representation of main message.
Source code in rm_gallery/core/model/message.py
160 161 162 163 164 165 |
|
ChatTool
Bases: BaseModel
Represents a chat tool call with function metadata.
Source code in rm_gallery/core/model/message.py
24 25 26 27 28 29 |
|
MessageRole
Bases: str
, Enum
Message role.
Source code in rm_gallery/core/model/message.py
8 9 10 11 12 13 14 |
|
Tool
Bases: BaseModel
Represents a function tool with name and arguments.
Source code in rm_gallery/core/model/message.py
17 18 19 20 21 |
|
format_messages(messages)
Formats chat messages into XML-style string representation.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
messages
|
List[ChatMessage]
|
List of ChatMessage objects to format |
required |
Returns:
Type | Description |
---|---|
str
|
String with messages wrapped in role-specific tags |
Source code in rm_gallery/core/model/message.py
201 202 203 204 205 206 207 208 209 210 211 212 213 |
|