4
4
5
5
from labelbox .exceptions import ResourceNotFoundError
6
6
from labelbox .pagination import PaginatedCollection
7
- from pydantic import BaseModel , root_validator , Field
7
+ from pydantic import BaseModel , model_validator , Field
8
8
from labelbox .schema .search_filters import SearchFilter , build_search_filter
9
9
from labelbox .utils import _CamelCaseMixin
10
10
from .ontology_kind import EditorTaskType
11
11
from labelbox .schema .media_type import MediaType
12
12
from labelbox .schema .labeling_service_status import LabelingServiceStatus
13
- from labelbox .utils import _CamelCaseMixin , sentence_case
13
+ from labelbox .utils import sentence_case
14
14
15
15
GRAPHQL_QUERY_SELECTIONS = """
16
16
id
@@ -58,7 +58,7 @@ class LabelingServiceDashboard(_CamelCaseMixin):
58
58
status (LabelingServiceStatus): status of the labeling service
59
59
data_rows_count (int): total number of data rows batched in the project
60
60
tasks_completed_count (int): number of tasks completed (in the Done queue)
61
- tasks_remaining_count (int): number of tasks remaining (in a queue other then Done)
61
+ tasks_remaining_count (int): number of tasks remaining (i.e. tasks in progress), None if labeling has not started
62
62
tags (List[LabelingServiceDashboardTags]): tags associated with the project
63
63
media_type (MediaType): media type of the project
64
64
editor_task_type (EditorTaskType): editor task type of the project
@@ -73,7 +73,7 @@ class LabelingServiceDashboard(_CamelCaseMixin):
73
73
status : LabelingServiceStatus = Field (frozen = True , default = None )
74
74
data_rows_count : int = Field (frozen = True )
75
75
tasks_completed_count : int = Field (frozen = True )
76
- tasks_remaining_count : int = Field (frozen = True )
76
+ tasks_remaining_count : Optional [ int ] = Field (frozen = True , default = None )
77
77
media_type : Optional [MediaType ] = Field (frozen = True , default = None )
78
78
editor_task_type : EditorTaskType = Field (frozen = True , default = None )
79
79
tags : List [LabelingServiceDashboardTags ] = Field (frozen = True , default = None )
@@ -84,8 +84,7 @@ def __init__(self, **kwargs):
84
84
super ().__init__ (** kwargs )
85
85
if not self .client .enable_experimental :
86
86
raise RuntimeError (
87
- "Please enable experimental in client to use LabelingService"
88
- )
87
+ "Please enable experimental in client to use LabelingService" )
89
88
90
89
@property
91
90
def service_type (self ):
@@ -98,28 +97,20 @@ def service_type(self):
98
97
if self .editor_task_type is None :
99
98
return sentence_case (self .media_type .value )
100
99
101
- if (
102
- self .editor_task_type == EditorTaskType .OfflineModelChatEvaluation
103
- and self .media_type == MediaType .Conversational
104
- ):
100
+ if (self .editor_task_type == EditorTaskType .OfflineModelChatEvaluation
101
+ and self .media_type == MediaType .Conversational ):
105
102
return "Offline chat evaluation"
106
103
107
- if (
108
- self .editor_task_type == EditorTaskType .ModelChatEvaluation
109
- and self .media_type == MediaType .Conversational
110
- ):
104
+ if (self .editor_task_type == EditorTaskType .ModelChatEvaluation and
105
+ self .media_type == MediaType .Conversational ):
111
106
return "Live chat evaluation"
112
107
113
- if (
114
- self .editor_task_type == EditorTaskType .ResponseCreation
115
- and self .media_type == MediaType .Text
116
- ):
108
+ if (self .editor_task_type == EditorTaskType .ResponseCreation and
109
+ self .media_type == MediaType .Text ):
117
110
return "Response creation"
118
111
119
- if (
120
- self .media_type == MediaType .LLMPromptCreation
121
- or self .media_type == MediaType .LLMPromptResponseCreation
122
- ):
112
+ if (self .media_type == MediaType .LLMPromptCreation or
113
+ self .media_type == MediaType .LLMPromptResponseCreation ):
123
114
return "Prompt response creation"
124
115
125
116
return sentence_case (self .media_type .value )
@@ -163,8 +154,7 @@ def get_all(
163
154
pageInfo { endCursor }
164
155
}
165
156
}
166
- """
167
- )
157
+ """ )
168
158
else :
169
159
template = Template (
170
160
"""query SearchProjectsPyApi($$first: Int, $$from: String) {
@@ -174,13 +164,11 @@ def get_all(
174
164
pageInfo { endCursor }
175
165
}
176
166
}
177
- """
178
- )
167
+ """ )
179
168
query_str = template .substitute (
180
169
labeling_dashboard_selections = GRAPHQL_QUERY_SELECTIONS ,
181
170
search_query = build_search_filter (search_query )
182
- if search_query
183
- else None ,
171
+ if search_query else None ,
184
172
)
185
173
params : Dict [str , Union [str , int ]] = {}
186
174
@@ -198,7 +186,7 @@ def convert_to_labeling_service_dashboard(client, data):
198
186
experimental = True ,
199
187
)
200
188
201
- @root_validator ( pre = True )
189
+ @model_validator ( mode = 'before' )
202
190
def convert_boost_data (cls , data ):
203
191
if "boostStatus" in data :
204
192
data ["status" ] = LabelingServiceStatus (data .pop ("boostStatus" ))
@@ -212,6 +200,12 @@ def convert_boost_data(cls, data):
212
200
if "boostRequestedBy" in data :
213
201
data ["created_by_id" ] = data .pop ("boostRequestedBy" )
214
202
203
+ tasks_remaining_count = data .get ("tasksRemainingCount" , 0 )
204
+ tasks_total_count = data .get ("tasksTotalCount" , 0 )
205
+ # to avoid confusion, setting tasks_completed_count to None if none of tasks has even completed an none are in flight
206
+ if tasks_total_count == 0 and tasks_remaining_count == 0 :
207
+ data .pop ("tasksRemainingCount" )
208
+
215
209
return data
216
210
217
211
def dict (self , * args , ** kwargs ):
0 commit comments