Skip to content

Commit

Permalink
started the RegexpGroupSlot and string_format tutorial
Browse files Browse the repository at this point in the history
  • Loading branch information
ZergLev committed Dec 13, 2024
1 parent fc5bc58 commit 4d9f790
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 1 deletion.
1 change: 1 addition & 0 deletions chatsky/slots/standard_slots.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
28 changes: 28 additions & 0 deletions tutorials/slots/2_regexgroupslot_and_string_format.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down

0 comments on commit 4d9f790

Please sign in to comment.