# hub

Python API: `hubai_sdk.utils.hub`

## 函数

### get_configs

```python
def get_configs(path: str | None, opts: list[str] | dict[str, Any] | None = None) -> tuple[Config, NNArchiveConfig | None, str | None]:
```

设置配置。

参数

 * `path` (`str | None`): 配置文件或 NN Archive 的路径。
 * `opts` (`list[str] | dict[str, Any] | None`): 配置文件的可选 CLI 覆盖。

返回

 * `tuple[Config, NNArchiveConfig | None, str | None]`: 解析后的模型转换器配置、可选的 NN Archive 配置和主阶段键。

### get_output_dir_name

```python
def get_output_dir_name(target: Target, name: str, output_dir: str | None) -> Path:
```

为转换结果构建输出目录路径。

### get_resource_id

```python
def get_resource_id(identifier: str, endpoint: Literal['models', 'modelVersions', 'modelInstances']) -> str:
```

将 UUID、HubAI ID、原始 slug 或资源路径解析为资源 ID。

参数

 * `identifier` (`str`): 用户提供的 UUID、HubAI ID、原始 slug 或资源路径。
 * `endpoint` (`Literal['models', 'modelVersions', 'modelInstances']`): 要解析的资源端点。

返回

 * `str`: 解析后的 HubAI 资源 ID。

引发

 * `ResourceAmbiguousError`: 如果标识符匹配多个资源。
 * `ValueError`: 如果标识符无法解析。

### get_resource_info

```python
def get_resource_info(identifier: str, endpoint: ResourceEndpoint) -> dict[str, Any]:
```

为已解析的标识符获取原始 HubAI 资源数据。

### get_target_specific_options

```python
def get_target_specific_options(target: Target, cfg: SingleStageConfig, tool_version: str | None = None) -> dict[str, Any]:
```

从解析的配置为目标构建导出选项。

### get_variant_name

```python
def get_variant_name(cfg: SingleStageConfig, model_type: ModelType, name: str) -> str:
```

派生变体名称，并在已知时附加输入分辨率。

### get_version_number

```python
def get_version_number(model_id: str) -> str:
```

返回模型变体的下一个补丁版本。

### init_dirs

```python
def init_dirs():
```

如果 SDK 工作目录不存在，则创建它们。

### is_hubai_id

```python
def is_hubai_id(identifier: str) -> bool:
```

返回标识符是否看起来像 HubAI 资源 ID。

### is_valid_uuid

```python
def is_valid_uuid(uuid_string: str) -> bool:
```

返回字符串是否是有效的 UUID。

### print_hub_ls

```python
def print_hub_ls(data: list[dict[str, Any]], keys: list[str], rename: dict[str, str] | None = None):
```

将 HubAI 资源列表渲染为富表格。

### print_hub_resource_info

```python
def print_hub_resource_info(model: dict[str, Any], keys: list[str], json: bool, rename: dict[str, str] | None = None, **kwargs):
```

以 CLI 友好的富输出渲染单个 HubAI 资源。

### raise_for_hub_error

```python
def raise_for_hub_error(exc: HTTPError, *, identifier: str | None = None, endpoint: ResourceEndpoint | Literal['jobs'] | None = None, conflict_message: str | None = None) -> NoReturn:
```

将请求 HTTP 错误转换为 SDK 特定的异常。

### resolve_resource_id

```python
def resolve_resource_id(identifier: str, endpoint: ResourceEndpoint) -> str:
```

解析标识符并将查找失败转换为 SDK 错误。

### run_cli

```python
def run_cli(action: Callable[[], T]) -> T:
```

运行 CLI 操作并将 SDK 异常转换为干净退出。

### slug_to_id

```python
def slug_to_id(slug: str, endpoint: Literal['models', 'modelVersions', 'modelInstances']) -> str | None:
```

将原始资源 slug 解析为其资源 ID。

### wait_for_job

```python
def wait_for_job(job_id: str) -> JobMessageResponse:
```

轮询 HubAI 作业，直到它完成或失败。

参数

 * `job_id` (`str`): HubAI 作业 ID。

返回

 * `JobMessageResponse`: 完成的作业响应。

引发

 * `HubApiError`: 如果作业失败或以终端非成功状态结束。

## 属性

### ResourceEndpoint

### T
