Skip to content

Commit f859770

Browse files
author
Val Brodsky
committed
Add support for offline chat model evaluation project creation
1 parent dc86872 commit f859770

File tree

2 files changed

+92
-69
lines changed

2 files changed

+92
-69
lines changed

libs/labelbox/src/labelbox/client.py

Lines changed: 91 additions & 69 deletions
Original file line numberDiff line numberDiff line change
@@ -652,7 +652,8 @@ def delete_model_config(self, id: str) -> bool:
652652
params = {"id": id}
653653
result = self.execute(query, params)
654654
if not result:
655-
raise labelbox.exceptions.ResourceNotFoundError(Entity.ModelConfig, params)
655+
raise labelbox.exceptions.ResourceNotFoundError(
656+
Entity.ModelConfig, params)
656657
return result['deleteModelConfig']['success']
657658

658659
def create_dataset(self,
@@ -716,6 +717,8 @@ def create_dataset(self,
716717
raise e
717718
return dataset
718719

720+
# **** Create Project begin ****
721+
719722
def create_project(self, **kwargs) -> Project:
720723
""" Creates a Project object on the server.
721724
@@ -741,7 +744,93 @@ def create_project(self, **kwargs) -> Project:
741744
InvalidAttributeError: If the Project type does not contain
742745
any of the attribute names given in kwargs.
743746
"""
747+
kwargs.pop("ontology_kind", None)
748+
kwargs.pop("dataset_name_or_id", None)
749+
kwargs.pop("append_to_existing_dataset", None)
750+
kwargs.pop("data_row_count", None)
751+
kwargs.pop("editor_task_type", None)
752+
return self._create_project(**kwargs)
753+
754+
@overload
755+
def create_model_evaluation_project(self,
756+
dataset_name: str,
757+
dataset_id: str = None,
758+
data_row_count: int = 100,
759+
**kwargs) -> Project:
760+
pass
761+
762+
@overload
763+
def create_model_evaluation_project(self,
764+
dataset_id: str,
765+
dataset_name: str = None,
766+
data_row_count: int = 100,
767+
**kwargs) -> Project:
768+
pass
769+
770+
def create_model_evaluation_project(self,
771+
dataset_id: Optional[str] = None,
772+
dataset_name: Optional[str] = None,
773+
data_row_count: int = 100,
774+
**kwargs) -> Project:
775+
"""
776+
Use this method exclusively to create a chat model evaluation project.
777+
Args:
778+
dataset_name: When creating a new dataset, pass the name
779+
dataset_id: When using an existing dataset, pass the id
780+
data_row_count: The number of data row assets to use for the project
781+
**kwargs: Additional parameters to pass to the the create_project method
782+
Returns:
783+
Project: The created project
784+
785+
Examples:
786+
>>> client.create_model_evaluation_project(name=project_name, dataset_name="new data set")
787+
>>> This creates a new dataset with a default number of rows (100), creates new project and assigns a batch of the newly created datarows to the project.
788+
789+
>>> client.create_model_evaluation_project(name=project_name, dataset_name="new data set", data_row_count=10)
790+
>>> This creates a new dataset with 10 data rows, creates new project and assigns a batch of the newly created datarows to the project.
791+
792+
>>> client.create_model_evaluation_project(name=project_name, dataset_id="clr00u8j0j0j0")
793+
>>> This creates a new project, and adds 100 datarows to the dataset with id "clr00u8j0j0j0" and assigns a batch of the newly created data rows to the project.
794+
795+
>>> client.create_model_evaluation_project(name=project_name, dataset_id="clr00u8j0j0j0", data_row_count=10)
796+
>>> This creates a new project, and adds 100 datarows to the dataset with id "clr00u8j0j0j0" and assigns a batch of the newly created 10 data rows to the project.
797+
798+
799+
"""
800+
if not dataset_id and not dataset_name:
801+
raise ValueError(
802+
"dataset_name or data_set_id must be present and not be an empty string."
803+
)
804+
if data_row_count <= 0:
805+
raise ValueError("data_row_count must be a positive integer.")
806+
807+
if dataset_id:
808+
append_to_existing_dataset = True
809+
dataset_name_or_id = dataset_id
810+
else:
811+
append_to_existing_dataset = False
812+
dataset_name_or_id = dataset_name
813+
814+
kwargs["media_type"] = MediaType.Conversational
815+
kwargs["dataset_name_or_id"] = dataset_name_or_id
816+
kwargs["append_to_existing_dataset"] = append_to_existing_dataset
817+
kwargs["data_row_count"] = data_row_count
818+
kwargs["editor_task_type"] = EditorTaskType.ModelChatEvaluation.value
819+
820+
return self._create_project(**kwargs)
821+
822+
def create_offline_model_evaluation_project(self, **kwargs) -> Project:
823+
kwargs["media_type"] = MediaType.Conversational
824+
kwargs["editor_task_type"] = EditorTaskType.OfflineModelEvaluation.value
744825

826+
return self.create_project(**kwargs)
827+
828+
def _create_project(self, **kwargs) -> Project:
829+
"""
830+
Internal method to create a project with the given parameters.
831+
Args: see other create_project methods
832+
NOTE: do not use this method directly. Use create_project* methods instead.
833+
"""
745834
auto_audit_percentage = kwargs.get("auto_audit_percentage")
746835
auto_audit_number_of_labels = kwargs.get("auto_audit_number_of_labels")
747836
if auto_audit_percentage is not None or auto_audit_number_of_labels is not None:
@@ -805,8 +894,6 @@ def create_project(self, **kwargs) -> Project:
805894
params = {**data}
806895
if media_type_value:
807896
params["media_type"] = media_type_value
808-
if editor_task_type_value:
809-
params["editor_task_type"] = editor_task_type_value
810897

811898
extra_params = {
812899
Field.String("dataset_name_or_id"):
@@ -820,73 +907,8 @@ def create_project(self, **kwargs) -> Project:
820907

821908
return self._create(Entity.Project, params, extra_params)
822909

823-
@overload
824-
def create_model_evaluation_project(self,
825-
dataset_name: str,
826-
dataset_id: str = None,
827-
data_row_count: int = 100,
828-
**kwargs) -> Project:
829-
pass
830-
831-
@overload
832-
def create_model_evaluation_project(self,
833-
dataset_id: str,
834-
dataset_name: str = None,
835-
data_row_count: int = 100,
836-
**kwargs) -> Project:
837-
pass
838-
839-
def create_model_evaluation_project(self,
840-
dataset_id: Optional[str] = None,
841-
dataset_name: Optional[str] = None,
842-
data_row_count: int = 100,
843-
**kwargs) -> Project:
844-
"""
845-
Use this method exclusively to create a chat model evaluation project.
846-
Args:
847-
dataset_name: When creating a new dataset, pass the name
848-
dataset_id: When using an existing dataset, pass the id
849-
data_row_count: The number of data row assets to use for the project
850-
**kwargs: Additional parameters to pass to the the create_project method
851-
Returns:
852-
Project: The created project
853-
854-
Examples:
855-
>>> client.create_model_evaluation_project(name=project_name, dataset_name="new data set")
856-
>>> This creates a new dataset with a default number of rows (100), creates new project and assigns a batch of the newly created datarows to the project.
857-
858-
>>> client.create_model_evaluation_project(name=project_name, dataset_name="new data set", data_row_count=10)
859-
>>> This creates a new dataset with 10 data rows, creates new project and assigns a batch of the newly created datarows to the project.
860-
861-
>>> client.create_model_evaluation_project(name=project_name, dataset_id="clr00u8j0j0j0")
862-
>>> This creates a new project, and adds 100 datarows to the dataset with id "clr00u8j0j0j0" and assigns a batch of the newly created data rows to the project.
863-
864-
>>> client.create_model_evaluation_project(name=project_name, dataset_id="clr00u8j0j0j0", data_row_count=10)
865-
>>> This creates a new project, and adds 100 datarows to the dataset with id "clr00u8j0j0j0" and assigns a batch of the newly created 10 data rows to the project.
866-
867910

868-
"""
869-
if not dataset_id and not dataset_name:
870-
raise ValueError(
871-
"dataset_name or data_set_id must be present and not be an empty string."
872-
)
873-
if data_row_count <= 0:
874-
raise ValueError("data_row_count must be a positive integer.")
875-
876-
if dataset_id:
877-
append_to_existing_dataset = True
878-
dataset_name_or_id = dataset_id
879-
else:
880-
append_to_existing_dataset = False
881-
dataset_name_or_id = dataset_name
882-
883-
kwargs["media_type"] = MediaType.Conversational
884-
kwargs["ontology_kind"] = OntologyKind.ModelEvaluation
885-
kwargs["dataset_name_or_id"] = dataset_name_or_id
886-
kwargs["append_to_existing_dataset"] = append_to_existing_dataset
887-
kwargs["data_row_count"] = data_row_count
888-
889-
return self.create_project(**kwargs)
911+
# **** Create Project end ****
890912

891913
def get_roles(self) -> List[Role]:
892914
"""

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ def get_ontology_kind_validation_error(cls, ontology_kind):
2626
class EditorTaskType(Enum):
2727
ModelChatEvaluation = "MODEL_CHAT_EVALUATION"
2828
ResponseCreation = "RESPONSE_CREATION"
29+
OfflineModelChatEvaluation = "OFFLINE_MODEL_CHAT_EVALUATION"
2930
Missing = None
3031

3132
@classmethod

0 commit comments

Comments
 (0)