diff --git a/chatsky/slots/standard_slots.py b/chatsky/slots/standard_slots.py index 364940b1b..f361c9817 100644 --- a/chatsky/slots/standard_slots.py +++ b/chatsky/slots/standard_slots.py @@ -69,6 +69,7 @@ class RegexpGroupSlot(GroupSlot, extra="forbid", frozen=True): groups: dict[str, int] "A dictionary mapping slot names to match_group indexes." default_values: dict[str, Any] = Field(default_factory=dict) + # TODO: write docstring, could copy from tutorial def __init__(self, **kwargs): # supress unexpected argument warnings super().__init__(**kwargs) diff --git a/tutorials/slots/2_regexgroupslot_and_string_format.py b/tutorials/slots/2_regexgroupslot_and_string_format.py index e919fc106..91826fd66 100644 --- a/tutorials/slots/2_regexgroupslot_and_string_format.py +++ b/tutorials/slots/2_regexgroupslot_and_string_format.py @@ -32,6 +32,34 @@ # %% [markdown] """ +## RegexpGroupSlot extraction + +The `RegexpGroupSlot` class reuses one regex.search() call to save on +execution time in specific cases like LLM, where the amount of get_value() +calls is important. + +## RegexpGroupSlot arguments + +* `regexp` - the regular expression to match with the `ctx.last_request.text`. +* `groups` - a dictionary mapping slot names to group indexes, where numbers + mean the index of the capture group that was found with `re.search()` +* `default_values` - a list of functions that run after the service. + You can read more about the handlers in this [tutorial] + +This means higher efficiency than a GroupSlot of RegexpSlots, +because only a single regex search is performed. It is saved and reused +for all specified groups, thus reducing the amount of calls to your model, +for example an LLM model. + +The `RegexpGroupSlot` class is derived from `GroupSlot` class, inheriting +its `string_format()` feature, which will be explained later in this tutorial. +Though, `partial extraction` is turned off for this class. + +This means that unsuccessfully trying to extract a slot will not overwrite +its previously extracted value. + +Note that `save_on_failure` is `True` by default. + The slots fall into the following category groups: - Value slots can be used to extract slot values from user utterances. diff --git a/tutorials/slots/2_partial_extraction.py b/tutorials/slots/3_partial_extraction.py similarity index 99% rename from tutorials/slots/2_partial_extraction.py rename to tutorials/slots/3_partial_extraction.py index aa8e7875e..7f4d7c4fa 100644 --- a/tutorials/slots/2_partial_extraction.py +++ b/tutorials/slots/3_partial_extraction.py @@ -1,6 +1,6 @@ # %% [markdown] """ -# 2. Partial slot extraction +# 3. Partial slot extraction This tutorial shows advanced options for slot extraction allowing to extract only some of the slots.