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,308 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import typer
|
|
4
|
+
|
|
5
|
+
from nufi.cli.commands import common
|
|
6
|
+
from nufi import config
|
|
7
|
+
|
|
8
|
+
app = typer.Typer(
|
|
9
|
+
help="Manage NuFi projects.",
|
|
10
|
+
invoke_without_command=True,
|
|
11
|
+
context_settings=common.CONTEXT_SETTINGS,
|
|
12
|
+
)
|
|
13
|
+
token_app = typer.Typer(
|
|
14
|
+
help="Manage project access tokens.",
|
|
15
|
+
invoke_without_command=True,
|
|
16
|
+
context_settings=common.CONTEXT_SETTINGS,
|
|
17
|
+
)
|
|
18
|
+
app.add_typer(token_app, name="token")
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
@app.callback()
|
|
22
|
+
def projects(ctx: typer.Context):
|
|
23
|
+
common.show_help_if_no_subcommand(ctx)
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
@token_app.callback()
|
|
27
|
+
def project_tokens(ctx: typer.Context):
|
|
28
|
+
common.show_help_if_no_subcommand(ctx)
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
@token_app.command("create")
|
|
32
|
+
def create_project_token(
|
|
33
|
+
name: str = typer.Argument(..., help="Token display name."),
|
|
34
|
+
project: str | None = typer.Option(
|
|
35
|
+
None,
|
|
36
|
+
"--project",
|
|
37
|
+
help="Project name or ID.",
|
|
38
|
+
show_default=False,
|
|
39
|
+
),
|
|
40
|
+
expires_in_days: int = typer.Option(
|
|
41
|
+
90,
|
|
42
|
+
"--expires-in-days",
|
|
43
|
+
min=1,
|
|
44
|
+
max=365,
|
|
45
|
+
help="Token lifetime in days.",
|
|
46
|
+
),
|
|
47
|
+
profile_name: str | None = typer.Option(None, "--profile", help="Profile name."),
|
|
48
|
+
output: common.OutputChoice = typer.Option(
|
|
49
|
+
common.OutputChoice.table,
|
|
50
|
+
"--output",
|
|
51
|
+
help="Output format.",
|
|
52
|
+
),
|
|
53
|
+
verbose: bool = typer.Option(False, "--verbose", help="Show detailed errors."),
|
|
54
|
+
):
|
|
55
|
+
client = None
|
|
56
|
+
try:
|
|
57
|
+
resolved_project = common.resolve_cli_project(
|
|
58
|
+
project,
|
|
59
|
+
None,
|
|
60
|
+
profile_name=profile_name,
|
|
61
|
+
)
|
|
62
|
+
client = common.make_profile_client(profile_name)
|
|
63
|
+
created = client.projects.tokens.create(
|
|
64
|
+
name,
|
|
65
|
+
project=resolved_project,
|
|
66
|
+
expires_in_days=expires_in_days,
|
|
67
|
+
)
|
|
68
|
+
except Exception as exc:
|
|
69
|
+
common.handle_cli_error(exc, verbose=verbose)
|
|
70
|
+
finally:
|
|
71
|
+
if client is not None:
|
|
72
|
+
client.close()
|
|
73
|
+
|
|
74
|
+
if output == common.OutputChoice.json:
|
|
75
|
+
common.print_json(created)
|
|
76
|
+
return
|
|
77
|
+
common.print_table(
|
|
78
|
+
["ID", "Name", "Expires", "Status"],
|
|
79
|
+
[
|
|
80
|
+
[
|
|
81
|
+
created.id,
|
|
82
|
+
created.name,
|
|
83
|
+
created.expires_at.isoformat(),
|
|
84
|
+
created.status,
|
|
85
|
+
]
|
|
86
|
+
],
|
|
87
|
+
)
|
|
88
|
+
common.console.print(
|
|
89
|
+
f"Token: {created.token}",
|
|
90
|
+
markup=False,
|
|
91
|
+
soft_wrap=True,
|
|
92
|
+
)
|
|
93
|
+
|
|
94
|
+
|
|
95
|
+
@token_app.command("list")
|
|
96
|
+
def list_project_tokens(
|
|
97
|
+
project: str | None = typer.Option(
|
|
98
|
+
None,
|
|
99
|
+
"--project",
|
|
100
|
+
help="Project name or ID.",
|
|
101
|
+
show_default=False,
|
|
102
|
+
),
|
|
103
|
+
profile_name: str | None = typer.Option(None, "--profile", help="Profile name."),
|
|
104
|
+
output: common.OutputChoice = typer.Option(
|
|
105
|
+
common.OutputChoice.table,
|
|
106
|
+
"--output",
|
|
107
|
+
help="Output format.",
|
|
108
|
+
),
|
|
109
|
+
verbose: bool = typer.Option(False, "--verbose", help="Show detailed errors."),
|
|
110
|
+
):
|
|
111
|
+
client = None
|
|
112
|
+
try:
|
|
113
|
+
resolved_project = common.resolve_cli_project(
|
|
114
|
+
project,
|
|
115
|
+
None,
|
|
116
|
+
profile_name=profile_name,
|
|
117
|
+
)
|
|
118
|
+
client = common.make_profile_client(profile_name)
|
|
119
|
+
tokens = client.projects.tokens.list(project=resolved_project)
|
|
120
|
+
except Exception as exc:
|
|
121
|
+
common.handle_cli_error(exc, verbose=verbose)
|
|
122
|
+
finally:
|
|
123
|
+
if client is not None:
|
|
124
|
+
client.close()
|
|
125
|
+
|
|
126
|
+
if output == common.OutputChoice.json:
|
|
127
|
+
common.print_json(tokens)
|
|
128
|
+
return
|
|
129
|
+
common.print_table(
|
|
130
|
+
["ID", "Name", "Creator", "Created", "Expires", "Status", "Revoked"],
|
|
131
|
+
[
|
|
132
|
+
[
|
|
133
|
+
token.id,
|
|
134
|
+
token.name,
|
|
135
|
+
token.created_by_name,
|
|
136
|
+
token.created_at.isoformat(),
|
|
137
|
+
token.expires_at.isoformat(),
|
|
138
|
+
token.status,
|
|
139
|
+
token.revoked_at.isoformat() if token.revoked_at else "-",
|
|
140
|
+
]
|
|
141
|
+
for token in tokens
|
|
142
|
+
],
|
|
143
|
+
)
|
|
144
|
+
|
|
145
|
+
|
|
146
|
+
@token_app.command("revoke")
|
|
147
|
+
def revoke_project_token(
|
|
148
|
+
token: str = typer.Argument(..., help="Token name or ID."),
|
|
149
|
+
project: str | None = typer.Option(
|
|
150
|
+
None,
|
|
151
|
+
"--project",
|
|
152
|
+
help="Project name or ID.",
|
|
153
|
+
show_default=False,
|
|
154
|
+
),
|
|
155
|
+
profile_name: str | None = typer.Option(None, "--profile", help="Profile name."),
|
|
156
|
+
yes: bool = typer.Option(False, "--yes", help="Skip revoke confirmation."),
|
|
157
|
+
verbose: bool = typer.Option(False, "--verbose", help="Show detailed errors."),
|
|
158
|
+
):
|
|
159
|
+
client = None
|
|
160
|
+
try:
|
|
161
|
+
resolved_project = common.resolve_cli_project(
|
|
162
|
+
project,
|
|
163
|
+
None,
|
|
164
|
+
profile_name=profile_name,
|
|
165
|
+
)
|
|
166
|
+
client = common.make_profile_client(profile_name)
|
|
167
|
+
target = common.resolve_named_resource(
|
|
168
|
+
client.projects.tokens.list(project=resolved_project),
|
|
169
|
+
token,
|
|
170
|
+
resource="project access token",
|
|
171
|
+
)
|
|
172
|
+
if not yes and not typer.confirm(
|
|
173
|
+
f"Revoke project access token '{target.name}' ({target.id}) "
|
|
174
|
+
f"from '{resolved_project}'?",
|
|
175
|
+
default=False,
|
|
176
|
+
):
|
|
177
|
+
common.console.print("Aborted.")
|
|
178
|
+
return
|
|
179
|
+
client.projects.tokens.revoke(target.id, project=resolved_project)
|
|
180
|
+
except Exception as exc:
|
|
181
|
+
common.handle_cli_error(exc, verbose=verbose)
|
|
182
|
+
finally:
|
|
183
|
+
if client is not None:
|
|
184
|
+
client.close()
|
|
185
|
+
common.console.print(f"[bold green]Project access token revoked:[/] {target.id}")
|
|
186
|
+
|
|
187
|
+
|
|
188
|
+
@app.command("list")
|
|
189
|
+
def list_projects(
|
|
190
|
+
profile_name: str | None = typer.Option(None, "--profile", help="Profile name."),
|
|
191
|
+
output: common.OutputChoice = typer.Option(
|
|
192
|
+
common.OutputChoice.table,
|
|
193
|
+
"--output",
|
|
194
|
+
help="Output format.",
|
|
195
|
+
),
|
|
196
|
+
verbose: bool = typer.Option(False, "--verbose", help="Show detailed errors."),
|
|
197
|
+
):
|
|
198
|
+
client = None
|
|
199
|
+
try:
|
|
200
|
+
client = common.make_client(profile_name)
|
|
201
|
+
projects = client.projects.list()
|
|
202
|
+
except Exception as exc:
|
|
203
|
+
common.handle_cli_error(exc, verbose=verbose)
|
|
204
|
+
finally:
|
|
205
|
+
if client is not None:
|
|
206
|
+
client.close()
|
|
207
|
+
|
|
208
|
+
if output == common.OutputChoice.json:
|
|
209
|
+
common.print_json(projects)
|
|
210
|
+
return
|
|
211
|
+
|
|
212
|
+
common.print_table(
|
|
213
|
+
["ID", "Name", "Created"],
|
|
214
|
+
[
|
|
215
|
+
[str(project.id), project.name, str(project.created_at)]
|
|
216
|
+
for project in projects
|
|
217
|
+
],
|
|
218
|
+
)
|
|
219
|
+
|
|
220
|
+
|
|
221
|
+
@app.command("create")
|
|
222
|
+
def create_project(
|
|
223
|
+
name: str = typer.Argument(..., help="Project name."),
|
|
224
|
+
profile_name: str | None = typer.Option(None, "--profile", help="Profile name."),
|
|
225
|
+
verbose: bool = typer.Option(False, "--verbose", help="Show detailed errors."),
|
|
226
|
+
):
|
|
227
|
+
client = None
|
|
228
|
+
try:
|
|
229
|
+
client = common.make_client(profile_name)
|
|
230
|
+
project = client.projects.create(name)
|
|
231
|
+
except Exception as exc:
|
|
232
|
+
common.handle_cli_error(exc, verbose=verbose)
|
|
233
|
+
finally:
|
|
234
|
+
if client is not None:
|
|
235
|
+
client.close()
|
|
236
|
+
|
|
237
|
+
common.console.print(f"[bold green]Project created:[/] {project.name}")
|
|
238
|
+
|
|
239
|
+
|
|
240
|
+
@app.command("use")
|
|
241
|
+
def use_project(
|
|
242
|
+
project: str = typer.Argument(..., help="Project name or ID."),
|
|
243
|
+
profile_name: str | None = typer.Option(None, "--profile", help="Profile name."),
|
|
244
|
+
):
|
|
245
|
+
client = None
|
|
246
|
+
try:
|
|
247
|
+
client = common.make_client(profile_name)
|
|
248
|
+
resolved = client.projects.resolve(project)
|
|
249
|
+
config.use_project(resolved.name, profile_name=profile_name)
|
|
250
|
+
except Exception as exc:
|
|
251
|
+
common.handle_cli_error(exc, verbose=False)
|
|
252
|
+
finally:
|
|
253
|
+
if client is not None:
|
|
254
|
+
client.close()
|
|
255
|
+
common.console.print(f"[bold green]Active project:[/] {resolved.name}")
|
|
256
|
+
|
|
257
|
+
|
|
258
|
+
@app.command("current")
|
|
259
|
+
def current_project(
|
|
260
|
+
profile_name: str | None = typer.Option(None, "--profile", help="Profile name."),
|
|
261
|
+
):
|
|
262
|
+
try:
|
|
263
|
+
project = config.resolve_project(None, profile_name=profile_name)
|
|
264
|
+
except Exception as exc:
|
|
265
|
+
common.handle_cli_error(exc, verbose=False)
|
|
266
|
+
common.console.print(project)
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
@app.command("delete")
|
|
270
|
+
def delete_project(
|
|
271
|
+
project: str | None = typer.Argument(None, help="Project name."),
|
|
272
|
+
project_id: int | None = typer.Option(
|
|
273
|
+
None,
|
|
274
|
+
"--project-id",
|
|
275
|
+
min=1,
|
|
276
|
+
help="Project ID.",
|
|
277
|
+
show_default=False,
|
|
278
|
+
),
|
|
279
|
+
profile_name: str | None = typer.Option(None, "--profile", help="Profile name."),
|
|
280
|
+
yes: bool = typer.Option(False, "--yes", help="Skip delete confirmation."),
|
|
281
|
+
verbose: bool = typer.Option(False, "--verbose", help="Show detailed errors."),
|
|
282
|
+
):
|
|
283
|
+
try:
|
|
284
|
+
target_project = common.resolve_cli_project(
|
|
285
|
+
project,
|
|
286
|
+
project_id,
|
|
287
|
+
profile_name=profile_name,
|
|
288
|
+
)
|
|
289
|
+
except Exception as exc:
|
|
290
|
+
common.handle_cli_error(exc, verbose=verbose)
|
|
291
|
+
|
|
292
|
+
common.confirm_delete(
|
|
293
|
+
resource="project",
|
|
294
|
+
target=str(target_project),
|
|
295
|
+
profile_name=profile_name,
|
|
296
|
+
yes=yes,
|
|
297
|
+
)
|
|
298
|
+
client = None
|
|
299
|
+
try:
|
|
300
|
+
client = common.make_client(profile_name)
|
|
301
|
+
client.projects.delete(target_project)
|
|
302
|
+
except Exception as exc:
|
|
303
|
+
common.handle_cli_error(exc, verbose=verbose)
|
|
304
|
+
finally:
|
|
305
|
+
if client is not None:
|
|
306
|
+
client.close()
|
|
307
|
+
|
|
308
|
+
common.console.print(f"[bold green]Project deleted:[/] {target_project}")
|
|
@@ -0,0 +1,306 @@
|
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
from pathlib import Path
|
|
4
|
+
from typing import Any
|
|
5
|
+
|
|
6
|
+
import typer
|
|
7
|
+
import yaml
|
|
8
|
+
|
|
9
|
+
from nufi.cli.commands import common
|
|
10
|
+
|
|
11
|
+
app = typer.Typer(
|
|
12
|
+
help="Manage NuFi servings.",
|
|
13
|
+
invoke_without_command=True,
|
|
14
|
+
context_settings=common.CONTEXT_SETTINGS,
|
|
15
|
+
)
|
|
16
|
+
|
|
17
|
+
|
|
18
|
+
@app.callback()
|
|
19
|
+
def servings(ctx: typer.Context):
|
|
20
|
+
common.show_help_if_no_subcommand(ctx)
|
|
21
|
+
|
|
22
|
+
|
|
23
|
+
@app.command("list")
|
|
24
|
+
def list_servings(
|
|
25
|
+
project: str | None = typer.Option(
|
|
26
|
+
None,
|
|
27
|
+
"--project",
|
|
28
|
+
help="Project name.",
|
|
29
|
+
show_default=False,
|
|
30
|
+
),
|
|
31
|
+
project_id: int | None = typer.Option(
|
|
32
|
+
None,
|
|
33
|
+
"--project-id",
|
|
34
|
+
min=1,
|
|
35
|
+
help="Project ID.",
|
|
36
|
+
show_default=False,
|
|
37
|
+
),
|
|
38
|
+
profile_name: str | None = typer.Option(None, "--profile", help="Profile name."),
|
|
39
|
+
output: common.OutputChoice = typer.Option(
|
|
40
|
+
common.OutputChoice.table,
|
|
41
|
+
"--output",
|
|
42
|
+
help="Output format.",
|
|
43
|
+
),
|
|
44
|
+
verbose: bool = typer.Option(False, "--verbose", help="Show detailed errors."),
|
|
45
|
+
):
|
|
46
|
+
client = None
|
|
47
|
+
try:
|
|
48
|
+
resolved_project = common.resolve_cli_project(
|
|
49
|
+
project,
|
|
50
|
+
project_id,
|
|
51
|
+
profile_name=profile_name,
|
|
52
|
+
)
|
|
53
|
+
client = common.make_client(profile_name)
|
|
54
|
+
servings = client.servings.list(project=resolved_project)
|
|
55
|
+
except Exception as exc:
|
|
56
|
+
common.handle_cli_error(exc, verbose=verbose)
|
|
57
|
+
finally:
|
|
58
|
+
if client is not None:
|
|
59
|
+
client.close()
|
|
60
|
+
|
|
61
|
+
if output == common.OutputChoice.json:
|
|
62
|
+
common.print_json(servings)
|
|
63
|
+
return
|
|
64
|
+
|
|
65
|
+
common.print_table(
|
|
66
|
+
["Name", "Status", "Ready", "Desired", "Endpoint"],
|
|
67
|
+
[
|
|
68
|
+
[
|
|
69
|
+
serving.name,
|
|
70
|
+
serving.deploy_status or "",
|
|
71
|
+
"" if serving.ready_replicas is None else str(serving.ready_replicas),
|
|
72
|
+
""
|
|
73
|
+
if serving.desired_replicas is None
|
|
74
|
+
else str(serving.desired_replicas),
|
|
75
|
+
serving.endpoint or "",
|
|
76
|
+
]
|
|
77
|
+
for serving in servings
|
|
78
|
+
],
|
|
79
|
+
)
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
@app.command("create")
|
|
83
|
+
def create_serving(
|
|
84
|
+
name: str | None = typer.Argument(None, help="Serving name."),
|
|
85
|
+
file: Path | None = typer.Option(
|
|
86
|
+
None,
|
|
87
|
+
"-f",
|
|
88
|
+
"--file",
|
|
89
|
+
exists=True,
|
|
90
|
+
readable=True,
|
|
91
|
+
help="Serving YAML file.",
|
|
92
|
+
),
|
|
93
|
+
project: str | None = typer.Option(
|
|
94
|
+
None,
|
|
95
|
+
"--project",
|
|
96
|
+
help="Project name.",
|
|
97
|
+
show_default=False,
|
|
98
|
+
),
|
|
99
|
+
project_id: int | None = typer.Option(
|
|
100
|
+
None,
|
|
101
|
+
"--project-id",
|
|
102
|
+
min=1,
|
|
103
|
+
help="Project ID.",
|
|
104
|
+
show_default=False,
|
|
105
|
+
),
|
|
106
|
+
image: str | None = typer.Option(None, "--image", help="Container image."),
|
|
107
|
+
cpu: str | None = typer.Option(None, "--cpu", help="Requested CPU."),
|
|
108
|
+
memory: str | None = typer.Option(None, "--memory", help="Requested memory."),
|
|
109
|
+
replicas: int | None = typer.Option(None, "--replicas", help="Replica count."),
|
|
110
|
+
port: int | None = typer.Option(None, "--port", help="Inference port."),
|
|
111
|
+
profile_name: str | None = typer.Option(None, "--profile", help="Profile name."),
|
|
112
|
+
verbose: bool = typer.Option(False, "--verbose", help="Show detailed errors."),
|
|
113
|
+
):
|
|
114
|
+
client = None
|
|
115
|
+
try:
|
|
116
|
+
if file is not None:
|
|
117
|
+
_reject_file_mode_direct_inputs(
|
|
118
|
+
name=name,
|
|
119
|
+
project=project,
|
|
120
|
+
project_id=project_id,
|
|
121
|
+
image=image,
|
|
122
|
+
cpu=cpu,
|
|
123
|
+
memory=memory,
|
|
124
|
+
replicas=replicas,
|
|
125
|
+
port=port,
|
|
126
|
+
)
|
|
127
|
+
create_kwargs = (
|
|
128
|
+
_create_kwargs_from_yaml(file)
|
|
129
|
+
if file is not None
|
|
130
|
+
else _create_kwargs_from_flags(
|
|
131
|
+
name=name,
|
|
132
|
+
project=common.resolve_cli_project(
|
|
133
|
+
project,
|
|
134
|
+
project_id,
|
|
135
|
+
profile_name=profile_name,
|
|
136
|
+
),
|
|
137
|
+
image=image,
|
|
138
|
+
cpu=cpu,
|
|
139
|
+
memory=memory,
|
|
140
|
+
replicas=replicas,
|
|
141
|
+
port=port,
|
|
142
|
+
)
|
|
143
|
+
)
|
|
144
|
+
client = common.make_client(profile_name)
|
|
145
|
+
client.servings.create(**create_kwargs)
|
|
146
|
+
except Exception as exc:
|
|
147
|
+
common.handle_cli_error(exc, verbose=verbose)
|
|
148
|
+
finally:
|
|
149
|
+
if client is not None:
|
|
150
|
+
client.close()
|
|
151
|
+
|
|
152
|
+
common.console.print(f"[bold green]Serving created:[/] {create_kwargs['name']}")
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
@app.command("delete")
|
|
156
|
+
def delete_serving(
|
|
157
|
+
name: str = typer.Argument(..., help="Serving name."),
|
|
158
|
+
project: str | None = typer.Option(
|
|
159
|
+
None,
|
|
160
|
+
"--project",
|
|
161
|
+
help="Project name.",
|
|
162
|
+
show_default=False,
|
|
163
|
+
),
|
|
164
|
+
project_id: int | None = typer.Option(
|
|
165
|
+
None,
|
|
166
|
+
"--project-id",
|
|
167
|
+
min=1,
|
|
168
|
+
help="Project ID.",
|
|
169
|
+
show_default=False,
|
|
170
|
+
),
|
|
171
|
+
profile_name: str | None = typer.Option(None, "--profile", help="Profile name."),
|
|
172
|
+
yes: bool = typer.Option(False, "--yes", help="Skip delete confirmation."),
|
|
173
|
+
verbose: bool = typer.Option(False, "--verbose", help="Show detailed errors."),
|
|
174
|
+
):
|
|
175
|
+
try:
|
|
176
|
+
resolved_project = common.resolve_cli_project(
|
|
177
|
+
project,
|
|
178
|
+
project_id,
|
|
179
|
+
profile_name=profile_name,
|
|
180
|
+
)
|
|
181
|
+
except Exception as exc:
|
|
182
|
+
common.handle_cli_error(exc, verbose=verbose)
|
|
183
|
+
|
|
184
|
+
common.confirm_delete(
|
|
185
|
+
resource="serving",
|
|
186
|
+
target=f"{resolved_project}/{name}",
|
|
187
|
+
profile_name=profile_name,
|
|
188
|
+
yes=yes,
|
|
189
|
+
)
|
|
190
|
+
client = None
|
|
191
|
+
try:
|
|
192
|
+
client = common.make_client(profile_name)
|
|
193
|
+
client.servings.delete(name, project=resolved_project)
|
|
194
|
+
except Exception as exc:
|
|
195
|
+
common.handle_cli_error(exc, verbose=verbose)
|
|
196
|
+
finally:
|
|
197
|
+
if client is not None:
|
|
198
|
+
client.close()
|
|
199
|
+
|
|
200
|
+
common.console.print(f"[bold green]Serving deleted:[/] {name}")
|
|
201
|
+
|
|
202
|
+
|
|
203
|
+
def _create_kwargs_from_yaml(file: Path) -> dict[str, Any]:
|
|
204
|
+
payload = yaml.safe_load(file.read_text(encoding="utf-8")) or {}
|
|
205
|
+
if not isinstance(payload, dict):
|
|
206
|
+
raise typer.BadParameter("Serving YAML must contain a mapping.")
|
|
207
|
+
|
|
208
|
+
project = _required(payload, "project")
|
|
209
|
+
name = _required(payload, "name")
|
|
210
|
+
container = _required(payload, "container")
|
|
211
|
+
if not isinstance(container, dict):
|
|
212
|
+
raise typer.BadParameter("Serving YAML field 'container' must be a mapping.")
|
|
213
|
+
|
|
214
|
+
return {
|
|
215
|
+
"project": project,
|
|
216
|
+
"name": name,
|
|
217
|
+
"container": container,
|
|
218
|
+
"description": payload.get("description"),
|
|
219
|
+
"replicas": payload.get("replicas"),
|
|
220
|
+
"inference_port": payload.get("inferencePort"),
|
|
221
|
+
"volumes": payload.get("volumes"),
|
|
222
|
+
"transformer": payload.get("transformer"),
|
|
223
|
+
}
|
|
224
|
+
|
|
225
|
+
|
|
226
|
+
def _reject_file_mode_direct_inputs(
|
|
227
|
+
*,
|
|
228
|
+
name: str | None,
|
|
229
|
+
project: str | None,
|
|
230
|
+
project_id: int | None,
|
|
231
|
+
image: str | None,
|
|
232
|
+
cpu: str | None,
|
|
233
|
+
memory: str | None,
|
|
234
|
+
replicas: int | None,
|
|
235
|
+
port: int | None,
|
|
236
|
+
) -> None:
|
|
237
|
+
provided = [
|
|
238
|
+
label
|
|
239
|
+
for label, value in {
|
|
240
|
+
"name": name,
|
|
241
|
+
"--project": project,
|
|
242
|
+
"--project-id": project_id,
|
|
243
|
+
"--image": image,
|
|
244
|
+
"--cpu": cpu,
|
|
245
|
+
"--memory": memory,
|
|
246
|
+
"--replicas": replicas,
|
|
247
|
+
"--port": port,
|
|
248
|
+
}.items()
|
|
249
|
+
if value is not None
|
|
250
|
+
]
|
|
251
|
+
if provided:
|
|
252
|
+
raise typer.BadParameter(
|
|
253
|
+
"Cannot combine --file with direct create inputs: " + ", ".join(provided)
|
|
254
|
+
)
|
|
255
|
+
|
|
256
|
+
|
|
257
|
+
def _create_kwargs_from_flags(
|
|
258
|
+
*,
|
|
259
|
+
name: str | None,
|
|
260
|
+
project: str | None,
|
|
261
|
+
image: str | None,
|
|
262
|
+
cpu: str | None,
|
|
263
|
+
memory: str | None,
|
|
264
|
+
replicas: int | None,
|
|
265
|
+
port: int | None,
|
|
266
|
+
) -> dict[str, Any]:
|
|
267
|
+
missing = [
|
|
268
|
+
label
|
|
269
|
+
for label, value in {
|
|
270
|
+
"name": name,
|
|
271
|
+
"--project": project,
|
|
272
|
+
"--image": image,
|
|
273
|
+
"--cpu": cpu,
|
|
274
|
+
"--memory": memory,
|
|
275
|
+
}.items()
|
|
276
|
+
if value is None
|
|
277
|
+
]
|
|
278
|
+
if missing:
|
|
279
|
+
raise typer.BadParameter(
|
|
280
|
+
"Missing required direct create inputs: " + ", ".join(missing)
|
|
281
|
+
)
|
|
282
|
+
|
|
283
|
+
container = {
|
|
284
|
+
"image": image,
|
|
285
|
+
"resources": {
|
|
286
|
+
"requests": {"cpu": cpu, "memory": memory},
|
|
287
|
+
"limits": {"cpu": cpu, "memory": memory},
|
|
288
|
+
},
|
|
289
|
+
}
|
|
290
|
+
return {
|
|
291
|
+
"project": project,
|
|
292
|
+
"name": name,
|
|
293
|
+
"container": container,
|
|
294
|
+
"description": None,
|
|
295
|
+
"replicas": replicas,
|
|
296
|
+
"inference_port": port,
|
|
297
|
+
"volumes": None,
|
|
298
|
+
"transformer": None,
|
|
299
|
+
}
|
|
300
|
+
|
|
301
|
+
|
|
302
|
+
def _required(payload: dict[str, Any], key: str) -> Any:
|
|
303
|
+
value = payload.get(key)
|
|
304
|
+
if value is None or value == "":
|
|
305
|
+
raise typer.BadParameter(f"Serving YAML requires '{key}'.")
|
|
306
|
+
return value
|
nufi/cli/main.py
ADDED
|
@@ -0,0 +1,66 @@
|
|
|
1
|
+
from typing import Annotated
|
|
2
|
+
|
|
3
|
+
import typer
|
|
4
|
+
|
|
5
|
+
from nufi import __version__
|
|
6
|
+
from nufi.cli.commands.auth import login, logout, whoami
|
|
7
|
+
from nufi.cli.commands.compiles import app as compile_app
|
|
8
|
+
from nufi.cli.commands.common import CONTEXT_SETTINGS, show_help_if_no_subcommand
|
|
9
|
+
from nufi.cli.commands.custom_evaluation_templates import app as evaluation_template_app
|
|
10
|
+
from nufi.cli.commands.datasets import app as dataset_app
|
|
11
|
+
from nufi.cli.commands.evaluations import app as evaluation_app
|
|
12
|
+
from nufi.cli.commands.leaderboards import app as leaderboard_app
|
|
13
|
+
from nufi.cli.commands.models import app as model_app
|
|
14
|
+
from nufi.cli.commands.monitoring import app as monitoring_app
|
|
15
|
+
from nufi.cli.commands.profile import app as profile_app
|
|
16
|
+
from nufi.cli.commands.projects import app as project_app
|
|
17
|
+
from nufi.cli.commands.servings import app as serving_app
|
|
18
|
+
|
|
19
|
+
app = typer.Typer(
|
|
20
|
+
name="nufi",
|
|
21
|
+
help="NuFi SDK/CLI.",
|
|
22
|
+
add_completion=False,
|
|
23
|
+
invoke_without_command=True,
|
|
24
|
+
context_settings=CONTEXT_SETTINGS,
|
|
25
|
+
)
|
|
26
|
+
app.add_typer(profile_app, name="profile")
|
|
27
|
+
app.add_typer(project_app, name="project")
|
|
28
|
+
app.add_typer(dataset_app, name="dataset")
|
|
29
|
+
app.add_typer(evaluation_app, name="evaluation")
|
|
30
|
+
evaluation_app.add_typer(evaluation_template_app, name="template")
|
|
31
|
+
app.add_typer(leaderboard_app, name="leaderboard")
|
|
32
|
+
app.add_typer(model_app, name="model")
|
|
33
|
+
app.add_typer(serving_app, name="serving")
|
|
34
|
+
app.add_typer(compile_app, name="compile")
|
|
35
|
+
app.add_typer(monitoring_app, name="monitoring")
|
|
36
|
+
app.command("login")(login)
|
|
37
|
+
app.command("logout")(logout)
|
|
38
|
+
app.command("whoami")(whoami)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
@app.command("version")
|
|
42
|
+
def version_command():
|
|
43
|
+
"""Print the installed NuFi SDK version."""
|
|
44
|
+
typer.echo(__version__)
|
|
45
|
+
|
|
46
|
+
|
|
47
|
+
@app.callback()
|
|
48
|
+
def main(
|
|
49
|
+
ctx: typer.Context,
|
|
50
|
+
version: Annotated[
|
|
51
|
+
bool,
|
|
52
|
+
typer.Option(
|
|
53
|
+
"--version",
|
|
54
|
+
help="Show the installed NuFi SDK version and exit.",
|
|
55
|
+
is_eager=True,
|
|
56
|
+
),
|
|
57
|
+
] = False,
|
|
58
|
+
):
|
|
59
|
+
if version:
|
|
60
|
+
typer.echo(__version__)
|
|
61
|
+
raise typer.Exit()
|
|
62
|
+
show_help_if_no_subcommand(ctx)
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
if __name__ == "__main__":
|
|
66
|
+
app()
|