You've already forked DataMate
LSF
This commit is contained in:
@@ -30,6 +30,15 @@ from .mapping import (
|
||||
DeleteDatasetResponse,
|
||||
)
|
||||
|
||||
from .editor import (
|
||||
EditorProjectInfo,
|
||||
EditorTaskListItem,
|
||||
EditorTaskListResponse,
|
||||
EditorTaskResponse,
|
||||
UpsertAnnotationRequest,
|
||||
UpsertAnnotationResponse,
|
||||
)
|
||||
|
||||
# Rebuild model to resolve forward references
|
||||
DatasetMappingResponse.model_rebuild()
|
||||
|
||||
@@ -51,4 +60,10 @@ __all__ = [
|
||||
"UpdateAnnotationTemplateRequest",
|
||||
"AnnotationTemplateResponse",
|
||||
"AnnotationTemplateListResponse",
|
||||
]
|
||||
"EditorProjectInfo",
|
||||
"EditorTaskListItem",
|
||||
"EditorTaskListResponse",
|
||||
"EditorTaskResponse",
|
||||
"UpsertAnnotationRequest",
|
||||
"UpsertAnnotationResponse",
|
||||
]
|
||||
|
||||
@@ -0,0 +1,83 @@
|
||||
"""
|
||||
标注编辑器(Label Studio Editor)接口模型
|
||||
|
||||
设计目标:
|
||||
- 单人单份最终标签:每个 project_id + file_id 只维护 1 条最终标注结果
|
||||
- 完全兼容 Label Studio:标注结果以 annotation 原始 JSON 形式存储与返回
|
||||
"""
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
from datetime import datetime
|
||||
from typing import Any, Dict, List, Optional
|
||||
|
||||
from pydantic import BaseModel, Field, ConfigDict
|
||||
|
||||
|
||||
class EditorProjectInfo(BaseModel):
|
||||
"""编辑器项目元信息"""
|
||||
|
||||
project_id: str = Field(..., alias="projectId", description="DataMate 标注项目ID(t_dm_labeling_projects.id)")
|
||||
dataset_id: str = Field(..., alias="datasetId", description="数据集ID(t_dm_datasets.id)")
|
||||
template_id: Optional[str] = Field(None, alias="templateId", description="模板ID(t_dm_annotation_templates.id)")
|
||||
label_config: Optional[str] = Field(None, alias="labelConfig", description="Label Studio XML 配置")
|
||||
supported: bool = Field(..., description="当前数据类型是否支持内嵌编辑器")
|
||||
unsupported_reason: Optional[str] = Field(None, alias="unsupportedReason", description="不支持原因(当 supported=false)")
|
||||
|
||||
model_config = ConfigDict(populate_by_name=True)
|
||||
|
||||
|
||||
class EditorTaskListItem(BaseModel):
|
||||
"""编辑器任务列表条目(对应一个数据集文件)"""
|
||||
|
||||
file_id: str = Field(..., alias="fileId", description="文件ID")
|
||||
file_name: str = Field(..., alias="fileName", description="文件名")
|
||||
file_type: Optional[str] = Field(None, alias="fileType", description="文件类型")
|
||||
has_annotation: bool = Field(..., alias="hasAnnotation", description="是否已有最终标注")
|
||||
annotation_updated_at: Optional[datetime] = Field(None, alias="annotationUpdatedAt", description="标注更新时间")
|
||||
|
||||
model_config = ConfigDict(populate_by_name=True)
|
||||
|
||||
|
||||
class EditorTaskListResponse(BaseModel):
|
||||
"""编辑器任务列表响应"""
|
||||
|
||||
content: List[EditorTaskListItem] = Field(..., description="任务列表")
|
||||
total_elements: int = Field(..., alias="totalElements", description="总条数")
|
||||
total_pages: int = Field(..., alias="totalPages", description="总页数")
|
||||
page: int = Field(..., description="页码(从0开始)")
|
||||
size: int = Field(..., description="每页大小")
|
||||
|
||||
model_config = ConfigDict(populate_by_name=True)
|
||||
|
||||
|
||||
class EditorTaskResponse(BaseModel):
|
||||
"""编辑器任务详情(可直接喂给 Label Studio Editor 的 task 对象)"""
|
||||
|
||||
task: Dict[str, Any] = Field(..., description="Label Studio task 对象")
|
||||
annotation_updated_at: Optional[datetime] = Field(None, alias="annotationUpdatedAt", description="标注更新时间")
|
||||
|
||||
model_config = ConfigDict(populate_by_name=True)
|
||||
|
||||
|
||||
class UpsertAnnotationRequest(BaseModel):
|
||||
"""保存/覆盖最终标注(Label Studio annotation 原始对象)"""
|
||||
|
||||
annotation: Dict[str, Any] = Field(..., description="Label Studio annotation 对象(包含 result 等)")
|
||||
expected_updated_at: Optional[datetime] = Field(
|
||||
None,
|
||||
alias="expectedUpdatedAt",
|
||||
description="乐观锁:若提供则要求与当前记录 updated_at 一致,否则返回 409",
|
||||
)
|
||||
|
||||
model_config = ConfigDict(populate_by_name=True)
|
||||
|
||||
|
||||
class UpsertAnnotationResponse(BaseModel):
|
||||
"""保存/覆盖最终标注响应"""
|
||||
|
||||
annotation_id: str = Field(..., alias="annotationId", description="标注结果ID(t_dm_annotation_results.id)")
|
||||
updated_at: datetime = Field(..., alias="updatedAt", description="标注更新时间")
|
||||
|
||||
model_config = ConfigDict(populate_by_name=True)
|
||||
|
||||
Reference in New Issue
Block a user