From 250e7e82a7f0aebbf02886827c77fd8f3fb34df9 Mon Sep 17 00:00:00 2001 From: Anthony Naddeo Date: Sun, 24 Mar 2024 18:55:50 -0700 Subject: [PATCH] Use tuple instead of list in validation options This enesures that this type can be serialized. --- langkit/validators/comparison.py | 4 ++-- langkit/validators/library.py | 2 +- tests/langkit/validators/test_comparison.py | 24 ++++++++++----------- 3 files changed, 15 insertions(+), 15 deletions(-) diff --git a/langkit/validators/comparison.py b/langkit/validators/comparison.py index 72e7527..67bf378 100644 --- a/langkit/validators/comparison.py +++ b/langkit/validators/comparison.py @@ -1,6 +1,6 @@ from dataclasses import dataclass, replace from functools import partial -from typing import Any, Callable, List, Literal, Optional, Sequence, Set, Union +from typing import Any, Callable, List, Literal, Optional, Sequence, Set, Tuple, Union import numpy as np import pandas as pd @@ -208,7 +208,7 @@ def validate_result(self, df: pd.DataFrame) -> Optional[ValidationResult]: @dataclass class MultiColumnConstraintValidatorOptions: - constraints: List[ConstraintValidatorOptions] + constraints: Tuple[ConstraintValidatorOptions, ...] operator: Literal["AND", "OR"] = "AND" report_mode: Literal["ALL_FAILED_METRICS", "FIRST_FAILED_METRIC"] = "FIRST_FAILED_METRIC" diff --git a/langkit/validators/library.py b/langkit/validators/library.py index 7414644..4f79fa3 100644 --- a/langkit/validators/library.py +++ b/langkit/validators/library.py @@ -94,5 +94,5 @@ def multi_column_constraint( report_mode: Literal["ALL_FAILED_METRICS", "FIRST_FAILED_METRIC"] = "FIRST_FAILED_METRIC", ) -> Validator: return MultiColumnConstraintValidator( - MultiColumnConstraintValidatorOptions(constraints=constraints, operator=operator, report_mode=report_mode) + MultiColumnConstraintValidatorOptions(constraints=tuple(constraints), operator=operator, report_mode=report_mode) ) diff --git a/tests/langkit/validators/test_comparison.py b/tests/langkit/validators/test_comparison.py index b7a3aa1..e7d869b 100644 --- a/tests/langkit/validators/test_comparison.py +++ b/tests/langkit/validators/test_comparison.py @@ -155,10 +155,10 @@ def test_must_be_non_none(): def test_multiple_contraint_first_failure(): validator = MultiColumnConstraintValidator( MultiColumnConstraintValidatorOptions( - [ + ( ConstraintValidatorOptions("prompt.stats.char_count", lower_threshold=5), ConstraintValidatorOptions("prompt.stats.token_count", lower_threshold=5), - ] + ) ) ) wf = Workflow( @@ -188,10 +188,10 @@ def test_multiple_contraint_first_failure(): def test_multiple_constriant_all_failure(): validator = MultiColumnConstraintValidator( MultiColumnConstraintValidatorOptions( - [ + ( ConstraintValidatorOptions("prompt.stats.char_count", lower_threshold=5), ConstraintValidatorOptions("prompt.stats.token_count", lower_threshold=5), - ], + ), report_mode="ALL_FAILED_METRICS", operator="AND", ) @@ -234,10 +234,10 @@ def test_multiple_constriant_all_failure(): def test_multiple_constriant_all_failure_or(): validator = MultiColumnConstraintValidator( MultiColumnConstraintValidatorOptions( - [ + ( ConstraintValidatorOptions("prompt.stats.char_count", lower_threshold=4), ConstraintValidatorOptions("prompt.stats.token_count", lower_threshold=4), - ], + ), report_mode="ALL_FAILED_METRICS", operator="OR", ) @@ -268,10 +268,10 @@ def test_multiple_constriant_all_failure_or(): def test_multiple_constriant_first_failure_or(): validator = MultiColumnConstraintValidator( MultiColumnConstraintValidatorOptions( - [ + ( ConstraintValidatorOptions("prompt.stats.char_count", lower_threshold=4), ConstraintValidatorOptions("prompt.stats.token_count", lower_threshold=4), - ], + ), report_mode="FIRST_FAILED_METRIC", operator="OR", ) @@ -302,11 +302,11 @@ def test_multiple_constriant_first_failure_or(): def test_multiple_constriant_first_failure_or_multiple_failures(): validator = MultiColumnConstraintValidator( MultiColumnConstraintValidatorOptions( - [ + ( ConstraintValidatorOptions("prompt.stats.char_count", upper_threshold=100), ConstraintValidatorOptions("prompt.stats.token_count", upper_threshold=1), ConstraintValidatorOptions("prompt.regex.email_address", upper_threshold=0), - ], + ), report_mode="FIRST_FAILED_METRIC", operator="OR", ) @@ -338,11 +338,11 @@ def test_multiple_constriant_first_failure_or_multiple_failures(): def test_multiple_constriant_first_failure_and_ordering(): validator = MultiColumnConstraintValidator( MultiColumnConstraintValidatorOptions( - [ + ( ConstraintValidatorOptions("prompt.regex.email_address", upper_threshold=0), ConstraintValidatorOptions("prompt.stats.char_count", upper_threshold=1), ConstraintValidatorOptions("prompt.stats.token_count", upper_threshold=1), - ], + ), report_mode="FIRST_FAILED_METRIC", operator="AND", )