Skip to content

Commit 9ffa6a0

Browse files
FannyGaudinbaptiste-olivier
authored andcommitted
feat(LAB-3105): add param for exclude sent back labels
And fix export for llm
1 parent 361dece commit 9ffa6a0

5 files changed

Lines changed: 26 additions & 4 deletions

File tree

src/kili/presentation/client/label.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1138,6 +1138,7 @@ def export_labels(
11381138
asset_filter_kwargs: Optional[Dict[str, object]] = None,
11391139
normalized_coordinates: Optional[bool] = None,
11401140
label_type_in: Optional[List[str]] = None,
1141+
include_sent_back_labels: Optional[bool] = True,
11411142
) -> Optional[List[Dict[str, Union[List[str], str]]]]:
11421143
# pylint: disable=line-too-long
11431144
"""Export the project labels with the requested format into the requested output path.
@@ -1192,6 +1193,7 @@ def export_labels(
11921193
If False, the json response will contain additional fields with coordinates in absolute values, that is, in pixels.
11931194
label_type_in: Optional list of label type. Exported assets should have a label whose type belongs to that list.
11941195
By default, only `DEFAULT` and `REVIEW` labels are exported.
1196+
include_sent_back_labels: If True, the export will include the labels that have been sent back.
11951197
11961198
!!! Info
11971199
The supported formats are:
@@ -1249,6 +1251,7 @@ def is_rectangle(coco_annotation, coco_image, kili_annotation):
12491251
asset_filter_kwargs=asset_filter_kwargs,
12501252
normalized_coordinates=normalized_coordinates,
12511253
label_type_in=label_type_in,
1254+
include_sent_back_labels=include_sent_back_labels,
12521255
)
12531256
except NoCompatibleJobError as excp:
12541257
warnings.warn(str(excp), stacklevel=2)

src/kili/services/export/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ def export_labels( # pylint: disable=too-many-arguments, too-many-locals
3939
asset_filter_kwargs: Optional[Dict[str, object]],
4040
normalized_coordinates: Optional[bool],
4141
label_type_in: Optional[List[str]],
42+
include_sent_back_labels: Optional[bool] = True,
4243
) -> Optional[List[Dict[str, Union[List[str], str]]]]:
4344
"""Export the selected assets into the required format, and save it into a file archive."""
4445
kili.kili_api_gateway.get_project(project_id, ["id"])
@@ -56,6 +57,7 @@ def export_labels( # pylint: disable=too-many-arguments, too-many-locals
5657
asset_filter_kwargs=asset_filter_kwargs,
5758
normalized_coordinates=normalized_coordinates,
5859
label_type_in=label_type_in,
60+
include_sent_back_labels=include_sent_back_labels,
5961
)
6062

6163
logger = get_logger(log_level)

src/kili/services/export/format/base.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,7 @@ class ExportParams(NamedTuple):
4747
asset_filter_kwargs: Optional[Dict[str, object]]
4848
normalized_coordinates: Optional[bool]
4949
label_type_in: Optional[List[str]]
50+
include_sent_back_labels: Optional[bool]
5051

5152

5253
class AbstractExporter(ABC): # pylint: disable=too-many-instance-attributes
@@ -79,6 +80,7 @@ def __init__(
7980
self.asset_filter_kwargs = export_params.asset_filter_kwargs
8081
self.normalized_coordinates = export_params.normalized_coordinates
8182
self.label_type_in = export_params.label_type_in or ["DEFAULT", "REVIEW"]
83+
self.include_sent_back_labels = export_params.include_sent_back_labels
8284

8385
self.project = kili.kili_api_gateway.get_project(
8486
self.project_id, ["jsonInterface", "inputType", "title", "description", "id"]
@@ -273,19 +275,28 @@ def _format_json_response(label: Dict) -> Dict:
273275

274276
def preprocess_assets(self, assets: List[Dict]) -> List[Dict]:
275277
"""Format labels in the requested format, and filter out autosave labels."""
278+
include_sent_back_labels = self.include_sent_back_labels
276279
assets_in_format = []
277280
for asset in assets:
278281
if "labels" in asset:
279282
labels_of_asset = []
280283
for label in asset["labels"]:
281284
clean_label = AbstractExporter._format_json_response(label)
282285
labels_of_asset.append(clean_label)
286+
if not include_sent_back_labels:
287+
labels_of_asset = list(
288+
filter(
289+
lambda label: label["isSentBackToQueue"] is False, labels_of_asset
290+
)
291+
)
283292
asset["labels"] = labels_of_asset
293+
assets_in_format.append(asset)
284294
if "latestLabel" in asset:
285295
label = asset["latestLabel"]
286296
if label is not None:
287297
clean_label = AbstractExporter._format_json_response(label)
288298
asset["latestLabel"] = clean_label
289-
assets_in_format.append(asset)
299+
if include_sent_back_labels or asset["latestLabel"]["isSentBackToQueue"] is False:
300+
assets_in_format.append(asset)
290301

291302
return AbstractExporter._filter_out_autosave_labels(assets_in_format)

src/kili/services/export/format/llm/__init__.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,10 @@ def process(self, assets: List[Dict]) -> List[Dict[str, Union[List[str], str]]]:
5858
DeprecationWarning,
5959
stacklevel=2,
6060
)
61+
clean_assets = self.preprocess_assets(assets)
6162
if self.label_format == "llm_v1":
62-
return self._process_llm_v1(assets)
63-
return self._process_llm_dynamic_v1(assets)
63+
return self._process_llm_v1(clean_assets)
64+
return self._process_llm_dynamic_v1(clean_assets)
6465

6566
def _process_llm_dynamic_v1(self, assets: List[Dict]) -> List[Dict[str, Union[List[str], str]]]:
6667
result = []
@@ -262,7 +263,10 @@ def _format_raw_data(
262263
"id": _safe_pop(chat_items_ids),
263264
"chat_id": chat_id,
264265
"model": models[index_completion]
265-
if (index == len(prompts) - 1 or all_model_keys)
266+
if (
267+
(index == len(prompts) - 1 or all_model_keys)
268+
and len(models) > index_completion
269+
)
266270
else None,
267271
}
268272
)

src/kili/services/export/tools.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
"labels.author.lastname",
4242
"labels.createdAt",
4343
"labels.isLatestLabelForUser",
44+
"labels.isSentBackToQueue",
4445
"labels.labelType",
4546
"labels.modelName",
4647
]
@@ -53,6 +54,7 @@
5354
"latestLabel.author.lastname",
5455
"latestLabel.createdAt",
5556
"latestLabel.isLatestLabelForUser",
57+
"latestLabel.isSentBackToQueue",
5658
"latestLabel.labelType",
5759
"latestLabel.modelName",
5860
]

0 commit comments

Comments
 (0)