def _get_completed_on_topic_results_in_order()

in pyrit/orchestrator/multi_turn/tree_of_attacks_with_pruning_orchestrator.py [0:0]


    def _get_completed_on_topic_results_in_order(self, nodes: list[TreeOfAttacksNode]):
        completed_nodes = [
            node
            for node in nodes
            if node
            and node.completed
            and (not node.off_topic)
            and node.score
            and isinstance(node.score.get_value(), float)
        ]
        completed_nodes.sort(key=lambda x: (x.score.get_value() if x.score else 0.0, random.random()), reverse=True)
        return completed_nodes