intellif-aihub 0.1.3__py3-none-any.whl → 0.1.4__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.

Potentially problematic release.


This version of intellif-aihub might be problematic. Click here for more details.

Files changed (34) hide show
  1. aihub/__init__.py +1 -1
  2. aihub/client.py +95 -91
  3. aihub/exceptions.py +18 -18
  4. aihub/models/artifact.py +137 -137
  5. aihub/models/common.py +13 -13
  6. aihub/models/dataset_management.py +99 -99
  7. aihub/models/document_center.py +28 -28
  8. aihub/models/eval.py +17 -0
  9. aihub/models/labelfree.py +53 -31
  10. aihub/models/model_training_platform.py +234 -230
  11. aihub/models/quota_schedule_management.py +239 -0
  12. aihub/models/tag_resource_management.py +50 -50
  13. aihub/models/task_center.py +117 -117
  14. aihub/models/user_system.py +262 -262
  15. aihub/services/artifact.py +353 -353
  16. aihub/services/dataset_management.py +240 -240
  17. aihub/services/document_center.py +43 -43
  18. aihub/services/eval.py +68 -0
  19. aihub/services/labelfree.py +44 -44
  20. aihub/services/model_training_platform.py +209 -135
  21. aihub/services/quota_schedule_management.py +182 -18
  22. aihub/services/reporter.py +20 -20
  23. aihub/services/tag_resource_management.py +55 -55
  24. aihub/services/task_center.py +190 -190
  25. aihub/services/user_system.py +339 -339
  26. aihub/utils/download.py +69 -69
  27. aihub/utils/http.py +13 -13
  28. aihub/utils/s3.py +77 -77
  29. {intellif_aihub-0.1.3.dist-info → intellif_aihub-0.1.4.dist-info}/METADATA +1 -1
  30. intellif_aihub-0.1.4.dist-info/RECORD +36 -0
  31. {intellif_aihub-0.1.3.dist-info → intellif_aihub-0.1.4.dist-info}/licenses/LICENSE +200 -200
  32. intellif_aihub-0.1.3.dist-info/RECORD +0 -34
  33. {intellif_aihub-0.1.3.dist-info → intellif_aihub-0.1.4.dist-info}/WHEEL +0 -0
  34. {intellif_aihub-0.1.3.dist-info → intellif_aihub-0.1.4.dist-info}/top_level.txt +0 -0
