File size: 561 Bytes
a92f249 7c01a62 a92f249 7c01a62 a92f249 7c01a62 a92f249 0c31321 a92f249 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
from kani import Kani
class LogMessagesKani(Kani):
def __init__(self, engine, log_filepath: str = None, *args, **kwargs):
super().__init__(engine, *args, **kwargs)
self.log_filepath = log_filepath
async def add_to_history(self, message, *args, **kwargs):
await super().add_to_history(message, *args, **kwargs)
# Logs Message to File
if self.log_filepath:
with open(self.log_filepath, "a+") as log_file:
log_file.write(message.model_dump_json())
log_file.write("\n") |