From 729d4493e75521fb21da96c3f2d6720349fbb7c0 Mon Sep 17 00:00:00 2001 From: ZergLev Date: Thu, 12 Dec 2024 15:54:58 +0300 Subject: [PATCH] small review done in meeting (reverted exception handling in GroupSlot, test#3 tweaked(SlotEqualsValue) ), added SlotEqualsValue condition to existing tutorial --- chatsky/slots/base_slots.py | 12 +++++++----- tests/slots/test_slot_functions.py | 6 ++++-- tutorials/slots/1_basic_example.py | 2 ++ 3 files changed, 13 insertions(+), 7 deletions(-) diff --git a/chatsky/slots/base_slots.py b/chatsky/slots/base_slots.py index 3763ec791..5f1d05438 100644 --- a/chatsky/slots/base_slots.py +++ b/chatsky/slots/base_slots.py @@ -143,11 +143,7 @@ def __unset__(self): # fill template here def __str__(self): if self.string_format is not None: - try: - return KwargOnlyFormatter().format(self.string_format, **self.__pydantic_extra__) - except Exception as exc: - logger.exception("An exception occurred during template filling.", exc_info=exc) - return None + return KwargOnlyFormatter().format(self.string_format, **self.__pydantic_extra__) else: return str({key: str(value) for key, value in self.__pydantic_extra__.items()}) @@ -257,7 +253,13 @@ def __check_extra_field_names__(self): raise ValueError(f"Extra field names cannot be dunder: {field!r}") return self +# TODO: rewrite docs def _flatten_group_slot(self, slot, parent_key=""): + """ + Flattens GroupSlot from nested into a single dictionary. + + Helper method for reimplementing GroupSlots. + """ items = {} for key, value in slot.__pydantic_extra__.items(): new_key = f"{parent_key}.{key}" if parent_key else key diff --git a/tests/slots/test_slot_functions.py b/tests/slots/test_slot_functions.py index 6127475d2..df4d99ad1 100644 --- a/tests/slots/test_slot_functions.py +++ b/tests/slots/test_slot_functions.py @@ -60,6 +60,8 @@ async def test_basic_functions(context, manager, log_event_catcher): await proc.Extract("0", "2", "err").wrapped_call(context) assert manager.get_extracted_slot("0").value == 4 + assert await cnd.SlotValueEquals("0", 5) is False + assert await cnd.SlotValueEquals("0", 4) is True assert manager.is_slot_extracted("1") is False assert isinstance(manager.get_extracted_slot("err").extracted_value, SlotNotExtracted) @@ -69,8 +71,8 @@ async def test_basic_functions(context, manager, log_event_catcher): await proc.Extract("0", "2", "err", save_on_failure=False).wrapped_call(context) assert manager.get_extracted_slot("0").value == 4 - assert await cnd.SlotValueEquals("0", "5") is False - assert await cnd.SlotValueEquals("0", "4") is True + assert await cnd.SlotValueEquals("0", 5) is False + assert await cnd.SlotValueEquals("0", 4) is True assert manager.is_slot_extracted("1") is False assert isinstance(manager.get_extracted_slot("err").extracted_value, RuntimeError) diff --git a/tutorials/slots/1_basic_example.py b/tutorials/slots/1_basic_example.py index dcddfbade..56a1c19da 100644 --- a/tutorials/slots/1_basic_example.py +++ b/tutorials/slots/1_basic_example.py @@ -76,6 +76,8 @@ - %mddoclink(api,conditions.slots,SlotsExtracted): Condition for checking if specified slots are extracted. +- %mddoclink(api,conditions.slots,SlotValueEquals): + Condition for checking if the specified slots' value is equal to a given value. - %mddoclink(api,processing.slots,Extract): A processing function that extracts specified slots. - %mddoclink(api,processing.slots,Unset):