Skip to content

Commit

Permalink
small review done in meeting (reverted exception handling in GroupSlo…
Browse files Browse the repository at this point in the history
…t, test#3 tweaked(SlotEqualsValue) ), added SlotEqualsValue condition to existing tutorial
  • Loading branch information
ZergLev committed Dec 12, 2024
1 parent 4534466 commit 729d449
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 7 deletions.
12 changes: 7 additions & 5 deletions chatsky/slots/base_slots.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()})

Expand Down Expand Up @@ -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
Expand Down
6 changes: 4 additions & 2 deletions tests/slots/test_slot_functions.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand All @@ -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)

Expand Down
2 changes: 2 additions & 0 deletions tutorials/slots/1_basic_example.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 729d449

Please sign in to comment.