aihub/__init__.py CHANGED
@@ -1 +1 @@
1
- __version__ = "0.1.3"
1
+ __version__ = "0.1.4"
aihub/client.py CHANGED
@@ -1,91 +1,95 @@
1
- from __future__ import annotations
2
-
3
- import os
4
-
5
- import httpx
6
-
7
- from .exceptions import APIError
8
- from .services import artifact
9
- from .services import dataset_management
10
- from .services import document_center
11
- from .services import labelfree
12
- from .services import model_training_platform
13
- from .services import tag_resource_management
14
- from .services import task_center
15
- from .services import user_system
16
- from .services.artifact import ArtifactService
17
- from .services.dataset_management import DatasetManagementService
18
- from .services.document_center import DocumentCenterService
19
- from .services.labelfree import LabelfreeService
20
- from .services.model_training_platform import ModelTrainingPlatformService
21
- from .services.tag_resource_management import TagResourceManagementService
22
- from .services.task_center import TaskCenterService
23
- from .services.user_system import UserSystemService
24
-
25
-
26
- class Client:
27
- """AI-HUB python SDK 客户端
28
-
29
- Attributes:
30
- dataset_management (DatasetManagementService): 数据集管理服务
31
- labelfree (LabelfreeService): 标注服务
32
- task_center (TaskCenterService): 任务中心
33
- artifact (ArtifactService): 制品管理
34
-
35
- """
36
-
37
- labelfree: LabelfreeService = None
38
- tag_resource_management: TagResourceManagementService = None
39
- document_center: DocumentCenterService = None
40
- task_center: TaskCenterService = None
41
- dataset_management: DatasetManagementService = None
42
- artifact: ArtifactService = None
43
- user_system: UserSystemService = None
44
- model_training_platform: ModelTrainingPlatformService = None
45
-
46
- def __init__(self, *, base_url: str, token: str | None = None, timeout: float = 60.0):
47
- """AI-HUB python SDK 客户端
48
-
49
- Args:
50
- base_url (str): 服务地址
51
- token (str): 密钥,显式传入,或在环境变量AI_HUB_TOKEN中设置
52
-
53
- Examples:
54
- >>> from aihub.client import Client
55
- >>> client = Client(base_url="xxx", token="xxxx")
56
-
57
- """
58
- if not base_url:
59
- raise ValueError("base_url必须填写")
60
-
61
- token = os.getenv("AI_HUB_TOKEN") or token
62
- if not token:
63
- raise ValueError("缺少token:请显式传入,或在环境变量AI_HUB_TOKEN中设置")
64
-
65
- self._http = httpx.Client(
66
- base_url=base_url.rstrip("/"),
67
- timeout=timeout,
68
- headers={"Authorization": f"Bearer {token}"},
69
- # event_hooks={"response": [self._raise_for_status]},
70
- )
71
- self.dataset_management = dataset_management.DatasetManagementService(self._http)
72
- self.labelfree = labelfree.LabelfreeService(self._http)
73
- self.tag_resource_management = tag_resource_management.TagResourceManagementService(self._http)
74
- self.document_center = document_center.DocumentCenterService(self._http)
75
- self.task_center = task_center.TaskCenterService(self._http)
76
- self.artifact = artifact.ArtifactService(self._http)
77
- self.user_system = user_system.UserSystemService(self._http)
78
- self.model_training_platform = model_training_platform.ModelTrainingPlatformService(self._http)
79
-
80
- @staticmethod
81
- def _raise_for_status(r: httpx.Response):
82
- try:
83
- r.raise_for_status()
84
- except httpx.HTTPStatusError as e:
85
- raise APIError(f"{e.response.status_code}: {e.response.text}") from e
86
-
87
- def __enter__(self):
88
- return self
89
-
90
- def __exit__(self, *a):
91
- self._http.close()
1
+ from __future__ import annotations
2
+
3
+ import os
4
+
5
+ import httpx
6
+
7
+ from .exceptions import APIError
8
+ from .services import artifact
9
+ from .services import dataset_management
10
+ from .services import document_center
11
+ from .services import labelfree
12
+ from .services import model_training_platform
13
+ from .services import quota_schedule_management
14
+ from .services import tag_resource_management
15
+ from .services import task_center
16
+ from .services import user_system
17
+ from .services.artifact import ArtifactService
18
+ from .services.dataset_management import DatasetManagementService
19
+ from .services.document_center import DocumentCenterService
20
+ from .services.labelfree import LabelfreeService
21
+ from .services.model_training_platform import ModelTrainingPlatformService
22
+ from .services.quota_schedule_management import QuotaScheduleManagementService
23
+ from .services.tag_resource_management import TagResourceManagementService
24
+ from .services.task_center import TaskCenterService
25
+ from .services.user_system import UserSystemService
26
+
27
+
28
+ class Client:
29
+ """AI-HUB python SDK 客户端
30
+
31
+ Attributes:
32
+ dataset_management (DatasetManagementService): 数据集管理服务
33
+ labelfree (LabelfreeService): 标注服务
34
+ task_center (TaskCenterService): 任务中心
35
+ artifact (ArtifactService): 制品管理
36
+
37
+ """
38
+
39
+ labelfree: LabelfreeService = None
40
+ tag_resource_management: TagResourceManagementService = None
41
+ document_center: DocumentCenterService = None
42
+ task_center: TaskCenterService = None
43
+ dataset_management: DatasetManagementService = None
44
+ artifact: ArtifactService = None
45
+ user_system: UserSystemService = None
46
+ model_training_platform: ModelTrainingPlatformService = None
47
+ quota_schedule_management: QuotaScheduleManagementService = None
48
+
49
+ def __init__(self, *, base_url: str, token: str | None = None, timeout: float = 60.0):
50
+ """AI-HUB python SDK 客户端
51
+
52
+ Args:
53
+ base_url (str): 服务地址
54
+ token (str): 密钥,显式传入,或在环境变量AI_HUB_TOKEN中设置
55
+
56
+ Examples:
57
+ >>> from aihub.client import Client
58
+ >>> client = Client(base_url="xxx", token="xxxx")
59
+
60
+ """
61
+ if not base_url:
62
+ raise ValueError("base_url必须填写")
63
+
64
+ token = os.getenv("AI_HUB_TOKEN") or token
65
+ if not token:
66
+ raise ValueError("缺少token:请显式传入,或在环境变量AI_HUB_TOKEN中设置")
67
+
68
+ self._http = httpx.Client(
69
+ base_url=base_url.rstrip("/"),
70
+ timeout=timeout,
71
+ headers={"Authorization": f"Bearer {token}"},
72
+ # event_hooks={"response": [self._raise_for_status]},
73
+ )
74
+ self.dataset_management = dataset_management.DatasetManagementService(self._http)
75
+ self.labelfree = labelfree.LabelfreeService(self._http)
76
+ self.tag_resource_management = tag_resource_management.TagResourceManagementService(self._http)
77
+ self.document_center = document_center.DocumentCenterService(self._http)
78
+ self.task_center = task_center.TaskCenterService(self._http)
79
+ self.artifact = artifact.ArtifactService(self._http)
80
+ self.user_system = user_system.UserSystemService(self._http)
81
+ self.model_training_platform = model_training_platform.ModelTrainingPlatformService(self._http)
82
+ self.quota_schedule_management = quota_schedule_management.QuotaScheduleManagementService(self._http)
83
+
84
+ @staticmethod
85
+ def _raise_for_status(r: httpx.Response):
86
+ try:
87
+ r.raise_for_status()
88
+ except httpx.HTTPStatusError as e:
89
+ raise APIError(f"{e.response.status_code}: {e.response.text}") from e
90
+
91
+ def __enter__(self):
92
+ return self
93
+
94
+ def __exit__(self, *a):
95
+ self._http.close()
aihub/exceptions.py CHANGED
@@ -1,18 +1,18 @@
1
- from __future__ import annotations
2
-
3
- from typing import Any, Optional
4
-
5
-
6
- class SDKError(Exception):
7
- pass
8
-
9
-
10
- class APIError(SDKError):
11
- def __init__(self, message: str, *, status: Optional[int] = None, detail: Any = None) -> None:
12
- super().__init__(message)
13
- self.message: str = message
14
- self.status: Optional[int] = status
15
- self.detail: Any = detail
16
-
17
- def __str__(self) -> str:
18
- return f"[HTTP {self.status}] {self.message}" if self.status else self.message
1
+ from __future__ import annotations
2
+
3
+ from typing import Any, Optional
4
+
5
+
6
+ class SDKError(Exception):
7
+ pass
8
+
9
+
10
+ class APIError(SDKError):
11
+ def __init__(self, message: str, *, status: Optional[int] = None, detail: Any = None) -> None:
12
+ super().__init__(message)
13
+ self.message: str = message
14
+ self.status: Optional[int] = status
15
+ self.detail: Any = detail
16
+
17
+ def __str__(self) -> str:
18
+ return f"[HTTP {self.status}] {self.message}" if self.status else self.message
aihub/models/artifact.py CHANGED
@@ -1,137 +1,137 @@
1
- # !/usr/bin/env python
2
- # -*-coding:utf-8 -*-
3
- """制品管理模型模块
4
-
5
- 该模块定义了制品管理相关的数据模型,包括制品类型、创建制品请求、制品响应等。
6
- """
7
- from __future__ import annotations
8
-
9
- from enum import Enum
10
- from typing import List, Optional
11
-
12
- from pydantic import BaseModel
13
-
14
-
15
- class ArtifactType(str, Enum):
16
- """制品类型枚举
17
-
18
- 定义了系统支持的各种制品类型。
19
- """
20
-
21
- dataset = "dataset" # 数据集类型
22
- model = "model" # 模型类型
23
- metrics = "metrics" # 指标类型
24
- log = "log" # 日志类型
25
- checkpoint = "checkpoint" # 检查点类型
26
- image = "image" # 图像类型
27
- prediction = "prediction" # 预测结果类型
28
- other = "other" # 其他类型
29
-
30
-
31
- class CreateArtifactsReq(BaseModel):
32
- """创建制品请求模型
33
-
34
- 用于向服务器发送创建制品的请求。
35
- """
36
-
37
- entity_id: str
38
- """实体ID,通常是运行ID,用于关联制品与特定运行"""
39
-
40
- entity_type: ArtifactType = ArtifactType.other
41
- """制品类型,指定制品的类型,默认为other"""
42
-
43
- src_path: str
44
- """源路径,制品在系统中的路径标识"""
45
-
46
- is_dir: bool = False
47
- """是否为目录,True表示制品是一个目录,False表示是单个文件"""
48
-
49
-
50
- class CreateArtifactsResponseData(BaseModel):
51
- """创建制品响应数据模型
52
-
53
- 服务器创建制品后返回的数据。
54
- """
55
-
56
- id: int # 制品ID
57
- s3_path: str # S3存储路径
58
-
59
-
60
- class CreateArtifactsResponseModel(BaseModel):
61
- """创建制品响应模型
62
-
63
- 服务器对创建制品请求的完整响应。
64
- """
65
-
66
- code: int # 响应码,0表示成功
67
- msg: str = "" # 响应消息
68
- data: CreateArtifactsResponseData | None = None # 响应数据
69
-
70
-
71
- class CreatEvalReq(BaseModel):
72
- """创建评估请求模型
73
-
74
- 用于创建模型评估的请求。
75
- """
76
-
77
- dataset_id: int # 数据集ID
78
- dataset_version_id: int # 数据集版本ID
79
- prediction_artifact_path: str # 预测结果制品路径
80
- evaled_artifact_path: str # 评估结果制品路径
81
- run_id: str # 运行ID
82
- user_id: int # 用户ID
83
- report: dict = {} # 评估报告
84
-
85
-
86
- class ArtifactResp(BaseModel):
87
- """制品响应模型
88
-
89
- 表示一个制品的详细信息。
90
- """
91
-
92
- id: int # 制品ID
93
- entity_type: str # 实体类型
94
- entity_id: str # 实体ID
95
- src_path: str # 源路径
96
- s3_path: str # S3存储路径
97
- is_dir: bool # 是否为目录
98
-
99
-
100
- class ArtifactRespData(BaseModel):
101
- """制品响应数据模型
102
-
103
- 包含分页信息和制品列表的响应数据。
104
- """
105
-
106
- total: int # 总记录数
107
- page_size: int # 每页大小
108
- page_num: int # 页码
109
- data: List[ArtifactResp] # 制品列表
110
-
111
-
112
- class ArtifactRespModel(BaseModel):
113
- """制品响应模型
114
-
115
- 服务器对获取制品请求的完整响应。
116
- """
117
-
118
- code: int # 响应码,0表示成功
119
- msg: str = "" # 响应消息
120
- data: ArtifactRespData # 响应数据
121
-
122
-
123
- # 无限大的页面大小,用于一次性获取所有制品
124
- InfinityPageSize = 10000 * 100
125
-
126
-
127
- class StsResp(BaseModel):
128
- """STS临时凭证响应模型
129
-
130
- 包含访问S3存储所需的临时凭证信息。
131
- """
132
-
133
- access_key_id: Optional[str] = None # 访问密钥ID
134
- secret_access_key: Optional[str] = None # 秘密访问密钥
135
- session_token: Optional[str] = None # 会话令牌
136
- expiration: Optional[int] = None # 过期时间
137
- endpoint: Optional[str] = None # 端点URL
1
+ # !/usr/bin/env python
2
+ # -*-coding:utf-8 -*-
3
+ """制品管理模型模块
4
+
5
+ 该模块定义了制品管理相关的数据模型,包括制品类型、创建制品请求、制品响应等。
6
+ """
7
+ from __future__ import annotations
8
+
9
+ from enum import Enum
10
+ from typing import List, Optional
11
+
12
+ from pydantic import BaseModel
13
+
14
+
15
+ class ArtifactType(str, Enum):
16
+ """制品类型枚举
17
+
18
+ 定义了系统支持的各种制品类型。
19
+ """
20
+
21
+ dataset = "dataset" # 数据集类型
22
+ model = "model" # 模型类型
23
+ metrics = "metrics" # 指标类型
24
+ log = "log" # 日志类型
25
+ checkpoint = "checkpoint" # 检查点类型
26
+ image = "image" # 图像类型
27
+ prediction = "prediction" # 预测结果类型
28
+ other = "other" # 其他类型
29
+
30
+
31
+ class CreateArtifactsReq(BaseModel):
32
+ """创建制品请求模型
33
+
34
+ 用于向服务器发送创建制品的请求。
35
+ """
36
+
37
+ entity_id: str
38
+ """实体ID,通常是运行ID,用于关联制品与特定运行"""
39
+
40
+ entity_type: ArtifactType = ArtifactType.other
41
+ """制品类型,指定制品的类型,默认为other"""
42
+
43
+ src_path: str
44
+ """源路径,制品在系统中的路径标识"""
45
+
46
+ is_dir: bool = False
47
+ """是否为目录,True表示制品是一个目录,False表示是单个文件"""
48
+
49
+
50
+ class CreateArtifactsResponseData(BaseModel):
51
+ """创建制品响应数据模型
52
+
53
+ 服务器创建制品后返回的数据。
54
+ """
55
+
56
+ id: int # 制品ID
57
+ s3_path: str # S3存储路径
58
+
59
+
60
+ class CreateArtifactsResponseModel(BaseModel):
61
+ """创建制品响应模型
62
+
63
+ 服务器对创建制品请求的完整响应。
64
+ """
65
+
66
+ code: int # 响应码,0表示成功
67
+ msg: str = "" # 响应消息
68
+ data: CreateArtifactsResponseData | None = None # 响应数据
69
+
70
+
71
+ class CreatEvalReq(BaseModel):
72
+ """创建评估请求模型
73
+
74
+ 用于创建模型评估的请求。
75
+ """
76
+
77
+ dataset_id: int # 数据集ID
78
+ dataset_version_id: int # 数据集版本ID
79
+ prediction_artifact_path: str # 预测结果制品路径
80
+ evaled_artifact_path: str # 评估结果制品路径
81
+ run_id: str # 运行ID
82
+ user_id: int # 用户ID
83
+ report: dict = {} # 评估报告
84
+
85
+
86
+ class ArtifactResp(BaseModel):
87
+ """制品响应模型
88
+
89
+ 表示一个制品的详细信息。
90
+ """
91
+
92
+ id: int # 制品ID
93
+ entity_type: str # 实体类型
94
+ entity_id: str # 实体ID
95
+ src_path: str # 源路径
96
+ s3_path: str # S3存储路径
97
+ is_dir: bool # 是否为目录
98
+
99
+
100
+ class ArtifactRespData(BaseModel):
101
+ """制品响应数据模型
102
+
103
+ 包含分页信息和制品列表的响应数据。
104
+ """
105
+
106
+ total: int # 总记录数
107
+ page_size: int # 每页大小
108
+ page_num: int # 页码
109
+ data: List[ArtifactResp] # 制品列表
110
+
111
+
112
+ class ArtifactRespModel(BaseModel):
113
+ """制品响应模型
114
+
115
+ 服务器对获取制品请求的完整响应。
116
+ """
117
+
118
+ code: int # 响应码,0表示成功
119
+ msg: str = "" # 响应消息
120
+ data: ArtifactRespData # 响应数据
121
+
122
+
123
+ # 无限大的页面大小,用于一次性获取所有制品
124
+ InfinityPageSize = 10000 * 100
125
+
126
+
127
+ class StsResp(BaseModel):
128
+ """STS临时凭证响应模型
129
+
130
+ 包含访问S3存储所需的临时凭证信息。
131
+ """
132
+
133
+ access_key_id: Optional[str] = None # 访问密钥ID
134
+ secret_access_key: Optional[str] = None # 秘密访问密钥
135
+ session_token: Optional[str] = None # 会话令牌
136
+ expiration: Optional[int] = None # 过期时间
137
+ endpoint: Optional[str] = None # 端点URL
aihub/models/common.py CHANGED
@@ -1,13 +1,13 @@
1
- from __future__ import annotations
2
-
3
- from typing import Generic, Optional, TypeVar
4
-
5
- from pydantic import BaseModel
6
-
7
- T = TypeVar("T")
8
-
9
-
10
- class APIWrapper(BaseModel, Generic[T]):
11
- code: int
12
- msg: Optional[str] = None
13
- data: Optional[T]
1
+ from __future__ import annotations
2
+
3
+ from typing import Generic, Optional, TypeVar
4
+
5
+ from pydantic import BaseModel
6
+
7
+ T = TypeVar("T")
8
+
9
+
10
+ class APIWrapper(BaseModel, Generic[T]):
11
+ code: int
12
+ msg: Optional[str] = None
13
+ data: Optional[T]