52
52
from labelbox .schema .slice import CatalogSlice , ModelSlice
53
53
from labelbox .schema .task import Task
54
54
from labelbox .schema .user import User
55
+ from labelbox .schema .editor_task_type import EditorTaskType
55
56
56
57
logger = logging .getLogger (__name__ )
57
58
@@ -735,6 +736,12 @@ def create_project(self, **kwargs) -> Project:
735
736
} if media_type else {})
736
737
})
737
738
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
+
738
745
def get_roles (self ) -> List [Role ]:
739
746
"""
740
747
Returns:
@@ -938,10 +945,12 @@ def rootSchemaPayloadToFeatureSchema(client, payload):
938
945
rootSchemaPayloadToFeatureSchema ,
939
946
['rootSchemaNodes' , 'nextCursor' ])
940
947
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 :
945
954
"""
946
955
Creates an ontology from a list of feature schema ids
947
956
@@ -979,7 +988,10 @@ def create_ontology_from_feature_schemas(self,
979
988
"Neither `tool` or `classification` found in the normalized feature schema"
980
989
)
981
990
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 )
983
995
984
996
def delete_unused_feature_schema (self , feature_schema_id : str ) -> None :
985
997
"""
@@ -1166,7 +1178,11 @@ def get_unused_feature_schemas(self, after: str = None) -> List[str]:
1166
1178
"Failed to get unused feature schemas, message: " +
1167
1179
str (response .json ()['message' ]))
1168
1180
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 :
1170
1186
"""
1171
1187
Creates an ontology from normalized data
1172
1188
>>> normalized = {"tools" : [{'tool': 'polygon', 'name': 'cat', 'color': 'black'}], "classifications" : []}
@@ -1194,6 +1210,13 @@ def create_ontology(self, name, normalized, media_type=None) -> Ontology:
1194
1210
else :
1195
1211
raise get_media_type_validation_error (media_type )
1196
1212
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
+
1197
1220
query_str = """mutation upsertRootSchemaNodePyApi($data: UpsertOntologyInput!){
1198
1221
upsertOntology(data: $data){ %s }
1199
1222
} """ % query .results_query_part (Entity .Ontology )
@@ -1204,9 +1227,65 @@ def create_ontology(self, name, normalized, media_type=None) -> Ontology:
1204
1227
'mediaType' : media_type
1205
1228
}
1206
1229
}
1230
+ if editor_task_type :
1231
+ params ['data' ]['editorTaskType' ] = editor_task_type
1232
+
1207
1233
res = self .execute (query_str , params )
1208
1234
return Entity .Ontology (self , res ['upsertOntology' ])
1209
1235
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
+
1210
1289
def create_feature_schema (self , normalized ):
1211
1290
"""
1212
1291
Creates a feature schema from normalized data.
0 commit comments