# models

Python API: `hubai_sdk.services.models`

创建和管理顶级模型资源。

模型包含共享元数据，例如其显示名称、支持的任务、许可证和可见性。实际文件属于版本化变体下的模型实例；请参阅
[hubai_sdk.services.variants](/cloud/hubai/model-registry/hubai-sdk/hubai-sdk-api-reference/services/variants.md)
和
[hubai_sdk.services.instances](/cloud/hubai/model-registry/hubai-sdk/hubai-sdk-api-reference/services/instances.md)。

 * `标识符:`：接受 `identifier` 的函数支持 UUID、原始模型 slug 或 `<team>/<model>` 资源路径。这使得 slug 适用于配置文件，而 UUID 对于编程流程仍然有用。
 * `可见性:`：在创建过程中，`is_public=True` 使模型公开，`False` 使其私有，`None` 选择团队可见性。对于列表操作，`None` 表示没有可见性过滤器。对于更新，`None` 使现有可见性保持不变。

> **示例**
> ```python
models = client.models.list_models(
    tasks=["OBJECT_DETECTION"],
    is_public=True,
    limit=10,
)
model = client.models.get_model(models[0].id)
```

## 函数

### create_model

```python
def create_model(name: str, *, license_type: License = 'undefined', is_public: bool | None = False, description: str | None =
None, description_short: str = '<empty>', architecture_id: UUID | str | None = None, tasks: list[Task] | None = None, links:
list[str] | None = None, is_yolo: bool = False) -> ModelResponse:
```

创建模型资源。

参数

 * `name` (`str`): 人类可读的模型名称。HubAI 从中派生 slug。
 * `license_type` (`License`): 附加到模型元数据的许可证。
 * `is_public` (`bool | None`): `True` 表示公开，`False` 表示私有，`None` 表示团队可见性。
 * `description` (`str | None`): 完整的模型描述。
 * `description_short` (`str`): 模型列表中显示的简短摘要。
 * `architecture_id` (`UUID | str | None`): 相关的架构 UUID（如果已知）。
 * `tasks` (`list[Task] | None`): 模型支持的任务。
 * `links` (`list[str] | None`): 源代码、论文或其他相关资源的 URL。
 * `is_yolo` (`bool`): 模型是否使用受支持的 YOLO 输出契约。

返回

 * `ModelResponse`: 创建的模型资源。

引发

 * `ResourceConflictError`: 如果具有派生 slug 的模型已存在。
 * `HubApiError`: 如果 HubAI 因其他原因拒绝请求。

### create_model_cli

```python
def create_model_cli(name: str, *, license_type: License = 'undefined', is_public: bool | None = False, description: str | None =
None, description_short: str = '<empty>', architecture_id: UUID | str | None = None, tasks: list[Task] | None = None, links:
list[str] | None = None, is_yolo: bool = False):
```

创建新的模型资源。

### delete_model

```python
def delete_model(identifier: UUID | str):
```

从 HubAI 删除模型。

参数

 * `identifier` (`UUID | str`): 模型 UUID、原始 slug 或 `<team>/<model>` 路径。

引发

 * `ResourceNotFoundError`: 如果无法解析 `identifier`。
 * `HubApiError`: 如果 HubAI 拒绝删除。

### delete_model_cli

```python
def delete_model_cli(identifier: UUID | str):
```

删除模型。

### get_model

```python
def get_model(identifier: UUID | str) -> ModelResponse:
```

按标识符获取一个模型。

参数

 * `identifier` (`UUID | str`): 模型 UUID、原始 slug 或 `<team>/<model>` 路径。

返回

 * `ModelResponse`: 解析的模型资源。

### get_model_info_cli

```python
def get_model_info_cli(identifier: UUID | str):
```

从 HubAI 获取模型信息。

### list_models

```python
def list_models(tasks: list[Task] | None = None, license_type: License | None = None, is_public: bool | None = None, project_id:
str | None = None, luxonis_only: bool = False, limit: int = 50, sort: str = 'updated', order: Order = 'desc') ->
list[ModelResponse]:
```

列出对经过身份验证的 HubAI 团队可见的模型。

参数

 * `tasks` (`list[Task] | None`): 按支持的任务筛选模型。
 * `license_type` (`License | None`): 保留具有此许可证的模型。
 * `is_public` (`bool | None`): 按公开状态筛选。保留为 `None` 以包含 API 密钥可用的所有可见性。
 * `project_id` (`str | None`): 保留属于此项目的模型。
 * `luxonis_only` (`bool`): 是否仅返回 Luxonis 维护的模型。
 * `limit` (`int`): 要返回的最大模型数量。
 * `sort` (`str`): [ModelResponse](/cloud/hubai/model-registry/hubai-sdk/hubai-sdk-api-reference/utils/sdk_models.md) 用于排序的字段，例如 `"name"`、`"id"` 或 `"updated"`。
 * `order` (`Order`): 按升序或降序排序。

返回

 * `list[ModelResponse]`: 匹配的模型资源列表。

### list_models_cli

```python
def list_models_cli(tasks: list[Task] | None = None, license_type: License | None = None, is_public: bool | None = None,
project_id: str | None = None, luxonis_only: bool = False, limit: int = 50, sort: str = 'updated', order: Order = 'desc', field:
Annotated[list[str] | None, Parameter(name=['--field', '-f'])] = None):
```

列出 HubAI 中的模型。

### update_model

```python
def update_model(identifier: UUID | str, *, license_type: License | None = None, is_public: bool | None = None, description: str |
None = None, description_short: str | None = None, architecture_id: UUID | str | None = None, tasks: list[Task] | None = None,
links: list[str] | None = None, is_yolo: bool | None = None) -> ModelResponse:
```

更新现有模型上的字段。

只有值不为 `None` 的参数才会发送到 HubAI。这意味着无法使用此帮助程序清除可选文本字段。

参数

 * `identifier` (`UUID | str`): 模型 UUID、原始 slug 或 `<team>/<model>` 路径。
 * `license_type` (`License | None`): 替换许可证。
 * `is_public` (`bool | None`): 替换公开/私有状态。
 * `description` (`str | None`): 替换完整描述。
 * `description_short` (`str | None`): 替换简短描述。
 * `architecture_id` (`UUID | str | None`): 替换架构 UUID。
 * `tasks` (`list[Task] | None`): 替换任务列表。
 * `links` (`list[str] | None`): 替换相关资源链接。
 * `is_yolo` (`bool | None`): 替换 YOLO 标志。

返回

 * `ModelResponse`: 更新的模型资源。

### update_model_cli

```python
def update_model_cli(identifier: UUID | str, *, license_type: License | None = None, is_public: bool | None = None, description:
str | None = None, description_short: str | None = None, architecture_id: UUID | str | None = None, tasks: list[Task] | None =
None, links: list[str] | None = None, is_yolo: bool | None = None):
```

更新模型。

## 属性

### app

### MODEL_INFO_KEYS

### MODEL_LIST_KEYS
