5252from labelbox .schema .slice import CatalogSlice , ModelSlice
5353from labelbox .schema .task import Task
5454from labelbox .schema .user import User
55+ from labelbox .schema .editor_task_type import EditorTaskType
5556
5657logger = logging .getLogger (__name__ )
5758
@@ -735,6 +736,12 @@ def create_project(self, **kwargs) -> Project:
735736 } if media_type else {})
736737 })
737738
739+ def create_model_chat_project (self , ** kwargs ) -> Project :
740+ kwargs ["media_type" ] = media_type .MediaType .Conversational
741+ kwargs ["editor_task_type" ] = editor_task_type .EditorTaskType .ModelChatEvaluation
742+
743+ return self .create_project (** kwargs )
744+
738745 def get_roles (self ) -> List [Role ]:
739746 """
740747 Returns:
@@ -938,10 +945,12 @@ def rootSchemaPayloadToFeatureSchema(client, payload):
938945 rootSchemaPayloadToFeatureSchema ,
939946 ['rootSchemaNodes' , 'nextCursor' ])
940947
941- def create_ontology_from_feature_schemas (self ,
942- name ,
943- feature_schema_ids ,
944- media_type = None ) -> Ontology :
948+ def create_ontology_from_feature_schemas (
949+ self ,
950+ name ,
951+ feature_schema_ids ,
952+ media_type : MediaType = None ,
953+ editor_task_type : EditorTaskType = None ) -> Ontology :
945954 """
946955 Creates an ontology from a list of feature schema ids
947956
@@ -979,7 +988,10 @@ def create_ontology_from_feature_schemas(self,
979988 "Neither `tool` or `classification` found in the normalized feature schema"
980989 )
981990 normalized = {'tools' : tools , 'classifications' : classifications }
982- return self .create_ontology (name , normalized , media_type )
991+ return self .create_ontology (name = name ,
992+ normalized = normalized ,
993+ media_type = media_type ,
994+ editor_task_type = editor_task_type )
983995
984996 def delete_unused_feature_schema (self , feature_schema_id : str ) -> None :
985997 """
@@ -1166,7 +1178,11 @@ def get_unused_feature_schemas(self, after: str = None) -> List[str]:
11661178 "Failed to get unused feature schemas, message: " +
11671179 str (response .json ()['message' ]))
11681180
1169- def create_ontology (self , name , normalized , media_type = None ) -> Ontology :
1181+ def create_ontology (self ,
1182+ name ,
1183+ normalized ,
1184+ media_type : MediaType = None ,
1185+ editor_task_type : EditorTaskType = None ) -> Ontology :
11701186 """
11711187 Creates an ontology from normalized data
11721188 >>> normalized = {"tools" : [{'tool': 'polygon', 'name': 'cat', 'color': 'black'}], "classifications" : []}
@@ -1194,6 +1210,13 @@ def create_ontology(self, name, normalized, media_type=None) -> Ontology:
11941210 else :
11951211 raise get_media_type_validation_error (media_type )
11961212
1213+ if editor_task_type :
1214+ if EditorTaskType .is_supported (editor_task_type ):
1215+ editor_task_type = editor_task_type .value
1216+ else :
1217+ raise EditorTaskType .get_editor_task_type_validation_error (
1218+ editor_task_type )
1219+
11971220 query_str = """mutation upsertRootSchemaNodePyApi($data: UpsertOntologyInput!){
11981221 upsertOntology(data: $data){ %s }
11991222 } """ % query .results_query_part (Entity .Ontology )
@@ -1204,9 +1227,65 @@ def create_ontology(self, name, normalized, media_type=None) -> Ontology:
12041227 'mediaType' : media_type
12051228 }
12061229 }
1230+ if editor_task_type :
1231+ params ['data' ]['editorTaskType' ] = editor_task_type
1232+
12071233 res = self .execute (query_str , params )
12081234 return Entity .Ontology (self , res ['upsertOntology' ])
12091235
1236+ def create_model_chat_evaluation_ontology (self , name , normalized ):
1237+ """
1238+ Creates a model chat evalutation ontology from normalized data
1239+ >>> normalized = {"tools" : [{'tool': 'message-single-selection', 'name': 'model output single selection', 'color': '#ff0000',},
1240+ {'tool': 'message-multi-selection', 'name': 'model output multi selection', 'color': '#00ff00',},
1241+ {'tool': 'message-ranking', 'name': 'model output multi ranking', 'color': '#0000ff',}]
1242+ }
1243+ >>> ontology = client.create_ontology("ontology-name", normalized)
1244+
1245+ Or use the ontology builder
1246+ >>> ontology_builder = OntologyBuilder(tools=[
1247+ Tool(tool=Tool.Type.MESSAGE_SINGLE_SELECTION,
1248+ name="model output single selection"),
1249+ Tool(tool=Tool.Type.MESSAGE_MULTI_SELECTION,
1250+ name="model output multi selection"),
1251+ Tool(tool=Tool.Type.MESSAGE_RANKING,
1252+ name="model output multi ranking"),
1253+ ],)
1254+
1255+ >>> ontology = client.create_model_chat_evaluation_ontology("Multi-chat ontology", ontology_builder.asdict())
1256+
1257+ Args:
1258+ name (str): Name of the ontology
1259+ normalized (dict): A normalized ontology payload. See above for details.
1260+ Returns:
1261+ The created Ontology
1262+ """
1263+
1264+ return self .create_ontology (
1265+ name = name ,
1266+ normalized = normalized ,
1267+ media_type = MediaType .Conversational ,
1268+ editor_task_type = EditorTaskType .ModelChatEvaluation )
1269+
1270+ def create_model_chat_evaluation_ontology_from_feature_schemas (
1271+ self , name , feature_schema_ids ):
1272+ """
1273+ Creates an ontology from a list of feature schema ids
1274+
1275+ Args:
1276+ name (str): Name of the ontology
1277+ feature_schema_ids (List[str]): List of feature schema ids corresponding to
1278+ top level tools and classifications to include in the ontology
1279+ Returns:
1280+ The created Ontology
1281+ """
1282+
1283+ return self .create_ontology_from_feature_schemas (
1284+ name = name ,
1285+ feature_schema_ids = feature_schema_ids ,
1286+ media_type = MediaType .Conversational ,
1287+ editor_task_type = EditorTaskType .ModelChatEvaluation )
1288+
12101289 def create_feature_schema (self , normalized ):
12111290 """
12121291 Creates a feature schema from normalized data.
0 commit comments