mirror of
https://github.com/NousResearch/atropos.git
synced 2026-04-19 12:57:58 +00:00
fix: handle nested message format in jsonl2html.py (#308)
This commit is contained in:
parent
9f6681be95
commit
39f05d18fa
2 changed files with 157 additions and 1 deletions
|
|
@ -60,9 +60,31 @@ def create_html_for_group(group_data, index):
|
|||
|
||||
items_html = ""
|
||||
for i, (msg, score) in enumerate(zip(messages, scores)):
|
||||
# Handle both string and nested message formats
|
||||
if isinstance(msg, str):
|
||||
# Simple string format (original behavior)
|
||||
content = msg
|
||||
elif isinstance(msg, list):
|
||||
# Nested conversation format: List[Message] where Message is a dict
|
||||
# Format each message with its role
|
||||
parts = []
|
||||
for m in msg:
|
||||
if isinstance(m, dict):
|
||||
role = m.get("role", "unknown")
|
||||
content_text = m.get("content", "")
|
||||
parts.append(f"**{role.capitalize()}**: {content_text}")
|
||||
else:
|
||||
# Fallback for unexpected format
|
||||
parts.append(str(m))
|
||||
content = "\n\n".join(parts)
|
||||
else:
|
||||
# Fallback for any other type
|
||||
content = str(msg)
|
||||
|
||||
rendered_markdown = markdown.markdown(
|
||||
msg, extensions=["fenced_code", "tables", "nl2br"]
|
||||
content, extensions=["fenced_code", "tables", "nl2br"]
|
||||
)
|
||||
|
||||
score_class = get_score_class(score)
|
||||
item_id = f"group-{index}-item-{i}"
|
||||
items_html += textwrap.dedent(
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue