Skip to content

Instantly share code, notes, and snippets.

@vwxyzjn
Last active July 30, 2024 17:12
Show Gist options
  • Save vwxyzjn/c1b8787f031bed31d75a321b574327d9 to your computer and use it in GitHub Desktop.
Save vwxyzjn/c1b8787f031bed31d75a321b574327d9 to your computer and use it in GitHub Desktop.
from typing import Dict, List
from rich.console import Console
from rich.panel import Panel
from datasets import load_dataset
def print_hf_messages(messages: List[Dict[str, str]]):
console = Console()
colors = ["red", "green"]
color_idx = 0
console.rule(f"[bold yellow]The number of turns is {len(messages)}")
for message in messages:
role = message["role"]
content = message["content"]
console.print(Panel(content, title_align="left", title=role, border_style=colors[color_idx]))
color_idx = (color_idx + 1) % 2
# Example usage
ds = load_dataset("allenai/tulu-v2-sft-mixture")
i = 0
while True:
print_hf_messages(ds["train"][i]["messages"])
i += 1
input("Press Enter to continue...")
@vwxyzjn
Copy link
Author

vwxyzjn commented Jul 30, 2024

image

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment