Skip to content

Commit c0e5006

Browse files
authored
Add trigger for metrics pipeline (#352)
* Add trigger for metrics pipeline * Add interactive script to calculate metrics * Enable triggering metrics calculating from the CLI * Output job status * Remove pytest-xdist and update lock file
1 parent 506355a commit c0e5006

File tree

5 files changed

+170
-660
lines changed

5 files changed

+170
-660
lines changed

cli/models.py

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
import click
2+
import questionary
23
from rich.console import Console
4+
from rich.pretty import pretty_repr
35
from rich.table import Column, Table
46

57
from cli.client import init_client
@@ -18,6 +20,47 @@ def models(ctx, web):
1820
launch_web_or_invoke("models", ctx, web, list_models)
1921

2022

23+
STRING_REPLACEMENTS = {
24+
"\\n": "\n",
25+
"\\t": "\t",
26+
'\\"': '"',
27+
}
28+
29+
30+
def json_string_to_string(s: str) -> str:
31+
for key, val in STRING_REPLACEMENTS.items():
32+
s = s.replace(key, val)
33+
return s
34+
35+
36+
@models.command("calculate-metrics")
37+
def metrics():
38+
client = init_client()
39+
models = client.models
40+
prompt_to_id = {f"{m.id}: {m.name}": m.id for m in models}
41+
ans = questionary.select(
42+
"What model do you want to run metrics for?",
43+
choices=list(prompt_to_id.keys()),
44+
).ask()
45+
model_id = prompt_to_id[ans]
46+
jobs = client.validate.metrics(model_id)
47+
console = Console()
48+
with console.status("Calculating metrics"):
49+
for job in jobs:
50+
job.sleep_until_complete(False)
51+
52+
if len(job.errors()) == 0:
53+
status = job.status()
54+
click.echo(click.style("Done", fg="green"))
55+
console.print(pretty_repr(status))
56+
else:
57+
click.echo(
58+
click.style("Encountered errors during running", fg="green")
59+
)
60+
for error in job.errors():
61+
click.echo(json_string_to_string(error))
62+
63+
2164
@models.command("list")
2265
def list_models():
2366
"""List your Models"""

nucleus/validate/client.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,14 @@ def evaluate_model_on_scenario_tests(
194194
)
195195
return AsyncJob.from_json(response, self.connection)
196196

197+
def metrics(self, model_id: str):
198+
response = self.connection.post(
199+
{},
200+
f"validate/{model_id}/metrics",
201+
)
202+
jobs = [AsyncJob.from_json(job, self.connection) for job in response]
203+
return jobs
204+
197205
def create_external_eval_function(
198206
self,
199207
name: str,

0 commit comments

Comments
 (0)