1+ #
2+ # // Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
3+ # // SPDX-License-Identifier: Apache-2.0
4+ #
5+ from dynaconf import Dynaconf
6+ from wraval .actions .data_utils import load_latest_dataset
7+ import pandas as pd
8+ from typing import Optional
9+
10+
11+ def show_examples (settings : Dynaconf , tone : Optional [str ] = None , n_examples : int = 3 ) -> None :
12+ """
13+ Load the latest dataset and display examples grouped by tone and model.
14+
15+ Args:
16+ settings: Dynaconf settings object with data_dir setting
17+ tone: Optional tone to filter by
18+ n_examples: Number of examples to show per tone-model combination
19+ """
20+ try :
21+ # Use settings.data_dir which could be either local path or S3 URI
22+ data_location = settings .data_dir
23+ print (f"Loading data from: { data_location } " )
24+ d = load_latest_dataset (data_location )
25+
26+ if tone and tone != "all" :
27+ if tone not in d ['tone' ].unique ():
28+ print (f"Error: Tone '{ tone } ' not found in dataset." )
29+ print (f"Available tones: { ', ' .join (d ['tone' ].unique ())} " )
30+ return
31+ d = d [d ['tone' ] == tone ]
32+ print (f"\n Examples for Tone: { tone } " )
33+ else :
34+ print ("\n Examples by Tone and Model:" )
35+
36+ # Get unique combinations of tone and inference_model
37+ combinations = d [['tone' , 'inference_model' ]].drop_duplicates ()
38+
39+ for _ , (tone , model ) in combinations .iterrows ():
40+ print ("\n " + "=" * 80 )
41+ print (f"Tone: { tone } | Model: { model } " )
42+ print ("=" * 80 )
43+
44+ # Get examples for this tone-model combination
45+ examples = d [(d ['tone' ] == tone ) & (d ['inference_model' ] == model )]
46+
47+ # Sample n_examples if we have more
48+ if len (examples ) > n_examples :
49+ examples = examples .sample (n = n_examples , random_state = 42 )
50+
51+ # Display each example
52+ for idx , row in examples .iterrows ():
53+ print (f"\n Example { idx + 1 } :" )
54+ print (f"Original: { row ['synthetic_data' ]} " )
55+ print (f"Rewrite: { row ['rewrite' ]} " )
56+ print (f"Score: { row ['overall_score' ]:.2f} " )
57+ print ("-" * 40 )
58+
59+ except FileNotFoundError as e :
60+ print (f"Error: { e } " )
61+ print ("Please generate and judge data first." )
62+ except KeyError as e :
63+ print (f"Error: Missing required column { e } . Please ensure the dataset has been properly judged." )
64+ except Exception as e :
65+ print (f"Unexpected error: { e } " )
0 commit comments