Appends a new message to the chat history. Args: langchain_msg (AIMessage | HumanMessage): The message content (either an AI or Human message). metadata (dict[str, Any], optional): Additional metadata related to the message. Defaults to an empty dictionary.
(
self, langchain_msg: AIMessage | HumanMessage, metadata: dict[str, Any] = {}
)
| 48 | return len(self._msgs) |
| 49 | |
| 50 | def append( |
| 51 | self, langchain_msg: AIMessage | HumanMessage, metadata: dict[str, Any] = {} |
| 52 | ): |
| 53 | """ |
| 54 | Appends a new message to the chat history. |
| 55 | |
| 56 | Args: |
| 57 | langchain_msg (AIMessage | HumanMessage): The message content (either an AI or Human message). |
| 58 | metadata (dict[str, Any], optional): Additional metadata related to the message. Defaults to an empty dictionary. |
| 59 | """ |
| 60 | chat_msg = ChatMessage( |
| 61 | chat_id=self.id, |
| 62 | message_id=uuid4(), |
| 63 | brain_id=self.brain_id, |
| 64 | msg=langchain_msg, |
| 65 | message_time=datetime.now(), |
| 66 | metadata=metadata, |
| 67 | ) |
| 68 | self._msgs.append(chat_msg) |
| 69 | |
| 70 | def iter_pairs(self) -> Generator[Tuple[HumanMessage, AIMessage], None, None]: |
| 71 | """ |