Skip to content

Commit a686849

Browse files
[LABIMP-6971] Annotation_guide is now conditionally required based on annotation_template_id presence. (#6)
* [LABIMP-6971] Annotation_guide is now conditionally required based on annotation_template_id presence. * [LABIMP-6971] Update error message for missing annotation_guide to clarify requirements
1 parent abab6ed commit a686849

File tree

1 file changed

+22
-19
lines changed

1 file changed

+22
-19
lines changed

labellerr/client.py

Lines changed: 22 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1037,21 +1037,22 @@ def initiate_create_project(self, payload):
10371037
try:
10381038
result = {}
10391039
# validate all the parameters
1040-
required_params = ['client_id', 'dataset_name', 'dataset_description', 'data_type', 'created_by', 'project_name','annotation_guide','autolabel']
1040+
required_params = ['client_id', 'dataset_name', 'dataset_description', 'data_type', 'created_by', 'project_name','autolabel']
10411041
for param in required_params:
10421042
if param not in payload:
10431043
raise LabellerrError(f"Required parameter {param} is missing")
1044-
1045-
10461044
if param == 'client_id' and not isinstance(payload[param], str):
10471045
raise LabellerrError("client_id must be a non-empty string")
1048-
1049-
if param == 'annotation_guide':
1050-
for guide in payload['annotation_guide']:
1051-
if 'option_type' not in guide:
1052-
raise LabellerrError("option_type is required in annotation_guide")
1053-
if guide['option_type'] not in OPTION_TYPE_LIST:
1054-
raise LabellerrError(f"option_type must be one of {OPTION_TYPE_LIST}")
1046+
1047+
# annotation_guide is only required if annotation_template_id is not provided
1048+
if not payload.get('annotation_template_id'):
1049+
if 'annotation_guide' not in payload:
1050+
raise LabellerrError("Please provide either annotation guide or annotation template id")
1051+
for guide in payload['annotation_guide']:
1052+
if 'option_type' not in guide:
1053+
raise LabellerrError("option_type is required in annotation_guide")
1054+
if guide['option_type'] not in OPTION_TYPE_LIST:
1055+
raise LabellerrError(f"option_type must be one of {OPTION_TYPE_LIST}")
10551056

10561057

10571058
if 'folder_to_upload' in payload and 'files_to_upload' in payload:
@@ -1115,15 +1116,17 @@ def dataset_ready():
11151116

11161117
print("Dataset created and ready for use")
11171118

1118-
1119-
annotation_template_id = self.create_annotation_guideline(
1120-
payload['client_id'],
1121-
payload['annotation_guide'],
1122-
payload['project_name'],
1123-
payload['data_type']
1124-
)
1125-
print("Annotation guidelines created")
1126-
1119+
# Use annotation_template_id from payload if provided, else create a new one
1120+
if 'annotation_template_id' in payload and payload['annotation_template_id']:
1121+
annotation_template_id = payload['annotation_template_id']
1122+
else:
1123+
annotation_template_id = self.create_annotation_guideline(
1124+
payload['client_id'],
1125+
payload['annotation_guide'],
1126+
payload['project_name'],
1127+
payload['data_type']
1128+
)
1129+
print("Annotation guidelines created")
11271130

11281131
project_response = self.create_project(
11291132
project_name=payload['project_name'],

0 commit comments

Comments
 (0)