Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Slot Improvements #411

Open
wants to merge 33 commits into
base: dev
Choose a base branch
from
Open

Slot Improvements #411

wants to merge 33 commits into from

Conversation

ZergLev
Copy link
Collaborator

@ZergLev ZergLev commented Dec 13, 2024

Description

Refactored and added some features for existing Slots and a new type of slot - RegexpGroupSlot, which reuses one regex.search() call to save on execution time in specific cases like LLM, where the amount of get_value() calls is important. Also more minor changes like adding a new condition - SlotEqualsValue.

Changes relevant for the user:

  • Added SlotEqualsValue condition to check that a slot is equal to some value.
  • Added RegexpGroupSlot class. (e.g. (regexp=regexp, groups={"date": 1, "month": 2, "year": 3}) would yield ValueSlots with the respective numbers meaning the number of the group that was found with this regular expression) A better explanation can be found in the tutorials.
  • Group slots: Disallowed slots being named the same as class variables like string_format or allow_partial_extraction. A special exception will be raised in such cases.
  • GroupSlot now accepts string_format parameter, which makes it's ExtractedGroupSlot's __str__ representation formatted with extracted slot values being the keywords. (e.g. "{date}.{month}.{year}" is the value of a birthday group slot instead of "{'date': ..., 'month': ..., 'year': ...}") Almost the same as fill_template function in SlotManager class, except this doesn't catch exceptions. A better explanation will be provided in the tutorials.
  • Renamed success_only to save_on_failure.

Changes in the codebase (or others):

  • Added _flatten_group_slot method (for now a copy of flatten_llm_group_slot in LLM Slots PR), unpacks a GroupSlots nested Slots into a single dictionary.
  • Restructured slots.py (to reduce file length) -- moved concrete slot implementations to standard_slots.py, base classes are in base_slots.py, SlotManager is in slot_manager.py
  • Removed if TYPE_CHECKING in standard_slots.py to allow using FunctionSlot without importing Message first (no, rebuild it instead)
  • Pass previous slot value to slot extraction function (Write in tutorial how this is already possible)

Checklist

  • Production code changes done
  • Tests added
  • Check if I didn't update API reference anywhere
  • Add the 2_regexpgroupslot_and_string_format.py tutorial
  • I have performed a self-review of the changes

To Consider

  • Adding tools that simplify inheriting group slot and overwriting its get_value method to group multiple subslot extraction requests into one
  • Add a test for _flatten_group_slot(), there isn't one right now.
  • Update API reference / tutorials / guides
  • Update .ignore files, scripts (such as lint), distribution manifest (if files are added/deleted)
  • Search for references to changed entities in the codebase

…t with an f-string, moved derivative slots into a different file
…across the codebase (to the new file structure)
…e, finished the RegexpGroupSlot test, fixed a weird Pydantic inheritance issue
…resentation in ExtractedGroupSlot (SlotManager already does that, so I replicated that for coherence)
…t, test#3 tweaked(SlotEqualsValue) ), added SlotEqualsValue condition to existing tutorial
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant