Skip to content

Commit

Permalink
Fix logging for alternative message structure
Browse files Browse the repository at this point in the history
  • Loading branch information
njbbaer committed Aug 21, 2024
1 parent bce3d1d commit aadd91f
Showing 1 changed file with 10 additions and 8 deletions.
18 changes: 10 additions & 8 deletions src/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -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),
}
],
Expand All @@ -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

0 comments on commit aadd91f

Please sign in to comment.