@@ -211,9 +211,17 @@ def _post(path: str, json: dict) -> dict:
211
211
_post (f"/api/v1/tasks/{ task ['id' ]} /ack" , {"message_id" : message_id })
212
212
213
213
valid_labels = task ["valid_labels" ]
214
- labels_str : str = typer .prompt ("Enter labels, separated by commas" )
215
- labels = labels_str .lower ().replace (" " , "" ).split ("," )
216
- labels_dict = {label : "1" if label in labels else "0" for label in valid_labels }
214
+
215
+ labels_dict = None
216
+ while labels_dict is None :
217
+ labels_str : str = typer .prompt ("Enter labels, separated by commas" )
218
+ labels = labels_str .lower ().replace (" " , "" ).split ("," )
219
+
220
+ if all ([label in valid_labels for label in labels ]):
221
+ labels_dict = {label : "1" if label in labels else "0" for label in valid_labels }
222
+ else :
223
+ invalid_labels = [label for label in labels if label not in valid_labels ]
224
+ typer .echo (f"Invalid labels: { ', ' .join (invalid_labels )} . Valid: { ', ' .join (valid_labels )} " )
217
225
218
226
# send ranking
219
227
new_task = _post (
@@ -240,9 +248,17 @@ def _post(path: str, json: dict) -> dict:
240
248
_post (f"/api/v1/tasks/{ task ['id' ]} /ack" , {"message_id" : message_id })
241
249
242
250
valid_labels = task ["valid_labels" ]
243
- labels_str : str = typer .prompt ("Enter labels, separated by commas" )
244
- labels = labels_str .lower ().replace (" " , "" ).split ("," )
245
- labels_dict = {label : "1" if label in labels else "0" for label in valid_labels }
251
+
252
+ labels_dict = None
253
+ while labels_dict is None :
254
+ labels_str : str = typer .prompt ("Enter labels, separated by commas" )
255
+ labels = labels_str .lower ().replace (" " , "" ).split ("," )
256
+
257
+ if all ([label in valid_labels for label in labels ]):
258
+ labels_dict = {label : "1" if label in labels else "0" for label in valid_labels }
259
+ else :
260
+ invalid_labels = [label for label in labels if label not in valid_labels ]
261
+ typer .echo (f"Invalid labels: { ', ' .join (invalid_labels )} . Valid: { ', ' .join (valid_labels )} " )
246
262
247
263
# send ranking
248
264
new_task = _post (
0 commit comments