infixspeed-cli 0.0.16__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.
- infix_cli/__init__.py +5 -0
- infix_cli/__main__.py +6 -0
- infix_cli/agent-guide.txt +71 -0
- infix_cli/cli_framework.py +96 -0
- infix_cli/command_contract.py +157 -0
- infix_cli/commands/__init__.py +1 -0
- infix_cli/commands/_artifacts.py +142 -0
- infix_cli/commands/_comparison.py +443 -0
- infix_cli/commands/_confirm.py +26 -0
- infix_cli/commands/_control.py +290 -0
- infix_cli/commands/_create.py +351 -0
- infix_cli/commands/_create_output.py +139 -0
- infix_cli/commands/_delete.py +288 -0
- infix_cli/commands/_download.py +459 -0
- infix_cli/commands/_fusion_common.py +191 -0
- infix_cli/commands/_fusion_config.py +394 -0
- infix_cli/commands/_fusion_feedback.py +319 -0
- infix_cli/commands/_fusion_tasks.py +507 -0
- infix_cli/commands/_fusion_tensorboard.py +132 -0
- infix_cli/commands/_jobs.py +312 -0
- infix_cli/commands/_logs.py +210 -0
- infix_cli/commands/_publish.py +123 -0
- infix_cli/commands/_register.py +600 -0
- infix_cli/commands/_register_output.py +231 -0
- infix_cli/commands/_storage_tree.py +62 -0
- infix_cli/commands/admin.py +668 -0
- infix_cli/commands/asset.py +2012 -0
- infix_cli/commands/auth.py +246 -0
- infix_cli/commands/deploy.py +850 -0
- infix_cli/commands/evaluation.py +360 -0
- infix_cli/commands/examples.py +138 -0
- infix_cli/commands/fusion.py +1842 -0
- infix_cli/commands/merge.py +709 -0
- infix_cli/commands/resource.py +127 -0
- infix_cli/commands/spark.py +347 -0
- infix_cli/commands/storage.py +329 -0
- infix_cli/commands/training.py +748 -0
- infix_cli/config.py +311 -0
- infix_cli/config_input.py +217 -0
- infix_cli/context.py +84 -0
- infix_cli/discovery.py +459 -0
- infix_cli/domain/__init__.py +1 -0
- infix_cli/domain/dto/__init__.py +6 -0
- infix_cli/domain/dto/admin.py +413 -0
- infix_cli/domain/dto/asset.py +390 -0
- infix_cli/domain/dto/common.py +136 -0
- infix_cli/domain/dto/evaluation.py +296 -0
- infix_cli/domain/dto/logs.py +98 -0
- infix_cli/domain/dto/resource.py +108 -0
- infix_cli/domain/dto/serving.py +156 -0
- infix_cli/domain/dto/spark.py +241 -0
- infix_cli/domain/dto/storage.py +75 -0
- infix_cli/domain/dto/training.py +272 -0
- infix_cli/domain/enums.py +359 -0
- infix_cli/domain/hyperparams.py +190 -0
- infix_cli/domain/refs.py +108 -0
- infix_cli/domain/resolve.py +619 -0
- infix_cli/errors.py +158 -0
- infix_cli/example_data/__init__.py +1 -0
- infix_cli/example_data/fusion/README.md +128 -0
- infix_cli/example_data/fusion/fusion.json +149 -0
- infix_cli/example_data/fusion/prompts/code.jsonl +16 -0
- infix_cli/example_data/fusion/prompts/math.jsonl +16 -0
- infix_cli/example_data/fusion.zip +0 -0
- infix_cli/example_data/merge/README.md +89 -0
- infix_cli/example_data/merge/merge.json +26 -0
- infix_cli/example_data/merge.zip +0 -0
- infix_cli/http/__init__.py +1 -0
- infix_cli/http/browser_auth.py +160 -0
- infix_cli/http/client.py +575 -0
- infix_cli/http/pagination.py +84 -0
- infix_cli/http/upload.py +254 -0
- infix_cli/main.py +432 -0
- infix_cli/pipeline_config_schema.py +122 -0
- infix_cli/render/__init__.py +79 -0
- infix_cli/render/json_out.py +123 -0
- infix_cli/render/progress.py +62 -0
- infix_cli/render/text.py +233 -0
- infix_cli/update_check.py +177 -0
- infix_cli/waiter.py +93 -0
- infix_cli/workspace.py +158 -0
- infixspeed_cli-0.0.16.dist-info/METADATA +58 -0
- infixspeed_cli-0.0.16.dist-info/RECORD +85 -0
- infixspeed_cli-0.0.16.dist-info/WHEEL +4 -0
- infixspeed_cli-0.0.16.dist-info/entry_points.txt +2 -0
infix_cli/discovery.py
ADDED
|
@@ -0,0 +1,459 @@
|
|
|
1
|
+
"""从实际 Click 命令树生成离线能力和参数说明。"""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from importlib.resources import files
|
|
6
|
+
from typing import Annotated
|
|
7
|
+
from urllib.parse import quote
|
|
8
|
+
|
|
9
|
+
import typer
|
|
10
|
+
|
|
11
|
+
from infix_cli import __version__, render
|
|
12
|
+
from infix_cli.cli_framework import click, parameter_schema
|
|
13
|
+
from infix_cli.command_contract import effects, result_contract
|
|
14
|
+
from infix_cli.config_input import EXECUTION_OPTIONS, config_parameters
|
|
15
|
+
from infix_cli.commands._fusion_config import ALIASES, ORDER
|
|
16
|
+
from infix_cli.commands.deploy import _ENGINES
|
|
17
|
+
from infix_cli.commands.evaluation import _MODEL_SOURCES
|
|
18
|
+
from infix_cli.commands.training import _default_task
|
|
19
|
+
from infix_cli.domain import enums, hyperparams
|
|
20
|
+
from infix_cli.errors import ExitCode, UsageError
|
|
21
|
+
from infix_cli.pipeline_config_schema import pipeline_config_schema
|
|
22
|
+
from infix_cli.waiter import DEFAULT_WAIT_TIMEOUT
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def _features(path, command):
|
|
26
|
+
names = {p.name for p in command.params}
|
|
27
|
+
flags = {opt for p in command.params for opt in p.opts}
|
|
28
|
+
action = path[-1]
|
|
29
|
+
confirmation = sorted(flags & {"--yes", "--force"})
|
|
30
|
+
result = {
|
|
31
|
+
"dry_run": "dry_run" in names,
|
|
32
|
+
"wait": "wait" in names or action == "wait",
|
|
33
|
+
"config_stdin": "config" in names,
|
|
34
|
+
"idempotency_key": "idempotency_key" in names,
|
|
35
|
+
"explicit_confirmation": confirmation,
|
|
36
|
+
**effects(tuple(path), flags),
|
|
37
|
+
}
|
|
38
|
+
if confirmation:
|
|
39
|
+
result["confirmation_when"] = (
|
|
40
|
+
{"flag": "--all-checkpoints", "except_flag": "--dry-run"}
|
|
41
|
+
if tuple(path) == ("evaluation", "compare")
|
|
42
|
+
else "before_mutation"
|
|
43
|
+
)
|
|
44
|
+
if action == "logs":
|
|
45
|
+
result["log_output"] = {
|
|
46
|
+
"snapshot": "json" if path[0] in {"fusion", "merge"} else "ndjson",
|
|
47
|
+
**({"follow": "ndjson"} if "--follow" in flags else {}),
|
|
48
|
+
**({"download": "local_file"} if "--download" in flags else {}),
|
|
49
|
+
}
|
|
50
|
+
return result
|
|
51
|
+
|
|
52
|
+
|
|
53
|
+
def _target(ctx, path):
|
|
54
|
+
target = ctx.find_root().command
|
|
55
|
+
for name in path:
|
|
56
|
+
if not isinstance(target, click.Group):
|
|
57
|
+
raise UsageError("Invalid command path.", details={"command": path})
|
|
58
|
+
target = target.get_command(ctx, name)
|
|
59
|
+
if target is None:
|
|
60
|
+
raise UsageError("Unknown command.", details={"command": path})
|
|
61
|
+
return target
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def _parameters(command):
|
|
65
|
+
parameters = []
|
|
66
|
+
for param in command.params:
|
|
67
|
+
if not param.name or param.name.startswith("_"):
|
|
68
|
+
continue
|
|
69
|
+
flags = [flag for flag in param.opts if flag.startswith("-")]
|
|
70
|
+
parameters.append({
|
|
71
|
+
"name": param.name,
|
|
72
|
+
"kind": "option" if flags else "argument",
|
|
73
|
+
"flags": flags,
|
|
74
|
+
"required": param.required,
|
|
75
|
+
"default": None if callable(param.default) else param.default,
|
|
76
|
+
**({"negative_flags": param.secondary_opts} if getattr(param, "secondary_opts", []) else {}),
|
|
77
|
+
"schema": parameter_schema(param),
|
|
78
|
+
"description": getattr(param, "help", None),
|
|
79
|
+
})
|
|
80
|
+
return parameters
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
def guide(ctx: typer.Context) -> None:
|
|
84
|
+
"""Show the installed Agent integration guide (offline)."""
|
|
85
|
+
content = files("infix_cli").joinpath("agent-guide.txt").read_text(encoding="utf-8")
|
|
86
|
+
if ctx.obj.output == "json":
|
|
87
|
+
render.json_out.print_raw({"content": content})
|
|
88
|
+
else:
|
|
89
|
+
typer.echo(content, nl=False)
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def _walk(ctx, command, path=()):
|
|
93
|
+
if isinstance(command, click.Group):
|
|
94
|
+
for name in command.list_commands(ctx):
|
|
95
|
+
child = command.get_command(ctx, name)
|
|
96
|
+
if child is not None:
|
|
97
|
+
yield from _walk(ctx, child, (*path, name))
|
|
98
|
+
else:
|
|
99
|
+
yield {
|
|
100
|
+
"command": " ".join(path),
|
|
101
|
+
"description": command.get_short_help_str(limit=120),
|
|
102
|
+
**_features(path, command),
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
|
|
106
|
+
def capabilities(
|
|
107
|
+
ctx: typer.Context,
|
|
108
|
+
command: Annotated[list[str] | None, typer.Argument(help="Optional command or group prefix.")] = None,
|
|
109
|
+
groups: Annotated[bool, typer.Option("--groups", help="List immediate groups and commands only.")] = False,
|
|
110
|
+
) -> None:
|
|
111
|
+
"""List installed commands and supported automation features (offline)."""
|
|
112
|
+
ctx.obj.no_update_check = True
|
|
113
|
+
path = command or []
|
|
114
|
+
target = _target(ctx, path)
|
|
115
|
+
payload = {
|
|
116
|
+
"contract_version": "1",
|
|
117
|
+
"cli_version": __version__,
|
|
118
|
+
"scope": "installed_cli",
|
|
119
|
+
"scope_description": "Endpoint version, permissions and resource availability are checked separately.",
|
|
120
|
+
"guide_command": "infix guide -o text",
|
|
121
|
+
"defaults": {
|
|
122
|
+
"output": "json",
|
|
123
|
+
"interactive": False,
|
|
124
|
+
"submission": "async",
|
|
125
|
+
"wait_timeout_seconds": int(DEFAULT_WAIT_TIMEOUT),
|
|
126
|
+
},
|
|
127
|
+
"streams": {
|
|
128
|
+
"result": "stdout",
|
|
129
|
+
"error": "stderr",
|
|
130
|
+
"streaming_logs": "ndjson",
|
|
131
|
+
"snapshot_logs": "see_command_features",
|
|
132
|
+
},
|
|
133
|
+
"exit_codes": {**{str(int(code)): code.name.lower() for code in ExitCode}, "130": "interrupted"},
|
|
134
|
+
"global_parameters": _parameters(ctx.find_root().command),
|
|
135
|
+
"schema_command": "infix schema <command...>",
|
|
136
|
+
}
|
|
137
|
+
if groups and isinstance(target, click.Group):
|
|
138
|
+
payload["groups"] = [
|
|
139
|
+
{
|
|
140
|
+
"command": " ".join((*path, name)),
|
|
141
|
+
"group": isinstance(child, click.Group),
|
|
142
|
+
"description": child.get_short_help_str(limit=120),
|
|
143
|
+
}
|
|
144
|
+
for name in target.list_commands(ctx)
|
|
145
|
+
if (child := target.get_command(ctx, name)) is not None
|
|
146
|
+
]
|
|
147
|
+
else:
|
|
148
|
+
payload["commands"] = list(_walk(ctx.find_root(), target, tuple(path)))
|
|
149
|
+
render.render_object(
|
|
150
|
+
ctx.obj, payload, [(item["command"], item["description"])
|
|
151
|
+
for item in payload.get("groups", payload.get("commands", []))]
|
|
152
|
+
)
|
|
153
|
+
|
|
154
|
+
|
|
155
|
+
def schema(
|
|
156
|
+
ctx: typer.Context,
|
|
157
|
+
command: Annotated[
|
|
158
|
+
list[str],
|
|
159
|
+
typer.Argument(
|
|
160
|
+
help="Command path, e.g. training create or asset model register."
|
|
161
|
+
),
|
|
162
|
+
],
|
|
163
|
+
) -> None:
|
|
164
|
+
"""Describe CLI arguments and supported task configuration (offline)."""
|
|
165
|
+
ctx.obj.no_update_check = True
|
|
166
|
+
target = _target(ctx, command)
|
|
167
|
+
if isinstance(target, click.Group):
|
|
168
|
+
payload = {
|
|
169
|
+
"contract_version": "1",
|
|
170
|
+
"command": " ".join(command),
|
|
171
|
+
"commands": target.list_commands(ctx),
|
|
172
|
+
}
|
|
173
|
+
else:
|
|
174
|
+
features = _features(command, target)
|
|
175
|
+
payload = {
|
|
176
|
+
"contract_version": "1",
|
|
177
|
+
"command": " ".join(command),
|
|
178
|
+
"description": target.help,
|
|
179
|
+
"parameters": _parameters(target),
|
|
180
|
+
"features": features,
|
|
181
|
+
"output": {
|
|
182
|
+
"default": "json",
|
|
183
|
+
**(result_contract(tuple(command), dry_run=features["dry_run"])
|
|
184
|
+
if len(command) == 2 else {}),
|
|
185
|
+
"error_schema": {
|
|
186
|
+
"type": "object",
|
|
187
|
+
"required": ["contract_version", "error"],
|
|
188
|
+
"properties": {
|
|
189
|
+
"contract_version": {"const": "1"},
|
|
190
|
+
"error": {
|
|
191
|
+
"type": "object",
|
|
192
|
+
"required": ["code", "message", "retryable", "exit_code"],
|
|
193
|
+
"properties": {
|
|
194
|
+
"code": {"type": "string"},
|
|
195
|
+
"message": {"type": "string"},
|
|
196
|
+
"retryable": {"type": "boolean"},
|
|
197
|
+
"exit_code": {"type": "integer"},
|
|
198
|
+
},
|
|
199
|
+
},
|
|
200
|
+
},
|
|
201
|
+
},
|
|
202
|
+
},
|
|
203
|
+
}
|
|
204
|
+
if (
|
|
205
|
+
command[0] in {"training", "evaluation", "spark", "deploy"}
|
|
206
|
+
and command[-1] == "create"
|
|
207
|
+
):
|
|
208
|
+
payload["config_schema"] = _job_schema(ctx, target, command[0])
|
|
209
|
+
payload["config_rules"] = {
|
|
210
|
+
"format": ["json", "yaml"],
|
|
211
|
+
"stdin": "--config -",
|
|
212
|
+
"task_flags_with_config": "rejected",
|
|
213
|
+
"execution_options": sorted(
|
|
214
|
+
p.name for p in target.params
|
|
215
|
+
if p.name in EXECUTION_OPTIONS and p.name != "config"
|
|
216
|
+
),
|
|
217
|
+
}
|
|
218
|
+
if command[0] == "training" and command[-1] == "create":
|
|
219
|
+
payload["conditions"] = [
|
|
220
|
+
{
|
|
221
|
+
"when": {"method": "custom"},
|
|
222
|
+
"required": ["code", "image"],
|
|
223
|
+
"forbidden": ["set", "hyperparameters", "checkpoint_precision"],
|
|
224
|
+
},
|
|
225
|
+
*[
|
|
226
|
+
{
|
|
227
|
+
"when": {"method": method},
|
|
228
|
+
"applies_when_method_omitted": method == "fp8",
|
|
229
|
+
"required": ["checkpoint_precision"],
|
|
230
|
+
"checkpoint_precision": list(precisions),
|
|
231
|
+
"allowed_tasks": list(hyperparams.tasks_for_method(method)),
|
|
232
|
+
"default_task": _default_task(method),
|
|
233
|
+
}
|
|
234
|
+
for method, precisions in enums.CKPT_PRECISION_BY_METHOD.items()
|
|
235
|
+
],
|
|
236
|
+
]
|
|
237
|
+
payload["hyperparameters"] = {
|
|
238
|
+
task: {
|
|
239
|
+
name: {"minimum": low, "maximum": high, "default": default}
|
|
240
|
+
for name, (low, high, default) in values.items()
|
|
241
|
+
}
|
|
242
|
+
for task, values in hyperparams.SCHEMA.items()
|
|
243
|
+
}
|
|
244
|
+
payload["shared_sft_parameters"] = sorted(hyperparams.SHARED_SFT_KEYS)
|
|
245
|
+
if command == ["evaluation", "create"]:
|
|
246
|
+
payload["conditions"] = [
|
|
247
|
+
{"when": {"eval_type": "custom"}, "required": ["custom_format"]},
|
|
248
|
+
{"when": {"eval_type": "official"}, "forbidden": ["custom_format"]},
|
|
249
|
+
{"when": {"model_source": "endpoint"}, "chat_template": "model"},
|
|
250
|
+
]
|
|
251
|
+
if "config_schema" in payload:
|
|
252
|
+
required = payload["config_schema"]["required"]
|
|
253
|
+
payload["input_modes"] = {
|
|
254
|
+
"flags": {"required": [
|
|
255
|
+
next(p["flags"][0] for p in payload["parameters"] if p["name"] == name)
|
|
256
|
+
for name in required
|
|
257
|
+
]},
|
|
258
|
+
"config": {"required": ["--config"], "schema_field": "config_schema"},
|
|
259
|
+
}
|
|
260
|
+
if command in (["fusion", "run"], ["merge", "create"]):
|
|
261
|
+
payload["config_schema"] = pipeline_config_schema(command[0])
|
|
262
|
+
payload["input_modes"] = {
|
|
263
|
+
"config": {"required": ["--config"], "schema_field": "config_schema"},
|
|
264
|
+
}
|
|
265
|
+
if command[0] == "merge":
|
|
266
|
+
payload["input_modes"]["flags"] = {
|
|
267
|
+
"required": ["--name", "--base-model", "--expert-model"],
|
|
268
|
+
"defaults_from": ["infix", "merge", "methods"],
|
|
269
|
+
}
|
|
270
|
+
overrides = ["--name", "--visibility"]
|
|
271
|
+
if command[0] == "fusion":
|
|
272
|
+
overrides += ["--from", "--to"]
|
|
273
|
+
payload["stages"] = {
|
|
274
|
+
"order": list(ORDER),
|
|
275
|
+
"aliases": ALIASES,
|
|
276
|
+
"selection": "from must be at or before to. Supply inputs the selected stages cannot resolve from upstream.",
|
|
277
|
+
}
|
|
278
|
+
payload["config_rules"] = {
|
|
279
|
+
"format": ["json", "yaml"],
|
|
280
|
+
"stdin": "--config -",
|
|
281
|
+
"overrides": overrides,
|
|
282
|
+
"execution_options": ["--dry-run", "--wait", "--timeout"],
|
|
283
|
+
"required_from_config_or_flag": ["name"],
|
|
284
|
+
"validation": "Stage, resource and model constraints are validated by --dry-run against the endpoint.",
|
|
285
|
+
}
|
|
286
|
+
if command == ["evaluation", "compare"]:
|
|
287
|
+
payload["conditions"] = [
|
|
288
|
+
{"at_least_one": ["--candidate", "--candidate-from-merge", "--candidate-from-fusion"]},
|
|
289
|
+
{"mutually_exclusive": ["--last", "--checkpoint", "--all-checkpoints"]},
|
|
290
|
+
{"requires": ["--candidate-from-fusion"], "if_any": ["--last", "--checkpoint", "--all-checkpoints", "--run"]},
|
|
291
|
+
{"when": {"--eval-type": "custom"}, "required": ["--custom-format"]},
|
|
292
|
+
]
|
|
293
|
+
if command[0] == "fusion":
|
|
294
|
+
payload["dynamic_parameters_command"] = "infix fusion parameters"
|
|
295
|
+
if command[0] == "merge":
|
|
296
|
+
payload["dynamic_parameters_command"] = "infix merge methods"
|
|
297
|
+
if command[0] in {"fusion", "merge"}:
|
|
298
|
+
payload["example_command"] = (
|
|
299
|
+
f"infix examples show {command[0]} --file {command[0]}.json"
|
|
300
|
+
)
|
|
301
|
+
payload["global_parameters"] = _parameters(ctx.find_root().command)
|
|
302
|
+
render.render_object(ctx.obj, payload, [("Command", " ".join(command))])
|
|
303
|
+
|
|
304
|
+
|
|
305
|
+
def _job_schema(ctx, command, module):
|
|
306
|
+
properties = {}
|
|
307
|
+
with click.Context(command, parent=ctx.find_root()) as child:
|
|
308
|
+
for name, param in config_parameters(child).items():
|
|
309
|
+
if name in {"setting", "engine_arg"}:
|
|
310
|
+
name = {"setting": "set", "engine_arg": "engine_args"}[name]
|
|
311
|
+
prop = parameter_schema(param)
|
|
312
|
+
if param.name in {"setting", "engine_arg", "spark_conf"}:
|
|
313
|
+
prop = {"oneOf": [prop, {"type": "object"}]}
|
|
314
|
+
if module == "spark" and name == "dataset":
|
|
315
|
+
prop = {"oneOf": [{"type": "string"}, prop]}
|
|
316
|
+
if param.default is None:
|
|
317
|
+
prop = {"anyOf": [prop, {"type": "null"}]}
|
|
318
|
+
description = getattr(param, "help", None)
|
|
319
|
+
properties[name] = {**prop, **({"description": description} if description else {})}
|
|
320
|
+
required = {
|
|
321
|
+
"training": ["name", "base_model", "dataset", "hardware"],
|
|
322
|
+
"evaluation": ["name", "model_source", "model", "dataset"],
|
|
323
|
+
"spark": ["name", "dataset", "code", "main_script", "hardware"],
|
|
324
|
+
"deploy": ["name", "model", "hardware"],
|
|
325
|
+
}[module]
|
|
326
|
+
for name in required:
|
|
327
|
+
# 配置必须提供值。仅可选字段接受 null 回退到默认值。
|
|
328
|
+
prop = properties[name]
|
|
329
|
+
if "anyOf" in prop:
|
|
330
|
+
properties[name] = {**prop["anyOf"][0], **{key: value for key, value in prop.items() if key != "anyOf"}}
|
|
331
|
+
if properties[name].get("type") == "string":
|
|
332
|
+
properties[name]["minLength"] = 1
|
|
333
|
+
enum_fields = {"visibility": enums.VISIBILITY.cli_values}
|
|
334
|
+
defaults = {
|
|
335
|
+
"training": {"method": "fp8", "workers": 1},
|
|
336
|
+
"evaluation": {"eval_type": "official", "chat_template": "model"},
|
|
337
|
+
"spark": {"workers": 1},
|
|
338
|
+
"deploy": {"replicas": 1, "engine": "sglang"},
|
|
339
|
+
}[module]
|
|
340
|
+
defaults["visibility"] = "private"
|
|
341
|
+
constraints = []
|
|
342
|
+
if module == "training":
|
|
343
|
+
enum_fields.update(
|
|
344
|
+
method=enums.TRAINING_METHOD.cli_values, task=enums.TASK_TYPE.cli_values
|
|
345
|
+
)
|
|
346
|
+
properties["hyperparameters"] = properties["set"]
|
|
347
|
+
constraints.append({"not": {"required": ["set", "hyperparameters"]}})
|
|
348
|
+
for method, precisions in enums.CKPT_PRECISION_BY_METHOD.items():
|
|
349
|
+
constraints.append({
|
|
350
|
+
"if": {
|
|
351
|
+
"properties": {"method": {"const": method}},
|
|
352
|
+
**({"required": ["method"]} if method != "fp8" else {}),
|
|
353
|
+
},
|
|
354
|
+
"then": {
|
|
355
|
+
"required": ["checkpoint_precision"],
|
|
356
|
+
"properties": {
|
|
357
|
+
"checkpoint_precision": {"enum": list(precisions)},
|
|
358
|
+
"task": {"enum": list(hyperparams.tasks_for_method(method))},
|
|
359
|
+
},
|
|
360
|
+
},
|
|
361
|
+
})
|
|
362
|
+
constraints.append({
|
|
363
|
+
"if": {"properties": {"method": {"const": "custom"}}, "required": ["method"]},
|
|
364
|
+
"then": {
|
|
365
|
+
"required": ["code", "image"],
|
|
366
|
+
"properties": {name: {"type": "string", "minLength": 1} for name in ("code", "image")},
|
|
367
|
+
"not": {"anyOf": [
|
|
368
|
+
{"required": [key]} for key in ("set", "hyperparameters", "checkpoint_precision")
|
|
369
|
+
]},
|
|
370
|
+
},
|
|
371
|
+
})
|
|
372
|
+
if module == "evaluation":
|
|
373
|
+
enum_fields.update(
|
|
374
|
+
model_source=_MODEL_SOURCES, chat_template=["model", "plain"],
|
|
375
|
+
eval_type=["official", "custom"], custom_format=["single-choice", "question-answering"],
|
|
376
|
+
)
|
|
377
|
+
constraints.extend([
|
|
378
|
+
{
|
|
379
|
+
"if": {"properties": {"eval_type": {"const": "custom"}}, "required": ["eval_type"]},
|
|
380
|
+
"then": {"required": ["custom_format"]},
|
|
381
|
+
"else": {"not": {"required": ["custom_format"]}},
|
|
382
|
+
},
|
|
383
|
+
{
|
|
384
|
+
"if": {"properties": {"model_source": {"const": "endpoint"}}, "required": ["model_source"]},
|
|
385
|
+
"then": {"properties": {"chat_template": {"const": "model"}}},
|
|
386
|
+
},
|
|
387
|
+
])
|
|
388
|
+
if module == "deploy":
|
|
389
|
+
enum_fields["engine"] = _ENGINES
|
|
390
|
+
properties.update(
|
|
391
|
+
image={"type": "string"},
|
|
392
|
+
port={"type": "integer", "minimum": 1, "maximum": 65535},
|
|
393
|
+
)
|
|
394
|
+
for name, values in enum_fields.items():
|
|
395
|
+
if name in properties:
|
|
396
|
+
description = properties[name].get("description")
|
|
397
|
+
properties[name] = {
|
|
398
|
+
"type": "string", "enum": list(values),
|
|
399
|
+
**({"description": description} if description else {}),
|
|
400
|
+
}
|
|
401
|
+
for name, default in defaults.items():
|
|
402
|
+
properties[name]["default"] = default
|
|
403
|
+
return {
|
|
404
|
+
"$schema": "https://json-schema.org/draft/2020-12/schema",
|
|
405
|
+
"type": "object",
|
|
406
|
+
"properties": properties,
|
|
407
|
+
"required": required,
|
|
408
|
+
"additionalProperties": False,
|
|
409
|
+
**({"allOf": constraints} if constraints else {}),
|
|
410
|
+
}
|
|
411
|
+
|
|
412
|
+
|
|
413
|
+
def doctor(ctx: typer.Context) -> None:
|
|
414
|
+
"""Check the configured endpoint, credentials and workspace without changing state."""
|
|
415
|
+
from infix_cli.errors import AuthError, CliError
|
|
416
|
+
|
|
417
|
+
run = ctx.obj
|
|
418
|
+
run.no_update_check = True
|
|
419
|
+
profile = run.profile
|
|
420
|
+
checks = []
|
|
421
|
+
payload = {
|
|
422
|
+
"cli_version": __version__,
|
|
423
|
+
"profile": profile.name,
|
|
424
|
+
"api_url": profile.api_url,
|
|
425
|
+
"workspace_id": profile.workspace_id or None,
|
|
426
|
+
"checks": checks,
|
|
427
|
+
}
|
|
428
|
+
check = "authentication"
|
|
429
|
+
try:
|
|
430
|
+
client = run.client(require_workspace=False)
|
|
431
|
+
me = client.get("/account/me")
|
|
432
|
+
payload["identity"] = {
|
|
433
|
+
key: me[key] for key in ("id", "email", "username") if key in me
|
|
434
|
+
}
|
|
435
|
+
checks.append({"name": check, "ok": True})
|
|
436
|
+
|
|
437
|
+
check = "workspace_access"
|
|
438
|
+
workspace_id = profile.workspace_id
|
|
439
|
+
if not workspace_id:
|
|
440
|
+
from infix_cli.workspace import discover_workspace
|
|
441
|
+
|
|
442
|
+
workspace_id, _ = discover_workspace(client, profile.api_key, me)
|
|
443
|
+
payload["workspace_id"] = workspace_id
|
|
444
|
+
profile.workspace_id = workspace_id
|
|
445
|
+
run.close()
|
|
446
|
+
client = run.client()
|
|
447
|
+
try:
|
|
448
|
+
workspace = client.get(f"/workspaces/{quote(workspace_id, safe='')}")
|
|
449
|
+
except AuthError:
|
|
450
|
+
# 部署可能限制工作空间详情的鉴权方式,模型列表会校验 Key 绑定的工作空间。
|
|
451
|
+
client.get("/assets/models", params={"scope": "my", "page": 1, "page_size": 1})
|
|
452
|
+
workspace = {}
|
|
453
|
+
payload["workspace_status"] = workspace.get("provisioning_status")
|
|
454
|
+
checks.append({"name": check, "ok": True})
|
|
455
|
+
except CliError as exc:
|
|
456
|
+
checks.append({"name": check, "ok": False, "code": exc.code})
|
|
457
|
+
render.render_object(run, {**payload, "ok": False}, [("Status", "failed")])
|
|
458
|
+
raise
|
|
459
|
+
render.render_object(run, {**payload, "ok": True}, [("Status", "ok")])
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
"""Domain layer: vocabulary mapping, reference parsing, DTOs."""
|