Last active
July 30, 2024 17:12
-
-
Save vwxyzjn/c1b8787f031bed31d75a321b574327d9 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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...") |
Author
vwxyzjn
commented
Jul 30, 2024

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