Skip to content

Commit f1b2848

Browse files
committed
add a show examples action
1 parent 86fb753 commit f1b2848

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed
Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
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"\nExamples for Tone: {tone}")
33+
else:
34+
print("\nExamples 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"\nExample {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}")

src/wraval/main.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
from wraval.actions.aws_utils import get_current_aws_account_id
1313
from wraval.actions.action_results import show_results
1414
from wraval.actions.action_deploy import deploy
15+
from wraval.actions.action_examples import show_examples
1516
import os
1617

1718

@@ -57,6 +58,7 @@ def parse_args() -> argparse.Namespace:
5758
"human_judge_upload",
5859
"human_judge_parsing",
5960
"show_results",
61+
"show_examples",
6062
"deploy"
6163
],
6264
help="Action to perform (generate data or run inference)",
@@ -124,6 +126,9 @@ def handle_judge(args, settings):
124126
def handle_show_results(args, settings):
125127
show_results(settings, args.type)
126128

129+
def handle_show_examples(args, settings):
130+
show_examples(settings, args.type)
131+
127132
def handle_deploy(settings):
128133
deploy(settings)
129134

@@ -140,6 +145,8 @@ def main():
140145
handle_judge(args, settings)
141146
case "show_results":
142147
handle_show_results(args, settings)
148+
case "show_examples":
149+
handle_show_examples(args, settings)
143150
case "deploy":
144151
handle_deploy(settings)
145152
case _:

0 commit comments

Comments
 (0)