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 38 commits into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
38 commits
Select commit Hold shift + click to select a range
868f5ef
added SlotValueEquals, drafted RegexpGroupSlot, formatting a GroupSlo…
ZergLev Nov 22, 2024
80500f6
removed checking for funder names in slot names for GroupSlot + lint
ZergLev Nov 22, 2024
03fed9e
moved SlotManager into it's own file, ValueSlot back into base_slots,…
ZergLev Nov 25, 2024
eb0a528
changed RegexpGroupSlot to use regex only once, updated slot imports …
ZergLev Nov 25, 2024
036cf07
renamed 'success_only' to 'save_on_failure'
ZergLev Nov 25, 2024
14c651c
lint
ZergLev Nov 25, 2024
306cb84
refactored RegexGroupSlot, changed description for it
ZergLev Nov 27, 2024
36a3d2b
refactor: moved Extracted slots and GroupSlot into base_slots.py
ZergLev Nov 27, 2024
c18d01a
refactor: updated slot imports across the codebase (according to the …
ZergLev Nov 27, 2024
a49984b
drafted pipeline.yaml test files updates, test_script_parsing's TestI…
ZergLev Nov 27, 2024
c0ee05a
renamed slots.py -> standard_slots.py
ZergLev Dec 2, 2024
ad6d906
drafting dictionary validator for GorupSlot (unfinished)
ZergLev Dec 2, 2024
4e0215e
drafted model_validator for GroupSlot
ZergLev Dec 2, 2024
fe2a382
reverted pipeline.yml changes
ZergLev Dec 2, 2024
4423850
reverted changes for GroupSlot (extra fields are back), renamed value…
ZergLev Dec 4, 2024
2794f8f
made string_format Optional[]
ZergLev Dec 4, 2024
a33a4f7
moved ValueSlot before GroupSlot
ZergLev Dec 4, 2024
ce8f606
changed RegexGroupSlot base class to BaseSlot
ZergLev Dec 4, 2024
d9aa6b2
fixed tests, they pass now
ZergLev Dec 4, 2024
b361ea0
added default_values to RegexpGroupSlot, fixed an issue with get_valu…
ZergLev Dec 4, 2024
7e4580a
minor changes, lint, porting to laptop
ZergLev Dec 11, 2024
c53ffd1
added the string_format test, added exception handling for string rep…
ZergLev Dec 11, 2024
b254bd8
started tutorial for RegexpGroupSlot and string_format feature of Gro…
ZergLev Dec 11, 2024
89eee15
fixed test for string_format, works now
ZergLev Dec 11, 2024
4534466
added SlotValueEquals in test_slot_functions.py, this particular chan…
ZergLev Dec 11, 2024
729d449
small review done in meeting (reverted exception handling in GroupSlo…
ZergLev Dec 12, 2024
01731df
added docs for _flatten_group_slot
ZergLev Dec 13, 2024
14cc4fd
lint + SlotEqualsValue condition fixed (tests pass now)
ZergLev Dec 13, 2024
9890179
minor fix for doc building (title underscores added)
ZergLev Dec 13, 2024
fc5bc58
Updating API reference
ZergLev Dec 13, 2024
4d9f790
started the RegexpGroupSlot and string_format tutorial
ZergLev Dec 13, 2024
41ef517
model_validator added for RegexpGroupSlot (checking that groups() dic…
ZergLev Dec 16, 2024
575ad22
fixed weird test bug, will discuss during call
ZergLev Dec 16, 2024
efdb7f1
lint + pydantic fields validation changed at the work call, tutorial …
ZergLev Jan 9, 2025
0f70b0f
tutorial code written, testing now
ZergLev Jan 10, 2025
550a437
tutorial fixed and slightly simplified, made a minor change to Regexp…
ZergLev Jan 10, 2025
d38207d
string_format fixed
ZergLev Jan 10, 2025
870481d
lint
ZergLev Jan 10, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions chatsky/__rebuild_pydantic_models__.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# flake8: noqa: F401

from chatsky.core.service.types import ExtraHandlerRuntimeInfo, ComponentExecutionState
from chatsky.core import Context, Script
from chatsky.core import Context, Message, Script
from chatsky.core.script import Node
from chatsky.core.pipeline import Pipeline
from chatsky.slots.slots import SlotManager
from chatsky.slots.standard_slots import FunctionSlot
from chatsky.slots.slot_manager import SlotManager
from chatsky.core.context import FrameworkData, ServiceState
from chatsky.core.service import PipelineComponent

Expand All @@ -15,3 +16,4 @@
ExtraHandlerRuntimeInfo.model_rebuild()
FrameworkData.model_rebuild()
ServiceState.model_rebuild()
FunctionSlot.model_rebuild()
2 changes: 1 addition & 1 deletion chatsky/conditions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,5 @@
Not,
HasCallbackQuery,
)
from chatsky.conditions.slots import SlotsExtracted
from chatsky.conditions.slots import SlotsExtracted, SlotValueEquals
from chatsky.conditions.service import ServiceFinished
28 changes: 26 additions & 2 deletions chatsky/conditions/slots.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
"""

from __future__ import annotations
from typing import Literal, List
from typing import Literal, List, Any

from chatsky.core import Context, BaseCondition
from chatsky.slots.slots import SlotName
from chatsky.slots.slot_manager import SlotName


class SlotsExtracted(BaseCondition):
Expand Down Expand Up @@ -36,3 +36,27 @@ async def call(self, ctx: Context) -> bool:
return all(manager.is_slot_extracted(slot) for slot in self.slots)
elif self.mode == "any":
return any(manager.is_slot_extracted(slot) for slot in self.slots)


class SlotValueEquals(BaseCondition):
"""
Check if :py:attr:`.slot_name`'s extracted value is equal to a given value.

:raises KeyError: If the slot with the specified name does not exist.
"""

slot_name: SlotName
"""
Name of the slot that needs to be checked.
"""
value: Any
"""
The value which the slot's extracted value is supposed to be checked against.
"""

def __init__(self, slot_name: SlotName, value: Any):
super().__init__(slot_name=slot_name, value=value)

async def call(self, ctx: Context) -> bool:
manager = ctx.framework_data.slot_manager
return manager.get_extracted_slot(self.slot_name).value == self.value
2 changes: 1 addition & 1 deletion chatsky/core/context.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
from pydantic import BaseModel, Field

from chatsky.core.message import Message, MessageInitTypes
from chatsky.slots.slots import SlotManager
from chatsky.slots.slot_manager import SlotManager
from chatsky.core.node_label import AbsoluteNodeLabel, AbsoluteNodeLabelInitTypes

if TYPE_CHECKING:
Expand Down
2 changes: 1 addition & 1 deletion chatsky/core/pipeline.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

from chatsky.messengers.console import CLIMessengerInterface
from chatsky.messengers.common import MessengerInterface
from chatsky.slots.slots import GroupSlot
from chatsky.slots import GroupSlot
from chatsky.core.service.group import ServiceGroup, ServiceGroupInitTypes
from chatsky.core.service.extra import ComponentExtraHandlerInitTypes, BeforeHandler, AfterHandler
from .service import Service
Expand Down
10 changes: 5 additions & 5 deletions chatsky/processing/slots.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
import logging
from typing import List

from chatsky.slots.slots import SlotName
from chatsky.slots.slot_manager import SlotName
from chatsky.core import Context, BaseProcessing
from chatsky.responses.slots import FilledTemplate

Expand All @@ -24,16 +24,16 @@ class Extract(BaseProcessing):

slots: List[SlotName]
"""A list of slot names to extract."""
success_only: bool = True
save_on_failure: bool = True
"""If set, only successfully extracted values will be stored in the slot storage."""

def __init__(self, *slots: SlotName, success_only: bool = True):
super().__init__(slots=slots, success_only=success_only)
def __init__(self, *slots: SlotName, save_on_failure: bool = True):
super().__init__(slots=slots, save_on_failure=save_on_failure)

async def call(self, ctx: Context):
manager = ctx.framework_data.slot_manager
results = await asyncio.gather(
*(manager.extract_slot(slot, ctx, self.success_only) for slot in self.slots), return_exceptions=True
*(manager.extract_slot(slot, ctx, self.save_on_failure) for slot in self.slots), return_exceptions=True
)

for result in results:
Expand Down
3 changes: 2 additions & 1 deletion chatsky/slots/__init__.py
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
from chatsky.slots.slots import GroupSlot, ValueSlot, RegexpSlot, FunctionSlot
from chatsky.slots.standard_slots import RegexpSlot, RegexpGroupSlot, FunctionSlot
from chatsky.slots.base_slots import GroupSlot, ValueSlot
Loading
Loading