intellif-aihub 0.1.21__py3-none-any.whl → 0.1.23__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.
- aihub/__init__.py +1 -1
- aihub/cli/__init__.py +1 -0
- aihub/cli/__main__.py +8 -0
- aihub/cli/config.py +136 -0
- aihub/cli/main.py +295 -0
- aihub/cli/model_center.py +355 -0
- aihub/models/eval.py +31 -0
- aihub/models/model_center.py +80 -111
- aihub/models/task_center.py +1 -0
- aihub/models/user_system.py +1 -1
- aihub/services/eval.py +59 -9
- aihub/services/model_center.py +202 -54
- aihub/services/task_center.py +3 -0
- aihub/services/user_system.py +26 -9
- aihub/utils/s3.py +49 -6
- {intellif_aihub-0.1.21.dist-info → intellif_aihub-0.1.23.dist-info}/METADATA +2 -1
- {intellif_aihub-0.1.21.dist-info → intellif_aihub-0.1.23.dist-info}/RECORD +21 -15
- intellif_aihub-0.1.23.dist-info/entry_points.txt +2 -0
- {intellif_aihub-0.1.21.dist-info → intellif_aihub-0.1.23.dist-info}/WHEEL +0 -0
- {intellif_aihub-0.1.21.dist-info → intellif_aihub-0.1.23.dist-info}/licenses/LICENSE +0 -0
- {intellif_aihub-0.1.21.dist-info → intellif_aihub-0.1.23.dist-info}/top_level.txt +0 -0
aihub/models/model_center.py
CHANGED
|
@@ -1,112 +1,74 @@
|
|
|
1
1
|
from __future__ import annotations
|
|
2
2
|
|
|
3
|
-
from enum import IntEnum
|
|
4
3
|
from typing import List, Optional
|
|
5
4
|
|
|
6
|
-
from pydantic import BaseModel, Field, ConfigDict
|
|
5
|
+
from pydantic import BaseModel, Field, ConfigDict, field_validator
|
|
7
6
|
|
|
8
7
|
|
|
9
|
-
class
|
|
10
|
-
"""
|
|
8
|
+
class ListModelCard(BaseModel):
|
|
9
|
+
"""模型卡片"""
|
|
11
10
|
|
|
12
|
-
id: int = Field(description="
|
|
13
|
-
name: str = Field(description="
|
|
11
|
+
id: int = Field(alias="id", description="模型ID")
|
|
12
|
+
name: str = Field(alias="name", description="名称")
|
|
13
|
+
description: str = Field(alias="description", description="描述")
|
|
14
|
+
creator_id: int = Field(alias="creator_id", description="创建人ID")
|
|
15
|
+
creator_name: str = Field(alias="creator_name", description="创建人名称")
|
|
16
|
+
created_at: int = Field(alias="created_at", description="创建时间戳")
|
|
17
|
+
updated_at: int = Field(alias="updated_at", description="更新时间戳")
|
|
18
|
+
tags: List[int] = Field(default_factory=list, alias="tags", description="标签ID集合")
|
|
19
|
+
status: str = Field(alias="status", description="状态")
|
|
20
|
+
is_public: bool = Field(alias="is_public", description="是否公开")
|
|
14
21
|
|
|
22
|
+
@field_validator("tags", mode="before")
|
|
23
|
+
@classmethod
|
|
24
|
+
def _none_to_empty_list(cls, v):
|
|
25
|
+
return [] if v is None else v
|
|
15
26
|
|
|
16
|
-
|
|
17
|
-
"""模型类型"""
|
|
18
|
-
|
|
19
|
-
id: int = Field(description="类型ID")
|
|
20
|
-
name: str = Field(description="类型名称")
|
|
27
|
+
model_config = ConfigDict(protected_namespaces=())
|
|
21
28
|
|
|
22
29
|
|
|
23
|
-
class
|
|
24
|
-
"""
|
|
30
|
+
class ModelTreeNode(BaseModel):
|
|
31
|
+
"""模型树节点"""
|
|
25
32
|
|
|
26
|
-
|
|
27
|
-
name: str = Field(description="
|
|
33
|
+
model_id: int = Field(alias="model_id", description="模型ID")
|
|
34
|
+
name: str = Field(alias="name", description="名称")
|
|
35
|
+
relationship: str = Field(alias="relationship", description="与基模型关系")
|
|
28
36
|
|
|
37
|
+
model_config = ConfigDict(protected_namespaces=())
|
|
29
38
|
|
|
30
|
-
class QuantLevel(BaseModel):
|
|
31
|
-
"""量化等级"""
|
|
32
39
|
|
|
33
|
-
|
|
34
|
-
|
|
40
|
+
class ModelCardDetail(ListModelCard):
|
|
41
|
+
"""模型卡片详情"""
|
|
35
42
|
|
|
43
|
+
readme_content: str = Field(alias="readme_content", description="README 内容")
|
|
44
|
+
model_tree: Optional[List[ModelTreeNode]] = Field(default=None, alias="model_tree", description="模型树")
|
|
45
|
+
base_model: Optional[ModelTreeNode] = Field(default=None, alias="base_model", description="基模型")
|
|
46
|
+
file_storage_path: Optional[str] = Field(alias="file_storage_path", description="文件存储路径")
|
|
36
47
|
|
|
37
|
-
|
|
38
|
-
"""模型状态:1-Waiting;2-Creating;3-Success;4-Fail"""
|
|
39
|
-
Waiting = 1
|
|
40
|
-
Creating = 2
|
|
41
|
-
Success = 3
|
|
42
|
-
Fail = 4
|
|
48
|
+
model_config = ConfigDict(protected_namespaces=())
|
|
43
49
|
|
|
44
50
|
|
|
45
|
-
class
|
|
46
|
-
"""
|
|
51
|
+
class ModelDb(BaseModel):
|
|
52
|
+
"""模型"""
|
|
47
53
|
|
|
48
|
-
id: int = Field(description="
|
|
49
|
-
name: str = Field(description="
|
|
54
|
+
id: int = Field(description="ID")
|
|
55
|
+
name: str = Field(description="名称")
|
|
50
56
|
description: str = Field(description="描述")
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
"""
|
|
66
|
-
|
|
67
|
-
page_size: int = Field(999, alias="page_size", description="每页数量")
|
|
68
|
-
page_num: int = Field(1, alias="page_num", description="当前页码")
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
class ListModelTypesResponse(BaseModel):
|
|
72
|
-
"""查询模型类型列表返回"""
|
|
73
|
-
|
|
74
|
-
total: int = Field(description="总条数")
|
|
75
|
-
page_size: int = Field(alias="page_size", description="每页数量")
|
|
76
|
-
page_num: int = Field(alias="page_num", description="当前页码")
|
|
77
|
-
data: List[ModelType] = Field(default_factory=list, description="类型列表")
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
class ListDeployPlatformsRequest(BaseModel):
|
|
81
|
-
"""查询部署平台列表请求"""
|
|
82
|
-
|
|
83
|
-
page_size: int = Field(999, alias="page_size", description="每页数量")
|
|
84
|
-
page_num: int = Field(1, alias="page_num", description="当前页码")
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
class ListDeployPlatformsResponse(BaseModel):
|
|
88
|
-
"""查询部署平台列表返回"""
|
|
89
|
-
|
|
90
|
-
total: int = Field(description="总条数")
|
|
91
|
-
page_size: int = Field(alias="page_size", description="每页数量")
|
|
92
|
-
page_num: int = Field(alias="page_num", description="当前页码")
|
|
93
|
-
data: List[DeployPlatform] = Field(default_factory=list, description="平台列表")
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
class ListQuantLevelsRequest(BaseModel):
|
|
97
|
-
"""查询量化等级列表请求"""
|
|
98
|
-
|
|
99
|
-
page_size: int = Field(999, alias="page_size", description="每页数量")
|
|
100
|
-
page_num: int = Field(1, alias="page_num", description="当前页码")
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
class ListQuantLevelsResponse(BaseModel):
|
|
104
|
-
"""查询量化等级列表返回"""
|
|
105
|
-
|
|
106
|
-
total: int = Field(description="总条数")
|
|
107
|
-
page_size: int = Field(alias="page_size", description="每页数量")
|
|
108
|
-
page_num: int = Field(alias="page_num", description="当前页码")
|
|
109
|
-
data: List[QuantLevel] = Field(default_factory=list, description="量化等级列表")
|
|
57
|
+
readme_content: str = Field(alias="readme_content", description="README")
|
|
58
|
+
user_id: int = Field(alias="user_id", description="创建人ID")
|
|
59
|
+
status: str = Field(description="状态")
|
|
60
|
+
is_public: bool = Field(alias="is_public", description="是否公开")
|
|
61
|
+
base_model_id: int = Field(alias="base_model_id", description="基模型ID")
|
|
62
|
+
relation: str = Field(description="与基模型关系")
|
|
63
|
+
object_cnt: int = Field(alias="object_cnt", description="对象数量")
|
|
64
|
+
data_size: int = Field(alias="data_size", description="数据大小")
|
|
65
|
+
object_storage_path: str = Field(alias="object_storage_path", description="对象存储路径")
|
|
66
|
+
file_storage_path: str = Field(alias="file_storage_path", description="文件存储路径")
|
|
67
|
+
parquet_index_path: str = Field(alias="parquet_index_path", description="Parquet 索引路径")
|
|
68
|
+
csv_file_path: str = Field(alias="csv_file_path", description="CSV 文件路径")
|
|
69
|
+
task_status_s3_path: str = Field(alias="task_status_s3_path", description="任务状态S3路径")
|
|
70
|
+
created_at: int = Field(alias="created_at", description="创建时间戳")
|
|
71
|
+
updated_at: int = Field(alias="updated_at", description="更新时间戳")
|
|
110
72
|
|
|
111
73
|
|
|
112
74
|
class ListModelsRequest(BaseModel):
|
|
@@ -114,46 +76,53 @@ class ListModelsRequest(BaseModel):
|
|
|
114
76
|
|
|
115
77
|
page_size: int = Field(20, alias="page_size", description="每页数量")
|
|
116
78
|
page_num: int = Field(1, alias="page_num", description="当前页码")
|
|
117
|
-
name: Optional[str] = Field(None, description="名称过滤")
|
|
79
|
+
name: Optional[str] = Field(default=None, alias="name", description="名称过滤")
|
|
80
|
+
tags: Optional[str] = Field(default=None, alias="tags", description="标签过滤")
|
|
81
|
+
model_ids: Optional[str] = Field(default=None, alias="model_ids", description="模型ID过滤")
|
|
82
|
+
|
|
83
|
+
model_config = ConfigDict(protected_namespaces=())
|
|
118
84
|
|
|
119
85
|
|
|
120
86
|
class ListModelsResponse(BaseModel):
|
|
121
87
|
"""查询模型列表返回"""
|
|
122
88
|
|
|
123
|
-
total: int = Field(description="总条数")
|
|
89
|
+
total: int = Field(alias="total", description="总条数")
|
|
124
90
|
page_size: int = Field(alias="page_size", description="每页数量")
|
|
125
91
|
page_num: int = Field(alias="page_num", description="当前页码")
|
|
126
|
-
data: List[
|
|
92
|
+
data: List[ListModelCard] = Field(default_factory=list, alias="data", description="模型卡片列表")
|
|
93
|
+
|
|
94
|
+
model_config = ConfigDict(protected_namespaces=())
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
class GetModelRequest(BaseModel):
|
|
98
|
+
"""查询模型详情请求"""
|
|
99
|
+
|
|
100
|
+
id: int = Field(alias="id", description="模型ID")
|
|
127
101
|
|
|
128
102
|
|
|
129
103
|
class CreateModelRequest(BaseModel):
|
|
130
104
|
"""创建模型请求"""
|
|
131
105
|
|
|
132
|
-
name: str = Field(description="
|
|
133
|
-
description: Optional[str] = Field(None, description="描述")
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
param_cnt: Optional[str] = Field(None, alias="param_cnt", description="参数量")
|
|
138
|
-
quant_level_id: Optional[int] = Field(None, alias="quant_level_id", description="量化等级ID")
|
|
139
|
-
model_config = ConfigDict(protected_namespaces=())
|
|
106
|
+
name: str = Field(alias="name", description="名称")
|
|
107
|
+
description: Optional[str] = Field(default=None, alias="description", description="描述")
|
|
108
|
+
tags: Optional[str] = Field(default=None, alias="tags", description="标签")
|
|
109
|
+
is_public: bool = Field(alias="is_public", description="是否公开")
|
|
110
|
+
readme_content: Optional[str] = Field(default=None, description="README 文本内容")
|
|
140
111
|
|
|
141
112
|
|
|
142
113
|
class CreateModelResponse(BaseModel):
|
|
143
|
-
"""
|
|
144
|
-
|
|
145
|
-
id: int = Field(description="模型ID")
|
|
114
|
+
id: int = Field(alias="id", description="模型ID")
|
|
146
115
|
|
|
147
116
|
|
|
148
117
|
class EditModelRequest(BaseModel):
|
|
149
118
|
"""编辑模型请求"""
|
|
150
119
|
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
120
|
+
name: Optional[str] = Field(default=None, alias="name", description="名称")
|
|
121
|
+
description: Optional[str] = Field(default=None, alias="description", description="描述")
|
|
122
|
+
is_public: Optional[bool] = Field(default=None, alias="is_public", description="是否公开")
|
|
123
|
+
|
|
124
|
+
|
|
125
|
+
class EditModelResponse(BaseModel):
|
|
126
|
+
"""编辑模型返回"""
|
|
127
|
+
|
|
128
|
+
pass
|
aihub/models/task_center.py
CHANGED
|
@@ -42,6 +42,7 @@ class CreateTaskOtherInfo(BaseModel):
|
|
|
42
42
|
doc_type: str = Field(alias="doc_type", default="doc_center", description="文档类型")
|
|
43
43
|
|
|
44
44
|
model_config = {"use_enum_values": True}
|
|
45
|
+
auto_valid_interval: int = Field(3, description="自动验收间隔")
|
|
45
46
|
|
|
46
47
|
|
|
47
48
|
class ProjectInfo(BaseModel):
|
aihub/models/user_system.py
CHANGED
|
@@ -328,7 +328,7 @@ class SearchUsersResponse(BaseModel):
|
|
|
328
328
|
total: int = Field(description="总数")
|
|
329
329
|
page_size: int = Field(alias="page_size", description="单页条数")
|
|
330
330
|
page_num: int = Field(alias="page_num", description="当前页")
|
|
331
|
-
data: List[User] = Field(description="用户列表")
|
|
331
|
+
data: Optional[List[User]] = Field(description="用户列表")
|
|
332
332
|
|
|
333
333
|
|
|
334
334
|
# 此行放在文件末尾,否则序列化报错
|
aihub/services/eval.py
CHANGED
|
@@ -7,12 +7,21 @@
|
|
|
7
7
|
- **创建评测任务 / 评测报告**
|
|
8
8
|
- **获取评测任务列表**
|
|
9
9
|
"""
|
|
10
|
+
from typing import List
|
|
10
11
|
|
|
11
12
|
import httpx
|
|
12
13
|
|
|
13
14
|
from ..exceptions import APIError
|
|
14
15
|
from ..models.common import APIWrapper
|
|
15
|
-
from ..models.eval import
|
|
16
|
+
from ..models.eval import (
|
|
17
|
+
CreateLLMEvalReq,
|
|
18
|
+
CreateCVEvalReq,
|
|
19
|
+
CreateEvalResp,
|
|
20
|
+
ListEvalReq,
|
|
21
|
+
ListEvalResp,
|
|
22
|
+
GrantPermissionReq,
|
|
23
|
+
ClientType,
|
|
24
|
+
)
|
|
16
25
|
|
|
17
26
|
_BASE = "/eval-platform/api/v1"
|
|
18
27
|
|
|
@@ -32,16 +41,20 @@ class EvalService:
|
|
|
32
41
|
report_json: dict,
|
|
33
42
|
run_id,
|
|
34
43
|
user_id: int = 0,
|
|
44
|
+
is_public: bool = False,
|
|
45
|
+
access_user_ids: List[int] = None,
|
|
35
46
|
) -> int:
|
|
36
47
|
"""创建评测报告
|
|
37
48
|
|
|
38
49
|
Args:
|
|
50
|
+
is_public (bool): 是否公开
|
|
39
51
|
run_id (str): RUN ID
|
|
40
52
|
report_json (dict): 报告内容
|
|
41
53
|
evaled_artifact_path: 评测结果制品路径
|
|
42
54
|
prediction_artifact_path: 推理结果制品路径
|
|
43
55
|
dataset_version_name (str): 数据集名称
|
|
44
56
|
user_id (int, optional): 用户ID,默认为0
|
|
57
|
+
access_user_ids (list): 授权访问的用户id
|
|
45
58
|
|
|
46
59
|
Returns:
|
|
47
60
|
id (int): 评测报告id
|
|
@@ -50,9 +63,7 @@ class EvalService:
|
|
|
50
63
|
from .dataset_management import DatasetManagementService
|
|
51
64
|
|
|
52
65
|
dataset_service = DatasetManagementService(self._http)
|
|
53
|
-
dataset_version = dataset_service.get_dataset_version_by_name(
|
|
54
|
-
dataset_version_name
|
|
55
|
-
)
|
|
66
|
+
dataset_version = dataset_service.get_dataset_version_by_name(dataset_version_name)
|
|
56
67
|
payload = CreateLLMEvalReq(
|
|
57
68
|
dataset_id=dataset_version.dataset_id,
|
|
58
69
|
dataset_version_id=dataset_version.id,
|
|
@@ -61,9 +72,15 @@ class EvalService:
|
|
|
61
72
|
report=report_json,
|
|
62
73
|
run_id=run_id,
|
|
63
74
|
user_id=user_id,
|
|
75
|
+
is_public=is_public,
|
|
76
|
+
type="llm",
|
|
77
|
+
client_type=ClientType.Workflow,
|
|
64
78
|
)
|
|
79
|
+
resp = self._eval.create(payload)
|
|
80
|
+
if is_public is False and access_user_ids:
|
|
81
|
+
self.grant_permission(user_ids=access_user_ids, run_id=resp)
|
|
65
82
|
|
|
66
|
-
return
|
|
83
|
+
return resp
|
|
67
84
|
|
|
68
85
|
def create_cv_run(
|
|
69
86
|
self,
|
|
@@ -72,16 +89,21 @@ class EvalService:
|
|
|
72
89
|
metrics_artifact_path: str,
|
|
73
90
|
ground_truth_artifact_path: str,
|
|
74
91
|
user_id: int = 0,
|
|
92
|
+
is_public: bool = False,
|
|
93
|
+
access_user_ids: List[int] = None,
|
|
75
94
|
) -> int:
|
|
76
95
|
"""创建 CV 类型评测运行
|
|
77
|
-
|
|
96
|
+
|
|
78
97
|
Args:
|
|
98
|
+
access_user_ids: 授权访问的用户ID
|
|
99
|
+
is_public (bool): 是否公开
|
|
79
100
|
run_id (str): 运行ID
|
|
80
101
|
prediction_artifact_path (str): 推理产物的路径
|
|
81
102
|
metrics_artifact_path (str): 指标产物的路径
|
|
82
103
|
ground_truth_artifact_path (str): 真实标签产物的路径
|
|
83
104
|
user_id (int, optional): 用户ID,默认为0
|
|
84
|
-
|
|
105
|
+
access_user_ids (list): 授权访问的用户id
|
|
106
|
+
|
|
85
107
|
Returns:
|
|
86
108
|
id (int): 评测运行id
|
|
87
109
|
"""
|
|
@@ -91,9 +113,15 @@ class EvalService:
|
|
|
91
113
|
metrics_artifact_path=metrics_artifact_path,
|
|
92
114
|
ground_truth_artifact_path=ground_truth_artifact_path,
|
|
93
115
|
user_id=user_id,
|
|
116
|
+
is_public=is_public,
|
|
117
|
+
type="cv",
|
|
118
|
+
client_type=ClientType.Workflow,
|
|
94
119
|
)
|
|
95
|
-
|
|
96
|
-
|
|
120
|
+
resp = self._eval.create(payload)
|
|
121
|
+
if is_public is False and access_user_ids:
|
|
122
|
+
self.grant_permission(user_ids=access_user_ids, run_id=resp)
|
|
123
|
+
|
|
124
|
+
return resp
|
|
97
125
|
|
|
98
126
|
def list(
|
|
99
127
|
self,
|
|
@@ -146,6 +174,21 @@ class EvalService:
|
|
|
146
174
|
|
|
147
175
|
return self._eval.list(payload)
|
|
148
176
|
|
|
177
|
+
def grant_permission(self, user_ids: List[int], run_id: int):
|
|
178
|
+
"""授权访问
|
|
179
|
+
|
|
180
|
+
Args:
|
|
181
|
+
user_ids (list): 授权信息
|
|
182
|
+
run_id (int): 任务ID
|
|
183
|
+
|
|
184
|
+
Returns:
|
|
185
|
+
dict: 授权信息
|
|
186
|
+
"""
|
|
187
|
+
req = GrantPermissionReq(
|
|
188
|
+
user_ids=user_ids,
|
|
189
|
+
)
|
|
190
|
+
return self._eval.grant_permission(req, run_id)
|
|
191
|
+
|
|
149
192
|
|
|
150
193
|
class _Eval:
|
|
151
194
|
def __init__(self, http: httpx.Client):
|
|
@@ -158,6 +201,13 @@ class _Eval:
|
|
|
158
201
|
raise APIError(f"backend code {wrapper.code}: {wrapper.msg}")
|
|
159
202
|
return wrapper.data.eval_run.id
|
|
160
203
|
|
|
204
|
+
def grant_permission(self, payload, task_id):
|
|
205
|
+
resp = self._http.post(f"{_BASE}/run/{task_id}/permissions", json=payload.model_dump())
|
|
206
|
+
wrapper = APIWrapper[CreateEvalResp].model_validate(resp.json())
|
|
207
|
+
if wrapper.code != 0:
|
|
208
|
+
raise APIError(f"backend code {wrapper.code}: {wrapper.msg}")
|
|
209
|
+
return wrapper.data
|
|
210
|
+
|
|
161
211
|
def list(self, payload: ListEvalReq) -> ListEvalResp:
|
|
162
212
|
# Build query parameters, excluding None values
|
|
163
213
|
params = {}
|