diff --git a/src/logger.py b/src/logger.py index 16260b1..9bea914 100644 --- a/src/logger.py +++ b/src/logger.py @@ -17,7 +17,7 @@ def log(self, parameters, content, response): { "timestamp": self._current_timestamp(), "parameters": parameters, - "content": self._format_content(content), + "content": self._format_text(content), "response": LiteralScalarString(response), } ], @@ -31,11 +31,13 @@ def _current_timestamp(): return datetime.now().strftime("%Y-%m-%d %H:%M:%S") @staticmethod - def _format_content(content): - if isinstance(content, list): - return [ - {**msg, "content": LiteralScalarString(msg["content"])} - for msg in content - ] + def _format_text(data): + if isinstance(data, dict): + return { + k: LiteralScalarString(v) if k == "text" else Logger._format_text(v) + for k, v in data.items() + } + elif isinstance(data, list): + return [Logger._format_text(item) for item in data] else: - return LiteralScalarString(content) + return data