nufi-python 1.0.0__py3-none-any.whl
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- nufi/__init__.py +52 -0
- nufi/auth.py +364 -0
- nufi/cli/__init__.py +0 -0
- nufi/cli/commands/__init__.py +1 -0
- nufi/cli/commands/auth.py +113 -0
- nufi/cli/commands/common.py +198 -0
- nufi/cli/commands/compiles.py +507 -0
- nufi/cli/commands/custom_evaluation_templates.py +206 -0
- nufi/cli/commands/datasets.py +697 -0
- nufi/cli/commands/evaluations.py +854 -0
- nufi/cli/commands/leaderboards.py +763 -0
- nufi/cli/commands/models.py +1347 -0
- nufi/cli/commands/monitoring.py +350 -0
- nufi/cli/commands/profile.py +123 -0
- nufi/cli/commands/projects.py +308 -0
- nufi/cli/commands/servings.py +306 -0
- nufi/cli/main.py +66 -0
- nufi/client.py +103 -0
- nufi/config.py +281 -0
- nufi/evaluator.py +559 -0
- nufi/exceptions.py +58 -0
- nufi/http_utils.py +51 -0
- nufi/models/__init__.py +185 -0
- nufi/models/compiles.py +79 -0
- nufi/models/custom_evaluation_templates.py +111 -0
- nufi/models/datasets.py +94 -0
- nufi/models/evaluations.py +253 -0
- nufi/models/leaderboards.py +178 -0
- nufi/models/monitoring.py +179 -0
- nufi/models/pagination.py +33 -0
- nufi/models/projects.py +32 -0
- nufi/models/registry.py +138 -0
- nufi/models/servings.py +27 -0
- nufi/py.typed +1 -0
- nufi/resources/__init__.py +34 -0
- nufi/resources/base.py +190 -0
- nufi/resources/compiles.py +193 -0
- nufi/resources/custom_evaluation_templates.py +126 -0
- nufi/resources/datasets.py +786 -0
- nufi/resources/evaluations.py +428 -0
- nufi/resources/leaderboards.py +413 -0
- nufi/resources/models.py +726 -0
- nufi/resources/monitoring.py +82 -0
- nufi/resources/projects.py +114 -0
- nufi/resources/servings.py +80 -0
- nufi/transport.py +248 -0
- nufi_python-1.0.0.dist-info/METADATA +228 -0
- nufi_python-1.0.0.dist-info/RECORD +52 -0
- nufi_python-1.0.0.dist-info/WHEEL +5 -0
- nufi_python-1.0.0.dist-info/entry_points.txt +2 -0
- nufi_python-1.0.0.dist-info/licenses/LICENSE +21 -0
- nufi_python-1.0.0.dist-info/top_level.txt +1 -0
|
@@ -0,0 +1,206 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from collections.abc import Iterator
|
|
4
|
+
from contextlib import contextmanager
|
|
5
|
+
from pathlib import Path
|
|
6
|
+
from typing import Annotated, Any
|
|
7
|
+
|
|
8
|
+
import typer
|
|
9
|
+
from rich.markup import escape
|
|
10
|
+
|
|
11
|
+
from nufi.cli.commands import common
|
|
12
|
+
from nufi.resources import CustomEvaluationTemplatesResource
|
|
13
|
+
|
|
14
|
+
app = typer.Typer(
|
|
15
|
+
help="Manage Evaluation Templates.",
|
|
16
|
+
invoke_without_command=True,
|
|
17
|
+
context_settings=common.CONTEXT_SETTINGS,
|
|
18
|
+
)
|
|
19
|
+
|
|
20
|
+
Project = Annotated[
|
|
21
|
+
str | None,
|
|
22
|
+
typer.Option("--project", help="Project name.", show_default=False),
|
|
23
|
+
]
|
|
24
|
+
ProjectID = Annotated[
|
|
25
|
+
int | None,
|
|
26
|
+
typer.Option("--project-id", min=1, help="Project ID.", show_default=False),
|
|
27
|
+
]
|
|
28
|
+
Profile = Annotated[str | None, typer.Option("--profile", help="Profile name.")]
|
|
29
|
+
Output = Annotated[
|
|
30
|
+
common.OutputChoice,
|
|
31
|
+
typer.Option("--output", help="Output format."),
|
|
32
|
+
]
|
|
33
|
+
Verbose = Annotated[bool, typer.Option("--verbose", help="Show detailed errors.")]
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
@app.callback()
|
|
37
|
+
def evaluation_templates(ctx: typer.Context):
|
|
38
|
+
common.show_help_if_no_subcommand(ctx)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
@contextmanager
|
|
42
|
+
def _resource(profile_name: str | None) -> Iterator[CustomEvaluationTemplatesResource]:
|
|
43
|
+
client = common.make_client(profile_name)
|
|
44
|
+
try:
|
|
45
|
+
yield client.evaluations.templates
|
|
46
|
+
finally:
|
|
47
|
+
client.close()
|
|
48
|
+
|
|
49
|
+
|
|
50
|
+
def _project(
|
|
51
|
+
project: str | None, project_id: int | None, profile_name: str | None
|
|
52
|
+
) -> str | int:
|
|
53
|
+
return common.resolve_cli_project(project, project_id, profile_name=profile_name)
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
def _print_template(template: Any) -> None:
|
|
57
|
+
common.print_table(
|
|
58
|
+
["Field", "Value"],
|
|
59
|
+
[
|
|
60
|
+
["ID", template.id],
|
|
61
|
+
["Name", template.name],
|
|
62
|
+
["Version", template.version],
|
|
63
|
+
["Display Name", template.display_name],
|
|
64
|
+
["Image", template.image],
|
|
65
|
+
["Image Policy", template.image_policy],
|
|
66
|
+
["Image Pull Secrets", ", ".join(template.image_pull_secrets)],
|
|
67
|
+
["Archived", str(template.archived_at is not None).lower()],
|
|
68
|
+
],
|
|
69
|
+
)
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
@app.command("register")
|
|
73
|
+
def register_template(
|
|
74
|
+
file: Annotated[
|
|
75
|
+
Path, typer.Option("--file", help="YAML or JSON registration file.")
|
|
76
|
+
],
|
|
77
|
+
project: Project = None,
|
|
78
|
+
project_id: ProjectID = None,
|
|
79
|
+
profile_name: Profile = None,
|
|
80
|
+
output: Output = common.OutputChoice.table,
|
|
81
|
+
verbose: Verbose = False,
|
|
82
|
+
):
|
|
83
|
+
try:
|
|
84
|
+
selected = _project(project, project_id, profile_name)
|
|
85
|
+
with _resource(profile_name) as resource:
|
|
86
|
+
result = resource.register_file(file, project=selected)
|
|
87
|
+
except Exception as exc:
|
|
88
|
+
common.handle_cli_error(exc, verbose=verbose)
|
|
89
|
+
if result.image_policy == "mutable":
|
|
90
|
+
common.error_console.print(
|
|
91
|
+
"[yellow]Warning:[/] this image reference is mutable; different content "
|
|
92
|
+
"may run across Runs."
|
|
93
|
+
)
|
|
94
|
+
if output == common.OutputChoice.json:
|
|
95
|
+
common.print_json(result)
|
|
96
|
+
return
|
|
97
|
+
_print_template(result)
|
|
98
|
+
|
|
99
|
+
|
|
100
|
+
@app.command("list")
|
|
101
|
+
def list_templates(
|
|
102
|
+
archived: Annotated[
|
|
103
|
+
str | None,
|
|
104
|
+
typer.Option("--archived", help="Filter by true or false.", show_default=False),
|
|
105
|
+
] = None,
|
|
106
|
+
project: Project = None,
|
|
107
|
+
project_id: ProjectID = None,
|
|
108
|
+
profile_name: Profile = None,
|
|
109
|
+
output: Output = common.OutputChoice.table,
|
|
110
|
+
verbose: Verbose = False,
|
|
111
|
+
):
|
|
112
|
+
try:
|
|
113
|
+
selected = _project(project, project_id, profile_name)
|
|
114
|
+
archived_value = None
|
|
115
|
+
if archived is not None:
|
|
116
|
+
if archived.lower() not in {"true", "false"}:
|
|
117
|
+
raise typer.BadParameter("--archived must be true or false.")
|
|
118
|
+
archived_value = archived.lower() == "true"
|
|
119
|
+
with _resource(profile_name) as resource:
|
|
120
|
+
result = resource.list(project=selected, archived=archived_value)
|
|
121
|
+
except Exception as exc:
|
|
122
|
+
common.handle_cli_error(exc, verbose=verbose)
|
|
123
|
+
if output == common.OutputChoice.json:
|
|
124
|
+
common.print_json(result)
|
|
125
|
+
return
|
|
126
|
+
common.print_table(
|
|
127
|
+
["ID", "Name", "Version", "Display Name", "Image Policy", "Archived"],
|
|
128
|
+
[
|
|
129
|
+
[
|
|
130
|
+
item.id,
|
|
131
|
+
item.name,
|
|
132
|
+
item.version,
|
|
133
|
+
item.display_name,
|
|
134
|
+
item.image_policy,
|
|
135
|
+
str(item.archived_at is not None).lower(),
|
|
136
|
+
]
|
|
137
|
+
for item in result
|
|
138
|
+
],
|
|
139
|
+
)
|
|
140
|
+
|
|
141
|
+
|
|
142
|
+
@app.command("get")
|
|
143
|
+
def get_template(
|
|
144
|
+
template_id: Annotated[str, typer.Argument(help="Custom template UUID.")],
|
|
145
|
+
project: Project = None,
|
|
146
|
+
project_id: ProjectID = None,
|
|
147
|
+
profile_name: Profile = None,
|
|
148
|
+
output: Output = common.OutputChoice.table,
|
|
149
|
+
verbose: Verbose = False,
|
|
150
|
+
):
|
|
151
|
+
try:
|
|
152
|
+
with _resource(profile_name) as resource:
|
|
153
|
+
result = resource.get(
|
|
154
|
+
template_id, project=_project(project, project_id, profile_name)
|
|
155
|
+
)
|
|
156
|
+
except Exception as exc:
|
|
157
|
+
common.handle_cli_error(exc, verbose=verbose)
|
|
158
|
+
if output == common.OutputChoice.json:
|
|
159
|
+
common.print_json(result)
|
|
160
|
+
return
|
|
161
|
+
_print_template(result)
|
|
162
|
+
|
|
163
|
+
|
|
164
|
+
@app.command("archive")
|
|
165
|
+
def archive_template(
|
|
166
|
+
template_id: Annotated[str, typer.Argument(help="Custom template UUID.")],
|
|
167
|
+
project: Project = None,
|
|
168
|
+
project_id: ProjectID = None,
|
|
169
|
+
profile_name: Profile = None,
|
|
170
|
+
yes: Annotated[bool, typer.Option("--yes", help="Skip confirmation.")] = False,
|
|
171
|
+
verbose: Verbose = False,
|
|
172
|
+
):
|
|
173
|
+
try:
|
|
174
|
+
if not yes and not typer.confirm(f"Archive custom template '{template_id}'?"):
|
|
175
|
+
raise typer.Exit()
|
|
176
|
+
with _resource(profile_name) as resource:
|
|
177
|
+
resource.archive(
|
|
178
|
+
template_id, project=_project(project, project_id, profile_name)
|
|
179
|
+
)
|
|
180
|
+
except typer.Exit:
|
|
181
|
+
raise
|
|
182
|
+
except Exception as exc:
|
|
183
|
+
common.handle_cli_error(exc, verbose=verbose)
|
|
184
|
+
common.console.print(
|
|
185
|
+
f"[bold green]Custom template archived:[/] {escape(template_id)}"
|
|
186
|
+
)
|
|
187
|
+
|
|
188
|
+
|
|
189
|
+
@app.command("restore")
|
|
190
|
+
def restore_template(
|
|
191
|
+
template_id: Annotated[str, typer.Argument(help="Custom template UUID.")],
|
|
192
|
+
project: Project = None,
|
|
193
|
+
project_id: ProjectID = None,
|
|
194
|
+
profile_name: Profile = None,
|
|
195
|
+
verbose: Verbose = False,
|
|
196
|
+
):
|
|
197
|
+
try:
|
|
198
|
+
with _resource(profile_name) as resource:
|
|
199
|
+
resource.restore(
|
|
200
|
+
template_id, project=_project(project, project_id, profile_name)
|
|
201
|
+
)
|
|
202
|
+
except Exception as exc:
|
|
203
|
+
common.handle_cli_error(exc, verbose=verbose)
|
|
204
|
+
common.console.print(
|
|
205
|
+
f"[bold green]Custom template restored:[/] {escape(template_id)}"
|
|
206
|
+
)
|