@@ -149,6 +149,12 @@ def is_chat_evaluation(self) -> bool:
149149 def is_auto_data_generation (self ) -> bool :
150150 return (self .upload_type == UploadType .Auto ) # type: ignore
151151
152+ # we test not only the project ontology is None, but also a default empty ontology that we create when we attach a labeling front end in createLabelingFrontendOptions
153+ def is_empty_ontology (self ) -> bool :
154+ ontology = self .ontology () # type: ignore
155+ return ontology is None or (len (ontology .tools ()) == 0 and
156+ len (ontology .classifications ()) == 0 )
157+
152158 def project_model_configs (self ):
153159 query_str = """query ProjectModelConfigsPyApi($id: ID!) {
154160 project(where: {id : $id}) {
@@ -772,35 +778,27 @@ def setup_editor(self, ontology) -> None:
772778 Args:
773779 ontology (Ontology): The ontology to attach to the project
774780 """
781+ warnings .warn ("This method is deprecated use connect_ontology instead." )
782+ self .connect_ontology (ontology )
775783
776- if self .labeling_frontend () is not None and not self .is_chat_evaluation (
777- ): # Chat evaluation projects are automatically set up via the same api that creates a project
778- raise ResourceConflict ("Editor is already set up." )
779-
780- if not self .is_chat_evaluation ():
781- labeling_frontend = next (
782- self .client .get_labeling_frontends (
783- where = Entity .LabelingFrontend .name == "Editor" ))
784- self .labeling_frontend .connect (labeling_frontend )
785-
786- LFO = Entity .LabelingFrontendOptions
787- self .client ._create (
788- LFO , {
789- LFO .project :
790- self ,
791- LFO .labeling_frontend :
792- labeling_frontend ,
793- LFO .customization_options :
794- json .dumps ({
795- "tools" : [],
796- "classifications" : []
797- })
798- })
799- else :
800- warnings .warn ("""
801- Skipping editor setup for a chat evaluation project.
802- Editor was setup automatically.
803- """ )
784+ def connect_ontology (self , ontology ) -> None :
785+ """
786+ Connects the ontology to the project. If an editor is not setup, it will be connected as well.
787+
788+ Note: For live chat model evaluation projects, the editor setup is skipped becase it is automatically setup when the project is created.
789+
790+ Args:
791+ ontology (Ontology): The ontology to attach to the project
792+ """
793+ if self .labeling_frontend (
794+ ) is None : # Chat evaluation projects are automatically set up via the same api that creates a project
795+ self ._connect_default_labeling_front_end (ontology_as_dict = {
796+ "tools" : [],
797+ "classifications" : []
798+ })
799+
800+ if not self .is_empty_ontology ():
801+ raise ValueError ("Ontology already connected to project." )
804802
805803 query_str = """mutation ConnectOntologyPyApi($projectId: ID!, $ontologyId: ID!){
806804 project(where: {id: $projectId}) {connectOntology(ontologyId: $ontologyId) {id}}}"""
@@ -812,43 +810,55 @@ def setup_editor(self, ontology) -> None:
812810 self .update (setup_complete = timestamp )
813811
814812 def setup (self , labeling_frontend , labeling_frontend_options ) -> None :
815- """ Finalizes the Project setup .
813+ """ This method will associate default labeling frontend with the project and create an ontology based on labeling_frontend_options .
816814
817815 Args:
818- labeling_frontend (LabelingFrontend): Which UI to use to label the
819- data.
816+ labeling_frontend (LabelingFrontend): Do not use, this parameter is deprecated. We now associate the default labeling frontend with the project.
820817 labeling_frontend_options (dict or str): Labeling frontend options,
821818 a.k.a. project ontology. If given a `dict` it will be converted
822819 to `str` using `json.dumps`.
823820 """
824821
822+ warnings .warn ("This method is deprecated use connect_ontology instead." )
823+ if labeling_frontend is not None :
824+ warnings .warn (
825+ "labeling_frontend parameter will not be used to create a new labeling frontend."
826+ )
827+
825828 if self .is_chat_evaluation ():
826829 warnings .warn ("""
827- This project is a chat evaluation project.
830+ This project is a live chat evaluation project.
828831 Editor was setup automatically.
829- No need to call this method.
830832 """ )
831833 return
832834
833- if self .labeling_frontend () is not None :
834- raise ResourceConflict ("Editor is already set up." )
835+ if self .labeling_frontend (
836+ ) is None : # Chat evaluation projects are automatically set up via the same api that creates a project
837+ self ._connect_default_labeling_front_end (labeling_frontend_options )
835838
836- if not isinstance ( labeling_frontend_options , str ):
837- labeling_frontend_options = json . dumps ( labeling_frontend_options )
839+ timestamp = datetime . now ( timezone . utc ). strftime ( "%Y-%m-%dT%H:%M:%SZ" )
840+ self . update ( setup_complete = timestamp )
838841
842+ def _connect_default_labeling_front_end (self , ontology_as_dict : dict ):
843+ warnings .warn ("Connecting default labeling editor for the project." )
844+ labeling_frontend = next (
845+ self .client .get_labeling_frontends (
846+ where = Entity .LabelingFrontend .name == "Editor" ))
839847 self .labeling_frontend .connect (labeling_frontend )
840848
849+ if not isinstance (ontology_as_dict , str ):
850+ labeling_frontend_options_str = json .dumps (ontology_as_dict )
851+ else :
852+ labeling_frontend_options_str = ontology_as_dict
853+
841854 LFO = Entity .LabelingFrontendOptions
842855 self .client ._create (
843856 LFO , {
844857 LFO .project : self ,
845858 LFO .labeling_frontend : labeling_frontend ,
846- LFO .customization_options : labeling_frontend_options
859+ LFO .customization_options : labeling_frontend_options_str
847860 })
848861
849- timestamp = datetime .now (timezone .utc ).strftime ("%Y-%m-%dT%H:%M:%SZ" )
850- self .update (setup_complete = timestamp )
851-
852862 def create_batch (
853863 self ,
854864 name : str ,
0 commit comments