@@ -653,7 +653,8 @@ def delete_model_config(self, id: str) -> bool:
653653 params = {"id" : id }
654654 result = self .execute (query , params )
655655 if not result :
656- raise labelbox .exceptions .ResourceNotFoundError (Entity .ModelConfig , params )
656+ raise labelbox .exceptions .ResourceNotFoundError (
657+ Entity .ModelConfig , params )
657658 return result ['deleteModelConfig' ]['success' ]
658659
659660 def create_dataset (self ,
@@ -741,85 +742,17 @@ def create_project(self, **kwargs) -> Project:
741742 Raises:
742743 InvalidAttributeError: If the Project type does not contain
743744 any of the attribute names given in kwargs.
744- """
745-
746- auto_audit_percentage = kwargs .get ("auto_audit_percentage" )
747- auto_audit_number_of_labels = kwargs .get ("auto_audit_number_of_labels" )
748- if auto_audit_percentage is not None or auto_audit_number_of_labels is not None :
749- raise ValueError (
750- "quality_mode must be set instead of auto_audit_percentage or auto_audit_number_of_labels."
751- )
752-
753- name = kwargs .get ("name" )
754- if name is None or not name .strip ():
755- raise ValueError ("project name must be a valid string." )
756-
757- queue_mode = kwargs .get ("queue_mode" )
758- if queue_mode is QueueMode .Dataset :
759- raise ValueError (
760- "Dataset queue mode is deprecated. Please prefer Batch queue mode."
761- )
762- elif queue_mode is QueueMode .Batch :
763- logger .warning (
764- "Passing a queue mode of batch is redundant and will soon no longer be supported."
765- )
766745
767- media_type = kwargs .get ("media_type" )
768- if media_type and MediaType .is_supported (media_type ):
769- media_type_value = media_type .value
770- elif media_type :
771- raise TypeError (f"{ media_type } is not a valid media type. Use"
772- f" any of { MediaType .get_supported_members ()} "
773- " from MediaType. Example: MediaType.Image." )
774- else :
775- logger .warning (
776- "Creating a project without specifying media_type"
777- " through this method will soon no longer be supported." )
778- media_type_value = None
779-
780- ontology_kind = kwargs .pop ("ontology_kind" , None )
781- if ontology_kind and OntologyKind .is_supported (ontology_kind ):
782- editor_task_type_value = EditorTaskTypeMapper .to_editor_task_type (
783- ontology_kind , media_type ).value
784- elif ontology_kind :
785- raise OntologyKind .get_ontology_kind_validation_error (ontology_kind )
786- else :
787- editor_task_type_value = None
788-
789- quality_mode = kwargs .get ("quality_mode" )
790- if not quality_mode :
791- logger .info ("Defaulting quality mode to Benchmark." )
792-
793- data = kwargs
794- data .pop ("quality_mode" , None )
795- if quality_mode is None or quality_mode is QualityMode .Benchmark :
796- data [
797- "auto_audit_number_of_labels" ] = BENCHMARK_AUTO_AUDIT_NUMBER_OF_LABELS
798- data ["auto_audit_percentage" ] = BENCHMARK_AUTO_AUDIT_PERCENTAGE
799- elif quality_mode is QualityMode .Consensus :
800- data [
801- "auto_audit_number_of_labels" ] = CONSENSUS_AUTO_AUDIT_NUMBER_OF_LABELS
802- data ["auto_audit_percentage" ] = CONSENSUS_AUTO_AUDIT_PERCENTAGE
803- else :
804- raise ValueError (f"{ quality_mode } is not a valid quality mode." )
805-
806- params = {** data }
807- if media_type_value :
808- params ["media_type" ] = media_type_value
809- if editor_task_type_value :
810- params ["editor_task_type" ] = editor_task_type_value
811-
812- extra_params = {
813- Field .String ("dataset_name_or_id" ):
814- params .pop ("dataset_name_or_id" , None ),
815- Field .Boolean ("append_to_existing_dataset" ):
816- params .pop ("append_to_existing_dataset" , None ),
817- Field .Int ("data_row_count" ):
818- params .pop ("data_row_count" , None ),
819- }
820- extra_params = {k : v for k , v in extra_params .items () if v is not None }
821-
822- return self ._create (Entity .Project , params , extra_params )
746+ NOTE: the following attributes are used only in chat model evaluation projects:
747+ dataset_name_or_id, append_to_existing_dataset, data_row_count, editor_task_type
748+ They are not used for general projects and not supported in this method
749+ """
750+ # The following arguments are not supported for general projects, only for chat model evaluation projects
751+ kwargs .pop ("dataset_name_or_id" , None )
752+ kwargs .pop ("append_to_existing_dataset" , None )
753+ kwargs .pop ("data_row_count" , None )
754+ kwargs .pop ("editor_task_type" , None )
755+ return self ._create_project (** kwargs )
823756
824757 @overload
825758 def create_model_evaluation_project (self ,
@@ -882,13 +815,99 @@ def create_model_evaluation_project(self,
882815 dataset_name_or_id = dataset_name
883816
884817 kwargs ["media_type" ] = MediaType .Conversational
885- kwargs ["ontology_kind" ] = OntologyKind .ModelEvaluation
886818 kwargs ["dataset_name_or_id" ] = dataset_name_or_id
887819 kwargs ["append_to_existing_dataset" ] = append_to_existing_dataset
888820 kwargs ["data_row_count" ] = data_row_count
821+ kwargs ["editor_task_type" ] = EditorTaskType .ModelChatEvaluation .value
822+
823+ return self ._create_project (** kwargs )
824+
825+ def create_offline_model_evaluation_project (self , ** kwargs ) -> Project :
826+ """
827+ Creates a project for offline model evaluation.
828+ Args:
829+ **kwargs: Additional parameters to pass see the create_project method
830+ Returns:
831+ Project: The created project
832+ """
833+ kwargs [
834+ "media_type" ] = MediaType .Conversational # Only Conversational is supported
835+ kwargs [
836+ "editor_task_type" ] = EditorTaskType .OfflineModelChatEvaluation .value # Special editor task type for offline model evaluation
837+
838+ # The following arguments are not supported for offline model evaluation
839+ kwargs .pop ("dataset_name_or_id" , None )
840+ kwargs .pop ("append_to_existing_dataset" , None )
841+ kwargs .pop ("data_row_count" , None )
889842
890843 return self .create_project (** kwargs )
891844
845+ def _create_project (self , ** kwargs ) -> Project :
846+ auto_audit_percentage = kwargs .get ("auto_audit_percentage" )
847+ auto_audit_number_of_labels = kwargs .get ("auto_audit_number_of_labels" )
848+ if auto_audit_percentage is not None or auto_audit_number_of_labels is not None :
849+ raise ValueError (
850+ "quality_mode must be set instead of auto_audit_percentage or auto_audit_number_of_labels."
851+ )
852+
853+ name = kwargs .get ("name" )
854+ if name is None or not name .strip ():
855+ raise ValueError ("project name must be a valid string." )
856+
857+ queue_mode = kwargs .get ("queue_mode" )
858+ if queue_mode is QueueMode .Dataset :
859+ raise ValueError (
860+ "Dataset queue mode is deprecated. Please prefer Batch queue mode."
861+ )
862+ elif queue_mode is QueueMode .Batch :
863+ logger .warning (
864+ "Passing a queue mode of batch is redundant and will soon no longer be supported."
865+ )
866+
867+ media_type = kwargs .get ("media_type" )
868+ if media_type and MediaType .is_supported (media_type ):
869+ media_type_value = media_type .value
870+ elif media_type :
871+ raise TypeError (f"{ media_type } is not a valid media type. Use"
872+ f" any of { MediaType .get_supported_members ()} "
873+ " from MediaType. Example: MediaType.Image." )
874+ else :
875+ logger .warning (
876+ "Creating a project without specifying media_type"
877+ " through this method will soon no longer be supported." )
878+ media_type_value = None
879+
880+ quality_mode = kwargs .get ("quality_mode" )
881+ if not quality_mode :
882+ logger .info ("Defaulting quality mode to Benchmark." )
883+
884+ data = kwargs
885+ data .pop ("quality_mode" , None )
886+ if quality_mode is None or quality_mode is QualityMode .Benchmark :
887+ data [
888+ "auto_audit_number_of_labels" ] = BENCHMARK_AUTO_AUDIT_NUMBER_OF_LABELS
889+ data ["auto_audit_percentage" ] = BENCHMARK_AUTO_AUDIT_PERCENTAGE
890+ elif quality_mode is QualityMode .Consensus :
891+ data [
892+ "auto_audit_number_of_labels" ] = CONSENSUS_AUTO_AUDIT_NUMBER_OF_LABELS
893+ data ["auto_audit_percentage" ] = CONSENSUS_AUTO_AUDIT_PERCENTAGE
894+ else :
895+ raise ValueError (f"{ quality_mode } is not a valid quality mode." )
896+
897+ params = {** data }
898+ if media_type_value :
899+ params ["media_type" ] = media_type_value
900+
901+ extra_params = {
902+ Field .String ("dataset_name_or_id" ):
903+ params .pop ("dataset_name_or_id" , None ),
904+ Field .Boolean ("append_to_existing_dataset" ):
905+ params .pop ("append_to_existing_dataset" , None ),
906+ }
907+ extra_params = {k : v for k , v in extra_params .items () if v is not None }
908+
909+ return self ._create (Entity .Project , params , extra_params )
910+
892911 def get_roles (self ) -> List [Role ]:
893912 """
894913 Returns:
0 commit comments