Skip to content

Commit 669c3fa

Browse files
author
Val Brodsky
committed
Add support for service_type
1 parent bf30f08 commit 669c3fa

File tree

4 files changed

+59
-10
lines changed

4 files changed

+59
-10
lines changed

libs/labelbox/src/labelbox/schema/labeling_service_dashboard.py

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,10 @@
77
from labelbox.pydantic_compat import BaseModel, root_validator, Field
88
from labelbox.schema.search_filters import SearchFilter, build_search_filter
99
from labelbox.utils import _CamelCaseMixin
10+
from .ontology_kind import EditorTaskType
11+
from labelbox.schema.media_type import MediaType
1012
from labelbox.schema.labeling_service_status import LabelingServiceStatus
13+
from labelbox.utils import _CamelCaseMixin, sentence_case
1114

1215
GRAPHQL_QUERY_SELECTIONS = """
1316
id
@@ -21,6 +24,8 @@
2124
dataRowsInReviewCount
2225
dataRowsInReworkCount
2326
dataRowsDoneCount
27+
mediaType
28+
editorTaskType
2429
"""
2530

2631

@@ -38,7 +43,6 @@ class LabelingServiceDashboard(BaseModel):
3843
"""
3944
id: str = Field(frozen=True)
4045
name: str = Field(frozen=True)
41-
service_type: Optional[str] = Field(frozen=True, default=None)
4246
created_at: Optional[datetime] = Field(frozen=True, default=None)
4347
updated_at: Optional[datetime] = Field(frozen=True, default=None)
4448
created_by_id: Optional[str] = Field(frozen=True, default=None)
@@ -48,6 +52,9 @@ class LabelingServiceDashboard(BaseModel):
4852
data_rows_in_review_count: int = Field(frozen=True)
4953
data_rows_in_rework_count: int = Field(frozen=True)
5054
data_rows_done_count: int = Field(frozen=True)
55+
media_type: MediaType = Field(frozen=True, default=MediaType.Unknown)
56+
editor_task_type: EditorTaskType = Field(frozen=True,
57+
default=EditorTaskType.Missing)
5158

5259
client: Any # type Any to avoid circular import from client
5360

@@ -65,6 +72,25 @@ def tasks_completed(self):
6572
def tasks_remaining(self):
6673
return self.data_rows_count - self.data_rows_done_count
6774

75+
@property
76+
def service_type(self):
77+
if self.editor_task_type is None:
78+
return sentence_case(self.media_type.value)
79+
80+
if self.editor_task_type == EditorTaskType.OfflineModelChatEvaluation and self.media_type == MediaType.Conversational:
81+
return "Offline chat evaluation"
82+
83+
if self.editor_task_type == EditorTaskType.ModelChatEvaluation and self.media_type == MediaType.Conversational:
84+
return "Live chat evaluation"
85+
86+
if self.editor_task_type == EditorTaskType.ResponseCreation and self.media_type == MediaType.Text:
87+
return "Response creation"
88+
89+
if media_type == MediaType.LLMPromptCreation or media_type == MediaType.LLMPromptResponseCreation:
90+
return "Prompt response creation"
91+
92+
return sentence_case(self.media_type.value)
93+
6894
class Config(_CamelCaseMixin.Config):
6995
...
7096

libs/labelbox/src/labelbox/schema/ontology_kind.py

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,24 +21,30 @@ def get_ontology_kind_validation_error(cls, ontology_kind):
2121
return TypeError(f"{ontology_kind}: is not a valid ontology kind. Use"
2222
f" any of {OntologyKind.__members__.items()}"
2323
" from OntologyKind.")
24-
24+
2525
@staticmethod
26-
def evaluate_ontology_kind_with_media_type(ontology_kind,
27-
media_type: Optional[MediaType]) -> Union[MediaType, None]:
28-
26+
def evaluate_ontology_kind_with_media_type(
27+
ontology_kind,
28+
media_type: Optional[MediaType]) -> Union[MediaType, None]:
29+
2930
ontology_to_media = {
30-
OntologyKind.ModelEvaluation: (MediaType.Conversational, "For chat evaluation, media_type must be Conversational."),
31-
OntologyKind.ResponseCreation: (MediaType.Text, "For response creation, media_type must be Text.")
31+
OntologyKind.ModelEvaluation:
32+
(MediaType.Conversational,
33+
"For chat evaluation, media_type must be Conversational."),
34+
OntologyKind.ResponseCreation:
35+
(MediaType.Text,
36+
"For response creation, media_type must be Text.")
3237
}
3338

3439
if ontology_kind in ontology_to_media:
35-
expected_media_type, error_message = ontology_to_media[ontology_kind]
40+
expected_media_type, error_message = ontology_to_media[
41+
ontology_kind]
3642

3743
if media_type is None or media_type == expected_media_type:
3844
media_type = expected_media_type
3945
else:
4046
raise ValueError(error_message)
41-
47+
4248
return media_type
4349

4450

libs/labelbox/src/labelbox/utils.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,15 @@ def snake_case(s):
3939
return _convert(s, "_", lambda i: False)
4040

4141

42+
def sentence_case(s: str) -> str:
43+
""" Converts a string in [snake|camel|title]case to Sentence case. """
44+
# Replace underscores with spaces and convert to lower case
45+
sentence_str = s.replace("_", " ").lower()
46+
# Capitalize the first letter of each word
47+
sentence_str = sentence_str.capitalize()
48+
return sentence_str
49+
50+
4251
def is_exactly_one_set(*args):
4352
return sum([bool(arg) for arg in args]) == 1
4453

libs/labelbox/tests/unit/test_utils.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import pytest
2-
from labelbox.utils import format_iso_datetime, format_iso_from_string
2+
from labelbox.utils import format_iso_datetime, format_iso_from_string, sentence_case
33

44

55
@pytest.mark.parametrize('datetime_str, expected_datetime_str',
@@ -11,3 +11,11 @@ def test_datetime_parsing(datetime_str, expected_datetime_str):
1111
# NOTE I would normally not take 'expected' using another function from sdk code, but in this case this is exactly the usage in _validate_parse_datetime
1212
assert format_iso_datetime(
1313
format_iso_from_string(datetime_str)) == expected_datetime_str
14+
15+
16+
@pytest.mark.parametrize(
17+
'str, expected_str',
18+
[('AUDIO', 'Audio'),
19+
('LLM_PROMPT_RESPONSE_CREATION', 'Llm prompt response creation')])
20+
def test_sentence_case(str, expected_str):
21+
assert sentence_case(str) == expected_str

0 commit comments

Comments
 (0)