|
18 | 18 | console = Console() |
19 | 19 |
|
20 | 20 | app = typer.Typer( |
21 | | - help="[green]Quotient CLI tool for managing artifacts and running evaluations[/green]", |
| 21 | + help="[green]Quotient CLI tool for managing artifacts.[/green]", |
22 | 22 | rich_markup_mode="rich", |
23 | 23 | no_args_is_help=True, |
24 | 24 | pretty_exceptions_show_locals=False, |
|
30 | 30 |
|
31 | 31 | app.add_typer(list_app, name="list") |
32 | 32 |
|
33 | | -########################### |
34 | | -# Models # |
35 | | -########################### |
36 | | - |
37 | | - |
38 | | -@list_app.command(name="models") |
39 | | -def list_models(): |
40 | | - """Command to get all models with optional filters.""" |
41 | | - try: |
42 | | - quotient = QuotientAI() |
43 | | - models = quotient.models.list() |
44 | | - console.print(models) |
45 | | - except QuotientAIError as e: |
46 | | - click.echo(str(e)) |
47 | | - |
48 | | - |
49 | | -########################### |
50 | | -# Prompts # |
51 | | -########################### |
52 | | - |
53 | | - |
54 | | -@list_app.command(name="prompts") |
55 | | -def list_prompts(): |
56 | | - """Command to get all prompts.""" |
57 | | - try: |
58 | | - quotient = QuotientAI() |
59 | | - prompts = quotient.prompts.list() |
60 | | - console.print(prompts) |
61 | | - except QuotientAIError as e: |
62 | | - click.echo(str(e)) |
63 | | - |
64 | | - |
65 | | -########################### |
66 | | -# Datasets # |
67 | | -########################### |
68 | | - |
69 | | - |
70 | | -@list_app.command(name="datasets") |
71 | | -def list_datasets(): |
72 | | - """Command to get all datasets.""" |
73 | | - try: |
74 | | - quotient = QuotientAI() |
75 | | - datasets = quotient.datasets.list() |
76 | | - console.print(datasets) |
77 | | - except QuotientAIError as e: |
78 | | - click.echo(str(e)) |
79 | | - |
80 | | - |
81 | | -############### |
82 | | -# Evaluations # |
83 | | -############### |
84 | | - |
85 | | -@app.command(name="run") |
86 | | -def run_evaluation( |
87 | | - file: Path = typer.Argument( |
88 | | - ..., |
89 | | - exists=True, |
90 | | - file_okay=True, |
91 | | - dir_okay=True, |
92 | | - help="Path to the evaluation file or directory to search in", |
93 | | - ), |
94 | | -): |
95 | | - """Command to run an evaluation""" |
96 | | - try: |
97 | | - # show an initial progress bar to indicate that we're kicking things off |
98 | | - with Live(refresh_per_second=4) as live: |
99 | | - quotient = QuotientAI() |
100 | | - |
101 | | - # Create a progress display focused on status rather than percentage |
102 | | - status_progress = Progress( |
103 | | - SpinnerColumn(), |
104 | | - TextColumn("[progress.description]{task.description}"), |
105 | | - TimeElapsedColumn(), |
106 | | - ) |
107 | | - |
108 | | - task = status_progress.add_task("Starting...", total=None) # No total needed |
109 | | - |
110 | | - panel_content = Panel( |
111 | | - "Initializing evaluation. Hold tight 🚀...", |
112 | | - title="Evaluation In Progress", |
113 | | - subtitle="QuotientAI", |
114 | | - expand=False, |
115 | | - ) |
116 | | - |
117 | | - layout = Group(panel_content, status_progress) |
118 | | - live.update(layout) |
119 | | - |
120 | | - # Kick off the actual evaluation |
121 | | - run = exec_evaluate(file) |
122 | | - # Actually fetch the current status from the run |
123 | | - current_status = run.status |
124 | | - |
125 | | - while True: # pragma: no cover |
126 | | - # testing these three conditions is NIGHTMARE NITGHTMARE NITGHTMARE |
127 | | - if current_status == "not-started": # pragma: no cover |
128 | | - status_desc = "Initializing evaluation..." |
129 | | - style = "yellow" |
130 | | - elif current_status == "running": # pragma: no cover |
131 | | - status_desc = "Processing evaluation..." |
132 | | - style = "blue" |
133 | | - elif current_status == "completed": # pragma: no cover |
134 | | - status_desc = "Evaluation complete!" |
135 | | - style = "green" |
136 | | - break |
137 | | - |
138 | | - status_progress.update(task, description=status_desc) |
139 | | - panel_content = Panel( |
140 | | - f"[{style}]{status_desc}[/{style}]\n\n" |
141 | | - f"Run ID: {run.id}\n" |
142 | | - f"Status: {current_status}", |
143 | | - title="Evaluation In Progress", |
144 | | - subtitle="QuotientAI", |
145 | | - expand=False, |
146 | | - ) |
147 | | - |
148 | | - layout = Group(panel_content, status_progress) |
149 | | - live.update(layout) |
150 | | - |
151 | | - # Fetch the current status from the run |
152 | | - time.sleep(1) |
153 | | - run = quotient.runs.get(run.id) |
154 | | - current_status = run.status |
155 | | - |
156 | | - # Generate the summary after completion |
157 | | - summary = run.summarize() |
158 | | - console.print() |
159 | | - console.print("Evaluation complete!") |
160 | | - console.print() |
161 | | - |
162 | | - # turn the summary into a table and print it |
163 | | - # print the metadata of the run |
164 | | - table = Table(title=f"Run: {summary['run_id']}", title_justify='left') |
165 | | - table.add_column("Key") |
166 | | - table.add_column("Value") |
167 | | - table.add_row("Run ID", summary["run_id"]) |
168 | | - table.add_row("Model", summary["model"]["name"]) |
169 | | - table.add_row("Parameters", str(summary["parameters"])) |
170 | | - table.add_row("Created At", str(summary["created_at"])) |
171 | | - console.print(table) |
172 | | - |
173 | | - table = Table(title="Evaluation Summary", title_justify='left') |
174 | | - table.add_column("Metric") |
175 | | - table.add_column("Average") |
176 | | - table.add_column("Std Dev") |
177 | | - for metric, values in summary["metrics"].items(): |
178 | | - table.add_row(metric, str(values["avg"]), str(values["stddev"])) |
179 | | - |
180 | | - console.print(table) |
181 | | - |
182 | | - except QuotientAIError as e: |
183 | | - raise |
184 | | - |
185 | | - |
186 | | -@list_app.command(name="runs") |
187 | | -def list_runs(): |
188 | | - """Command to get all runs.""" |
189 | | - try: |
190 | | - quotient = QuotientAI() |
191 | | - runs = quotient.runs.list() |
192 | | - console.print(runs) |
193 | | - except QuotientAIError as e: |
194 | | - raise |
195 | | - |
196 | | - |
197 | | -@list_app.command(name="metrics") |
198 | | -def list_metrics(): |
199 | | - """Command to get all available metrics.""" |
200 | | - try: |
201 | | - quotient = QuotientAI() |
202 | | - response = quotient.metrics.list() |
203 | | - console.print(response) |
204 | | - except QuotientAIError as e: |
205 | | - raise |
206 | | - |
207 | | - |
208 | 33 | MAX_LOGS = 10 |
209 | 34 |
|
210 | 35 | @list_app.command(name="logs") |
|
0 commit comments