Skip to content

Commit 4f90d2a

Browse files
author
Val Brodsky
committed
Handle new editor task types without breaking Project
1 parent 3564796 commit 4f90d2a

File tree

4 files changed

+67
-3
lines changed

4 files changed

+67
-3
lines changed

libs/labelbox/src/labelbox/client.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,6 +743,10 @@ def create_project(self, **kwargs) -> Project:
743743
Raises:
744744
InvalidAttributeError: If the Project type does not contain
745745
any of the attribute names given in kwargs.
746+
747+
NOTE: the following attributes are used only chat model evaluation projects:
748+
dataset_name_or_id, append_to_existing_dataset, data_row_count, editor_task_type
749+
They are not used for general projects and not supported in this method
746750
"""
747751
kwargs.pop("dataset_name_or_id", None)
748752
kwargs.pop("append_to_existing_dataset", None)

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,6 +33,21 @@ class EditorTaskType(Enum):
3333
def is_supported(cls, value):
3434
return isinstance(value, cls)
3535

36+
@classmethod
37+
def _missing_(cls, name) -> 'EditorTaskType':
38+
"""Handle missing null new task types
39+
Handle upper case names for compatibility with
40+
the GraphQL"""
41+
42+
if name is None:
43+
return cls.Missing
44+
45+
for name, member in cls.__members__.items():
46+
if name == name.upper():
47+
return member
48+
49+
return cls.Missing
50+
3651

3752
class EditorTaskTypeMapper:
3853

libs/labelbox/tests/integration/test_offline_chat_evaluation_project.py

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,11 @@
1-
def test_create_offline_chat_evaluation_project(
2-
client, rand_gen, offline_chat_evaluation_project,
3-
chat_evaluation_ontology, offline_conversational_data_row):
1+
import pytest
2+
3+
4+
def test_create_offline_chat_evaluation_project(client, rand_gen,
5+
offline_chat_evaluation_project,
6+
chat_evaluation_ontology,
7+
offline_conversational_data_row,
8+
model_config):
49
project = offline_chat_evaluation_project
510
assert project
611

@@ -15,3 +20,7 @@ def test_create_offline_chat_evaluation_project(
1520
[offline_conversational_data_row.uid], # sample of data row objects
1621
)
1722
assert batch
23+
24+
# Can not add a model config to an offline chat evaluation project, since we do not use live models
25+
with pytest.raises(Exception):
26+
project.add_model_config(model_config.uid)
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
import pytest
2+
from unittest.mock import MagicMock
3+
4+
from labelbox.schema.project import Project
5+
from labelbox.schema.ontology_kind import EditorTaskType
6+
7+
8+
@pytest.mark.parametrize(
9+
'api_editor_task_type, expected_editor_task_type',
10+
[(None, EditorTaskType.Missing),
11+
('MODEL_CHAT_EVALUATION', EditorTaskType.ModelChatEvaluation),
12+
('RESPONSE_CREATION', EditorTaskType.ResponseCreation),
13+
('OFFLINE_MODEL_CHAT_EVALUATION',
14+
EditorTaskType.OfflineModelChatEvaluation),
15+
('NEW_TYPE', EditorTaskType.Missing)])
16+
def test_project_editor_task_type(api_editor_task_type,
17+
expected_editor_task_type):
18+
client = MagicMock()
19+
project = Project(
20+
client, {
21+
"id": "test",
22+
"name": "test",
23+
"createdAt": "2021-06-01T00:00:00.000Z",
24+
"updatedAt": "2021-06-01T00:00:00.000Z",
25+
"autoAuditNumberOfLabels": 1,
26+
"autoAuditPercentage": 100,
27+
"dataRowCount": 1,
28+
"description": "test",
29+
"editorTaskType": api_editor_task_type,
30+
"lastActivityTime": "2021-06-01T00:00:00.000Z",
31+
"allowedMediaType": "IMAGE",
32+
"queueMode": "BATCH",
33+
"setupComplete": "2021-06-01T00:00:00.000Z",
34+
})
35+
36+
assert project.editor_task_type == expected_editor_task_type

0 commit comments

Comments
 (0)