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.
- aihub/__init__.py +1 -1
- aihub/client.py +95 -91
- aihub/exceptions.py +18 -18
- aihub/models/artifact.py +137 -137
- aihub/models/common.py +13 -13
- aihub/models/dataset_management.py +99 -99
- aihub/models/document_center.py +28 -28
- aihub/models/eval.py +17 -0
- aihub/models/labelfree.py +53 -31
- aihub/models/model_training_platform.py +234 -230
- aihub/models/quota_schedule_management.py +239 -0
- aihub/models/tag_resource_management.py +50 -50
- aihub/models/task_center.py +117 -117
- aihub/models/user_system.py +262 -262
- aihub/services/artifact.py +353 -353
- aihub/services/dataset_management.py +240 -240
- aihub/services/document_center.py +43 -43
- aihub/services/eval.py +68 -0
- aihub/services/labelfree.py +44 -44
- aihub/services/model_training_platform.py +209 -135
- aihub/services/quota_schedule_management.py +182 -18
- aihub/services/reporter.py +20 -20
- aihub/services/tag_resource_management.py +55 -55
- aihub/services/task_center.py +190 -190
- aihub/services/user_system.py +339 -339
- aihub/utils/download.py +69 -69
- aihub/utils/http.py +13 -13
- aihub/utils/s3.py +77 -77
- {intellif_aihub-0.1.3.dist-info → intellif_aihub-0.1.4.dist-info}/METADATA +1 -1
- intellif_aihub-0.1.4.dist-info/RECORD +36 -0
- {intellif_aihub-0.1.3.dist-info → intellif_aihub-0.1.4.dist-info}/licenses/LICENSE +200 -200
- intellif_aihub-0.1.3.dist-info/RECORD +0 -34
- {intellif_aihub-0.1.3.dist-info → intellif_aihub-0.1.4.dist-info}/WHEEL +0 -0
- {intellif_aihub-0.1.3.dist-info → intellif_aihub-0.1.4.dist-info}/top_level.txt +0 -0
aihub/services/reporter.py
CHANGED
|
@@ -1,20 +1,20 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
import json
|
|
4
|
-
import os
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
class ReportService:
|
|
8
|
-
@staticmethod
|
|
9
|
-
def report_envs():
|
|
10
|
-
pod_namespace = os.environ.get('POD_NAMESPACE', '')
|
|
11
|
-
pod_name = os.environ.get('POD_NAME', '')
|
|
12
|
-
if not pod_namespace or not pod_name:
|
|
13
|
-
return
|
|
14
|
-
env_file_path = f'/var/mtp/log/{pod_namespace}/{pod_name}/env'
|
|
15
|
-
try:
|
|
16
|
-
os.makedirs(os.path.dirname(env_file_path), exist_ok=True)
|
|
17
|
-
with open(env_file_path, 'w', encoding='utf-8') as f:
|
|
18
|
-
f.write(json.dumps(dict(os.environ)))
|
|
19
|
-
except Exception as e:
|
|
20
|
-
print(f"[report_envs] 写入失败: {e}", flush=True)
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import json
|
|
4
|
+
import os
|
|
5
|
+
|
|
6
|
+
|
|
7
|
+
class ReportService:
|
|
8
|
+
@staticmethod
|
|
9
|
+
def report_envs():
|
|
10
|
+
pod_namespace = os.environ.get('POD_NAMESPACE', '')
|
|
11
|
+
pod_name = os.environ.get('POD_NAME', '')
|
|
12
|
+
if not pod_namespace or not pod_name:
|
|
13
|
+
return
|
|
14
|
+
env_file_path = f'/var/mtp/log/{pod_namespace}/{pod_name}/env'
|
|
15
|
+
try:
|
|
16
|
+
os.makedirs(os.path.dirname(env_file_path), exist_ok=True)
|
|
17
|
+
with open(env_file_path, 'w', encoding='utf-8') as f:
|
|
18
|
+
f.write(json.dumps(dict(os.environ)))
|
|
19
|
+
except Exception as e:
|
|
20
|
+
print(f"[report_envs] 写入失败: {e}", flush=True)
|
|
@@ -1,55 +1,55 @@
|
|
|
1
|
-
# !/usr/bin/env python
|
|
2
|
-
# -*-coding:utf-8 -*-
|
|
3
|
-
from __future__ import annotations
|
|
4
|
-
|
|
5
|
-
import httpx
|
|
6
|
-
|
|
7
|
-
from ..exceptions import APIError
|
|
8
|
-
from ..models.common import APIWrapper
|
|
9
|
-
from ..models.tag_resource_management import *
|
|
10
|
-
|
|
11
|
-
_BASE = "/tag-resource-management/api/v1"
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
class TagResourceManagementService:
|
|
15
|
-
def __init__(self, http: httpx.Client):
|
|
16
|
-
self._project = _Project(http)
|
|
17
|
-
self._virtual_cluster = _VirtualCluster(http)
|
|
18
|
-
|
|
19
|
-
def select_projects(self) -> List[Project]:
|
|
20
|
-
return self._project.select_projects()
|
|
21
|
-
|
|
22
|
-
def select_virtual_clusters(self, payload: SelectVirtualClustersRequest) -> List[VirtualClusterBrief]:
|
|
23
|
-
return self._virtual_cluster.select(payload).data
|
|
24
|
-
|
|
25
|
-
@property
|
|
26
|
-
def project(self) -> _Project:
|
|
27
|
-
return self._project
|
|
28
|
-
|
|
29
|
-
@property
|
|
30
|
-
def virtual_cluster(self) -> _VirtualCluster:
|
|
31
|
-
return self._virtual_cluster
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
class _Project:
|
|
35
|
-
def __init__(self, http: httpx.Client):
|
|
36
|
-
self._http = http
|
|
37
|
-
|
|
38
|
-
def select_projects(self) -> List[Project]:
|
|
39
|
-
resp = self._http.get(f"{_BASE}/select-projects")
|
|
40
|
-
wrapper = APIWrapper[ProjectListData].model_validate(resp.json())
|
|
41
|
-
if wrapper.code != 0:
|
|
42
|
-
raise APIError(f"backend code {wrapper.code}: {wrapper.msg}")
|
|
43
|
-
return wrapper.data.data
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
class _VirtualCluster:
|
|
47
|
-
def __init__(self, http: httpx.Client):
|
|
48
|
-
self._http = http
|
|
49
|
-
|
|
50
|
-
def select(self, payload: SelectVirtualClustersRequest) -> SelectVirtualClustersResponse:
|
|
51
|
-
resp = self._http.get(f"{_BASE}/select-clusters", params=payload.model_dump(by_alias=True, exclude_none=True))
|
|
52
|
-
wrapper = APIWrapper[SelectVirtualClustersResponse].model_validate(resp.json())
|
|
53
|
-
if wrapper.code != 0:
|
|
54
|
-
raise APIError(f"backend code {wrapper.code}: {wrapper.msg}")
|
|
55
|
-
return wrapper.data
|
|
1
|
+
# !/usr/bin/env python
|
|
2
|
+
# -*-coding:utf-8 -*-
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
import httpx
|
|
6
|
+
|
|
7
|
+
from ..exceptions import APIError
|
|
8
|
+
from ..models.common import APIWrapper
|
|
9
|
+
from ..models.tag_resource_management import *
|
|
10
|
+
|
|
11
|
+
_BASE = "/tag-resource-management/api/v1"
|
|
12
|
+
|
|
13
|
+
|
|
14
|
+
class TagResourceManagementService:
|
|
15
|
+
def __init__(self, http: httpx.Client):
|
|
16
|
+
self._project = _Project(http)
|
|
17
|
+
self._virtual_cluster = _VirtualCluster(http)
|
|
18
|
+
|
|
19
|
+
def select_projects(self) -> List[Project]:
|
|
20
|
+
return self._project.select_projects()
|
|
21
|
+
|
|
22
|
+
def select_virtual_clusters(self, payload: SelectVirtualClustersRequest) -> List[VirtualClusterBrief]:
|
|
23
|
+
return self._virtual_cluster.select(payload).data
|
|
24
|
+
|
|
25
|
+
@property
|
|
26
|
+
def project(self) -> _Project:
|
|
27
|
+
return self._project
|
|
28
|
+
|
|
29
|
+
@property
|
|
30
|
+
def virtual_cluster(self) -> _VirtualCluster:
|
|
31
|
+
return self._virtual_cluster
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
class _Project:
|
|
35
|
+
def __init__(self, http: httpx.Client):
|
|
36
|
+
self._http = http
|
|
37
|
+
|
|
38
|
+
def select_projects(self) -> List[Project]:
|
|
39
|
+
resp = self._http.get(f"{_BASE}/select-projects")
|
|
40
|
+
wrapper = APIWrapper[ProjectListData].model_validate(resp.json())
|
|
41
|
+
if wrapper.code != 0:
|
|
42
|
+
raise APIError(f"backend code {wrapper.code}: {wrapper.msg}")
|
|
43
|
+
return wrapper.data.data
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
class _VirtualCluster:
|
|
47
|
+
def __init__(self, http: httpx.Client):
|
|
48
|
+
self._http = http
|
|
49
|
+
|
|
50
|
+
def select(self, payload: SelectVirtualClustersRequest) -> SelectVirtualClustersResponse:
|
|
51
|
+
resp = self._http.get(f"{_BASE}/select-clusters", params=payload.model_dump(by_alias=True, exclude_none=True))
|
|
52
|
+
wrapper = APIWrapper[SelectVirtualClustersResponse].model_validate(resp.json())
|
|
53
|
+
if wrapper.code != 0:
|
|
54
|
+
raise APIError(f"backend code {wrapper.code}: {wrapper.msg}")
|
|
55
|
+
return wrapper.data
|
aihub/services/task_center.py
CHANGED
|
@@ -1,190 +1,190 @@
|
|
|
1
|
-
from __future__ import annotations
|
|
2
|
-
|
|
3
|
-
import datetime
|
|
4
|
-
|
|
5
|
-
import httpx
|
|
6
|
-
from loguru import logger
|
|
7
|
-
|
|
8
|
-
from .tag_resource_management import TagResourceManagementService
|
|
9
|
-
from .user_system import UserSystemService
|
|
10
|
-
from ..exceptions import APIError
|
|
11
|
-
from ..models.common import APIWrapper
|
|
12
|
-
from ..models.task_center import (
|
|
13
|
-
CreateTaskReq,
|
|
14
|
-
CreateTaskResp,
|
|
15
|
-
CreateTaskOtherInfo,
|
|
16
|
-
LabelProjectTypeEnum,
|
|
17
|
-
TaskCenterPriorityEnum,
|
|
18
|
-
LabelTaskDetail,
|
|
19
|
-
)
|
|
20
|
-
from ..models.user_system import SearchUsersRequest
|
|
21
|
-
|
|
22
|
-
_BASE = "/task-center/api/v1"
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
def date_str_to_timestamp(date_str: str) -> int:
|
|
26
|
-
date_obj = datetime.datetime.strptime(date_str, "%Y-%m-%d")
|
|
27
|
-
return int(date_obj.timestamp())
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
class TaskCenterService:
|
|
31
|
-
|
|
32
|
-
def __init__(self, http: httpx.Client):
|
|
33
|
-
self._TaskCenter = _TaskCenter(http)
|
|
34
|
-
self._http = http
|
|
35
|
-
|
|
36
|
-
def create(self, payload: CreateTaskReq) -> int:
|
|
37
|
-
return self._TaskCenter.create(payload)
|
|
38
|
-
|
|
39
|
-
def get(self, task_id: int) -> LabelTaskDetail:
|
|
40
|
-
"""获取任务信息
|
|
41
|
-
|
|
42
|
-
Args:
|
|
43
|
-
task_id (int): 任务ID
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
Returns:
|
|
47
|
-
LabelTaskDetail: 任务信息
|
|
48
|
-
|
|
49
|
-
"""
|
|
50
|
-
|
|
51
|
-
return self._TaskCenter.get(task_id)
|
|
52
|
-
|
|
53
|
-
# 如果想要访问子对象,也保留属性
|
|
54
|
-
@property
|
|
55
|
-
def TaskCenter(self) -> _TaskCenter:
|
|
56
|
-
return self._TaskCenter
|
|
57
|
-
|
|
58
|
-
def create_label_task(
|
|
59
|
-
self,
|
|
60
|
-
name: str,
|
|
61
|
-
dataset_version_name: str,
|
|
62
|
-
feishu_doc_name: str,
|
|
63
|
-
task_receiver_name: str,
|
|
64
|
-
estimated_delivery_at: str,
|
|
65
|
-
project_name: str,
|
|
66
|
-
label_type: LabelProjectTypeEnum = LabelProjectTypeEnum.IMAGE_CLASSIFICATION,
|
|
67
|
-
description: str = "",
|
|
68
|
-
task_priority: TaskCenterPriorityEnum = TaskCenterPriorityEnum.low,
|
|
69
|
-
) -> int:
|
|
70
|
-
"""创建标注任务
|
|
71
|
-
|
|
72
|
-
Examples:
|
|
73
|
-
>>> from aihub.client import Client
|
|
74
|
-
>>> client = Client(base_url="xxx", token="xxxx")
|
|
75
|
-
>>> task_id = client.task_center.create_label_task( \
|
|
76
|
-
name="test_task", dataset_version_name="re/V1",\
|
|
77
|
-
feishu_doc_name="人脸质量人脸照片分类", task_receiver_name="hyc", \
|
|
78
|
-
project_name="hycpro", label_type=LabelProjectTypeEnum.IMAGE_CLASSIFICATION, description="test_description", \
|
|
79
|
-
task_priority="low", estimated_delivery_at= "2025-08-01")
|
|
80
|
-
1
|
|
81
|
-
|
|
82
|
-
Args:
|
|
83
|
-
name (str): 任务名称
|
|
84
|
-
dataset_version_name (str): 数据集版本名称
|
|
85
|
-
feishu_doc_name (str): 飞书文档名称
|
|
86
|
-
task_receiver_name (str): 任务接收者名称
|
|
87
|
-
estimated_delivery_at (str): 预计交付时间,格式为 "YYYY-MM-DD"
|
|
88
|
-
project_name (str): 项目名称
|
|
89
|
-
label_type (LabelProjectTypeEnum): 标注项目类型,默认为图像分类
|
|
90
|
-
description (str): 任务描述,默认为空
|
|
91
|
-
task_priority (TaskCenterPriorityEnum): 任务优先级,默认为低优先级
|
|
92
|
-
Returns:
|
|
93
|
-
任务ID
|
|
94
|
-
"""
|
|
95
|
-
# 获取接收者ID
|
|
96
|
-
user_service = UserSystemService(self._http)
|
|
97
|
-
task_receiver_id = user_service.search_one(
|
|
98
|
-
payload=SearchUsersRequest(nickname=task_receiver_name)
|
|
99
|
-
)
|
|
100
|
-
|
|
101
|
-
# 获取项目ID
|
|
102
|
-
tag_service = TagResourceManagementService(self._http)
|
|
103
|
-
projects = tag_service.select_projects()
|
|
104
|
-
project_id = None
|
|
105
|
-
for project in projects:
|
|
106
|
-
if project.name == project_name:
|
|
107
|
-
project_id = project.id
|
|
108
|
-
break
|
|
109
|
-
|
|
110
|
-
if project_id is None:
|
|
111
|
-
raise APIError(f"未找到项目: {project_name}")
|
|
112
|
-
|
|
113
|
-
# 获取数据集ID
|
|
114
|
-
from .dataset_management import DatasetManagementService
|
|
115
|
-
|
|
116
|
-
dataset_service = DatasetManagementService(self._http)
|
|
117
|
-
dataset_version = dataset_service.get_dataset_version_by_name(
|
|
118
|
-
version_name=dataset_version_name
|
|
119
|
-
)
|
|
120
|
-
|
|
121
|
-
dataset_id = dataset_version.dataset_id
|
|
122
|
-
dataset_version_id = dataset_version.id
|
|
123
|
-
|
|
124
|
-
# 获取文档ID
|
|
125
|
-
from .document_center import DocumentCenterService
|
|
126
|
-
|
|
127
|
-
doc_service = DocumentCenterService(self._http)
|
|
128
|
-
docs = doc_service.get_documents(name=feishu_doc_name)
|
|
129
|
-
|
|
130
|
-
if not docs:
|
|
131
|
-
raise APIError(f"未找到文档: {feishu_doc_name}")
|
|
132
|
-
|
|
133
|
-
doc_id = docs[0].id
|
|
134
|
-
|
|
135
|
-
# 创建任务
|
|
136
|
-
other_info = CreateTaskOtherInfo(
|
|
137
|
-
label_project_type=label_type,
|
|
138
|
-
dataset_id=dataset_id,
|
|
139
|
-
dataset_version_id=dataset_version_id,
|
|
140
|
-
doc_id=doc_id,
|
|
141
|
-
doc_type="doc_center",
|
|
142
|
-
)
|
|
143
|
-
estimated_delivery_at_timestamp = date_str_to_timestamp(estimated_delivery_at)
|
|
144
|
-
task_req = CreateTaskReq(
|
|
145
|
-
name=name,
|
|
146
|
-
description=description,
|
|
147
|
-
task_priority=task_priority,
|
|
148
|
-
type="label",
|
|
149
|
-
receiver_id=task_receiver_id,
|
|
150
|
-
other_info=other_info,
|
|
151
|
-
project_id=project_id,
|
|
152
|
-
estimated_delivery_at=estimated_delivery_at_timestamp,
|
|
153
|
-
)
|
|
154
|
-
|
|
155
|
-
return self.create(task_req)
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
class _TaskCenter:
|
|
159
|
-
def __init__(self, http: httpx.Client):
|
|
160
|
-
self._http = http
|
|
161
|
-
|
|
162
|
-
def create(self, payload: CreateTaskReq) -> int:
|
|
163
|
-
"""创建任务"""
|
|
164
|
-
logger.debug(f"create task: {payload}")
|
|
165
|
-
resp = self._http.post(
|
|
166
|
-
f"{_BASE}/tasks",
|
|
167
|
-
json=payload.model_dump(),
|
|
168
|
-
)
|
|
169
|
-
logger.debug(f"create task response: {resp.text}")
|
|
170
|
-
if resp.status_code != 200:
|
|
171
|
-
raise APIError(
|
|
172
|
-
message="API Error", status=resp.status_code, detail=resp.json()
|
|
173
|
-
)
|
|
174
|
-
wrapper = APIWrapper[CreateTaskResp].model_validate(resp.json())
|
|
175
|
-
|
|
176
|
-
return wrapper.data.id
|
|
177
|
-
|
|
178
|
-
def get(self, task_id: int) -> LabelTaskDetail:
|
|
179
|
-
"""获取任务"""
|
|
180
|
-
logger.debug(f"get task: {task_id}")
|
|
181
|
-
resp = self._http.get(
|
|
182
|
-
f"{_BASE}/tasks/{task_id}",
|
|
183
|
-
)
|
|
184
|
-
logger.debug(f"get task response: {resp.text}")
|
|
185
|
-
if resp.status_code != 200:
|
|
186
|
-
raise APIError(
|
|
187
|
-
message="API Error", status=resp.status_code, detail=resp.json()
|
|
188
|
-
)
|
|
189
|
-
wrapper = APIWrapper[LabelTaskDetail].model_validate(resp.json())
|
|
190
|
-
return wrapper.data
|
|
1
|
+
from __future__ import annotations
|
|
2
|
+
|
|
3
|
+
import datetime
|
|
4
|
+
|
|
5
|
+
import httpx
|
|
6
|
+
from loguru import logger
|
|
7
|
+
|
|
8
|
+
from .tag_resource_management import TagResourceManagementService
|
|
9
|
+
from .user_system import UserSystemService
|
|
10
|
+
from ..exceptions import APIError
|
|
11
|
+
from ..models.common import APIWrapper
|
|
12
|
+
from ..models.task_center import (
|
|
13
|
+
CreateTaskReq,
|
|
14
|
+
CreateTaskResp,
|
|
15
|
+
CreateTaskOtherInfo,
|
|
16
|
+
LabelProjectTypeEnum,
|
|
17
|
+
TaskCenterPriorityEnum,
|
|
18
|
+
LabelTaskDetail,
|
|
19
|
+
)
|
|
20
|
+
from ..models.user_system import SearchUsersRequest
|
|
21
|
+
|
|
22
|
+
_BASE = "/task-center/api/v1"
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def date_str_to_timestamp(date_str: str) -> int:
|
|
26
|
+
date_obj = datetime.datetime.strptime(date_str, "%Y-%m-%d")
|
|
27
|
+
return int(date_obj.timestamp())
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class TaskCenterService:
|
|
31
|
+
|
|
32
|
+
def __init__(self, http: httpx.Client):
|
|
33
|
+
self._TaskCenter = _TaskCenter(http)
|
|
34
|
+
self._http = http
|
|
35
|
+
|
|
36
|
+
def create(self, payload: CreateTaskReq) -> int:
|
|
37
|
+
return self._TaskCenter.create(payload)
|
|
38
|
+
|
|
39
|
+
def get(self, task_id: int) -> LabelTaskDetail:
|
|
40
|
+
"""获取任务信息
|
|
41
|
+
|
|
42
|
+
Args:
|
|
43
|
+
task_id (int): 任务ID
|
|
44
|
+
|
|
45
|
+
|
|
46
|
+
Returns:
|
|
47
|
+
LabelTaskDetail: 任务信息
|
|
48
|
+
|
|
49
|
+
"""
|
|
50
|
+
|
|
51
|
+
return self._TaskCenter.get(task_id)
|
|
52
|
+
|
|
53
|
+
# 如果想要访问子对象,也保留属性
|
|
54
|
+
@property
|
|
55
|
+
def TaskCenter(self) -> _TaskCenter:
|
|
56
|
+
return self._TaskCenter
|
|
57
|
+
|
|
58
|
+
def create_label_task(
|
|
59
|
+
self,
|
|
60
|
+
name: str,
|
|
61
|
+
dataset_version_name: str,
|
|
62
|
+
feishu_doc_name: str,
|
|
63
|
+
task_receiver_name: str,
|
|
64
|
+
estimated_delivery_at: str,
|
|
65
|
+
project_name: str,
|
|
66
|
+
label_type: LabelProjectTypeEnum = LabelProjectTypeEnum.IMAGE_CLASSIFICATION,
|
|
67
|
+
description: str = "",
|
|
68
|
+
task_priority: TaskCenterPriorityEnum = TaskCenterPriorityEnum.low,
|
|
69
|
+
) -> int:
|
|
70
|
+
"""创建标注任务
|
|
71
|
+
|
|
72
|
+
Examples:
|
|
73
|
+
>>> from aihub.client import Client
|
|
74
|
+
>>> client = Client(base_url="xxx", token="xxxx")
|
|
75
|
+
>>> task_id = client.task_center.create_label_task( \
|
|
76
|
+
name="test_task", dataset_version_name="re/V1",\
|
|
77
|
+
feishu_doc_name="人脸质量人脸照片分类", task_receiver_name="hyc", \
|
|
78
|
+
project_name="hycpro", label_type=LabelProjectTypeEnum.IMAGE_CLASSIFICATION, description="test_description", \
|
|
79
|
+
task_priority="low", estimated_delivery_at= "2025-08-01")
|
|
80
|
+
1
|
|
81
|
+
|
|
82
|
+
Args:
|
|
83
|
+
name (str): 任务名称
|
|
84
|
+
dataset_version_name (str): 数据集版本名称
|
|
85
|
+
feishu_doc_name (str): 飞书文档名称
|
|
86
|
+
task_receiver_name (str): 任务接收者名称
|
|
87
|
+
estimated_delivery_at (str): 预计交付时间,格式为 "YYYY-MM-DD"
|
|
88
|
+
project_name (str): 项目名称
|
|
89
|
+
label_type (LabelProjectTypeEnum): 标注项目类型,默认为图像分类
|
|
90
|
+
description (str): 任务描述,默认为空
|
|
91
|
+
task_priority (TaskCenterPriorityEnum): 任务优先级,默认为低优先级
|
|
92
|
+
Returns:
|
|
93
|
+
任务ID
|
|
94
|
+
"""
|
|
95
|
+
# 获取接收者ID
|
|
96
|
+
user_service = UserSystemService(self._http)
|
|
97
|
+
task_receiver_id = user_service.search_one(
|
|
98
|
+
payload=SearchUsersRequest(nickname=task_receiver_name)
|
|
99
|
+
)
|
|
100
|
+
|
|
101
|
+
# 获取项目ID
|
|
102
|
+
tag_service = TagResourceManagementService(self._http)
|
|
103
|
+
projects = tag_service.select_projects()
|
|
104
|
+
project_id = None
|
|
105
|
+
for project in projects:
|
|
106
|
+
if project.name == project_name:
|
|
107
|
+
project_id = project.id
|
|
108
|
+
break
|
|
109
|
+
|
|
110
|
+
if project_id is None:
|
|
111
|
+
raise APIError(f"未找到项目: {project_name}")
|
|
112
|
+
|
|
113
|
+
# 获取数据集ID
|
|
114
|
+
from .dataset_management import DatasetManagementService
|
|
115
|
+
|
|
116
|
+
dataset_service = DatasetManagementService(self._http)
|
|
117
|
+
dataset_version = dataset_service.get_dataset_version_by_name(
|
|
118
|
+
version_name=dataset_version_name
|
|
119
|
+
)
|
|
120
|
+
|
|
121
|
+
dataset_id = dataset_version.dataset_id
|
|
122
|
+
dataset_version_id = dataset_version.id
|
|
123
|
+
|
|
124
|
+
# 获取文档ID
|
|
125
|
+
from .document_center import DocumentCenterService
|
|
126
|
+
|
|
127
|
+
doc_service = DocumentCenterService(self._http)
|
|
128
|
+
docs = doc_service.get_documents(name=feishu_doc_name)
|
|
129
|
+
|
|
130
|
+
if not docs:
|
|
131
|
+
raise APIError(f"未找到文档: {feishu_doc_name}")
|
|
132
|
+
|
|
133
|
+
doc_id = docs[0].id
|
|
134
|
+
|
|
135
|
+
# 创建任务
|
|
136
|
+
other_info = CreateTaskOtherInfo(
|
|
137
|
+
label_project_type=label_type,
|
|
138
|
+
dataset_id=dataset_id,
|
|
139
|
+
dataset_version_id=dataset_version_id,
|
|
140
|
+
doc_id=doc_id,
|
|
141
|
+
doc_type="doc_center",
|
|
142
|
+
)
|
|
143
|
+
estimated_delivery_at_timestamp = date_str_to_timestamp(estimated_delivery_at)
|
|
144
|
+
task_req = CreateTaskReq(
|
|
145
|
+
name=name,
|
|
146
|
+
description=description,
|
|
147
|
+
task_priority=task_priority,
|
|
148
|
+
type="label",
|
|
149
|
+
receiver_id=task_receiver_id,
|
|
150
|
+
other_info=other_info,
|
|
151
|
+
project_id=project_id,
|
|
152
|
+
estimated_delivery_at=estimated_delivery_at_timestamp,
|
|
153
|
+
)
|
|
154
|
+
|
|
155
|
+
return self.create(task_req)
|
|
156
|
+
|
|
157
|
+
|
|
158
|
+
class _TaskCenter:
|
|
159
|
+
def __init__(self, http: httpx.Client):
|
|
160
|
+
self._http = http
|
|
161
|
+
|
|
162
|
+
def create(self, payload: CreateTaskReq) -> int:
|
|
163
|
+
"""创建任务"""
|
|
164
|
+
logger.debug(f"create task: {payload}")
|
|
165
|
+
resp = self._http.post(
|
|
166
|
+
f"{_BASE}/tasks",
|
|
167
|
+
json=payload.model_dump(),
|
|
168
|
+
)
|
|
169
|
+
logger.debug(f"create task response: {resp.text}")
|
|
170
|
+
if resp.status_code != 200:
|
|
171
|
+
raise APIError(
|
|
172
|
+
message="API Error", status=resp.status_code, detail=resp.json()
|
|
173
|
+
)
|
|
174
|
+
wrapper = APIWrapper[CreateTaskResp].model_validate(resp.json())
|
|
175
|
+
|
|
176
|
+
return wrapper.data.id
|
|
177
|
+
|
|
178
|
+
def get(self, task_id: int) -> LabelTaskDetail:
|
|
179
|
+
"""获取任务"""
|
|
180
|
+
logger.debug(f"get task: {task_id}")
|
|
181
|
+
resp = self._http.get(
|
|
182
|
+
f"{_BASE}/tasks/{task_id}",
|
|
183
|
+
)
|
|
184
|
+
logger.debug(f"get task response: {resp.text}")
|
|
185
|
+
if resp.status_code != 200:
|
|
186
|
+
raise APIError(
|
|
187
|
+
message="API Error", status=resp.status_code, detail=resp.json()
|
|
188
|
+
)
|
|
189
|
+
wrapper = APIWrapper[LabelTaskDetail].model_validate(resp.json())
|
|
190
|
+
return wrapper.data
|