From c42ff0e03eaf71f39fc0cd53645d8ed03edee7f5 Mon Sep 17 00:00:00 2001 From: xhluca Date: Thu, 18 Apr 2024 17:38:09 -0400 Subject: [PATCH] New argument (significant change): `select_turns_and_candidates_for_prompts` now removes click, change, submit and textinput turns without a proper element --- weblinx/processing/prompt.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/weblinx/processing/prompt.py b/weblinx/processing/prompt.py index a87eb72..fec5bbe 100644 --- a/weblinx/processing/prompt.py +++ b/weblinx/processing/prompt.py @@ -615,6 +615,7 @@ def select_turns_and_candidates_for_prompts( demos, candidates=None, num_candidates=20, + remove_turns_without_elements=True, ): """ This will select the turns that will be used for building the prompts. It first filters @@ -635,6 +636,9 @@ def select_turns_and_candidates_for_prompts( num_candidates : int, optional The number of candidates to select for each turn. Defaults to 20. + remove_turns_without_elements : bool, optional + Whether to remove turns that do not have elements. Defaults to True. + Returns ------- list @@ -663,6 +667,14 @@ def select_turns_and_candidates_for_prompts( turn.type == "chat" and turn.get("speaker") != "navigator" ), ) + # Remove click and textinput turns where element is None + if remove_turns_without_elements: + turns = filter_turns( + turns, + lambda turn: not ( + turn.intent in ("click", "change", "textinput", "submit") and turn.element is None + ), + ) for i, turn in enumerate(turns): if candidates is None: