Skip to content

Commit 3bd0d42

Browse files
authored
refactor(giskard-checks)!: remove Scenario.from_sequence
2 parents d1ab25f + 311cbf9 commit 3bd0d42

4 files changed

Lines changed: 15 additions & 46 deletions

File tree

libs/giskard-checks/README.md

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -280,7 +280,7 @@ from giskard.checks import Scenario
280280

281281
chat = ChatInteraction(session_id="session_123", messages=["hi", "hello"])
282282
check = AdvancedSecurityCheck(name="security_test", threshold=0.7)
283-
scenario = Scenario.from_sequence(chat, check, name="custom_test")
283+
scenario = Scenario(name="custom_test").extend(chat, check)
284284

285285
serialized = scenario.model_dump()
286286
restored = Scenario.model_validate(serialized)
@@ -552,10 +552,9 @@ from giskard.checks import (
552552
Equals # Inherits from `Check`
553553
)
554554

555-
scenario = Scenario.from_sequence(
555+
scenario = Scenario(name="programmatic_scenario").extend(
556556
Interact(inputs="Hello", outputs=lambda inputs: "Hi"),
557557
Equals(expected_value="Hi", key="trace.last.outputs"),
558-
name="programmatic_scenario",
559558
)
560559

561560
result = await scenario.run()

libs/giskard-checks/src/giskard/checks/core/scenario.py

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ class Scenario[InputType, OutputType, TraceType: Trace](BaseModel): # pyright:
4848
result = await scenario.run()
4949
5050
For advanced usage you can instantiate with pre-filled steps or use
51-
``from_sequence()`` for a flat list of components:
51+
``extend()`` for a flat list of components:
5252
5353
from giskard.checks import Scenario, Interact, Equals
5454
scenario = Scenario(
@@ -110,36 +110,6 @@ def __init__(
110110
kwargs["name"] = name
111111
super().__init__(**kwargs)
112112

113-
@classmethod
114-
def from_sequence(
115-
cls,
116-
*components: (
117-
InteractionSpec[InputType, OutputType, TraceType]
118-
| Check[InputType, OutputType, TraceType]
119-
),
120-
name: str = "Unnamed Scenario",
121-
trace_type: type[TraceType] | None = None,
122-
annotations: dict[str, Any] | None = None,
123-
target: (
124-
ProviderType[[InputType], OutputType]
125-
| ProviderType[[InputType, TraceType], OutputType]
126-
| NotProvided
127-
) = NOT_PROVIDED,
128-
) -> Self:
129-
"""Create a scenario from a flat sequence of components.
130-
131-
Components are grouped into steps: a new step is created whenever an
132-
InteractionSpec follows a Check.
133-
"""
134-
without_steps = cls(
135-
name=name,
136-
trace_type=trace_type,
137-
annotations=annotations or {},
138-
target=target,
139-
)
140-
141-
return without_steps.extend(*components)
142-
143113
def _append_step(self) -> Step[InputType, OutputType, TraceType]:
144114
"""Append a new step."""
145115
step = Step(interacts=[], checks=[])

libs/giskard-checks/tests/core/test_scenario.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,24 +1016,23 @@ async def test_interact_with_trace_dependent_inputs(self):
10161016
assert result.final_trace.interactions[0].outputs == "Received: Message #1"
10171017

10181018

1019-
class TestScenarioFromSequenceAndSerialization:
1020-
"""Test Scenario.from_sequence() and step-based serialization."""
1019+
class TestScenarioExtendAndSerialization:
1020+
"""Test Scenario.extend() and step-based serialization."""
10211021

1022-
async def test_from_sequence_equivalent_to_fluent_api(self):
1023-
"""Scenario.from_sequence() produces same result as fluent API."""
1022+
async def test_extend_equivalent_to_fluent_api(self):
1023+
"""Scenario(...).extend(...) produces same result as fluent API."""
10241024
fluent = (
10251025
Scenario("fluent")
10261026
.interact("Hello", "Hi")
10271027
.check(Equals(expected_value="Hi", key="trace.last.outputs"))
10281028
.interact("World", "Echo: World")
10291029
.check(Equals(expected_value="Echo: World", key="trace.last.outputs"))
10301030
)
1031-
from_seq = Scenario.from_sequence(
1031+
from_seq = Scenario(name="fluent").extend(
10321032
Interact(inputs="Hello", outputs="Hi"),
10331033
Equals(expected_value="Hi", key="trace.last.outputs"),
10341034
Interact(inputs="World", outputs="Echo: World"),
10351035
Equals(expected_value="Echo: World", key="trace.last.outputs"),
1036-
name="fluent",
10371036
)
10381037

10391038
result_fluent = await fluent.run()
@@ -1045,10 +1044,10 @@ async def test_from_sequence_equivalent_to_fluent_api(self):
10451044
result_from_seq.final_trace.interactions
10461045
)
10471046

1048-
async def test_from_sequence_with_only_checks(self):
1049-
"""from_sequence handles scenario starting with checks only."""
1047+
async def test_extend_with_only_checks(self):
1048+
"""extend handles scenario starting with checks only."""
10501049
check = MockCheck(result=CheckResult.success(message="OK"))
1051-
scenario = Scenario.from_sequence(check, name="checks_only")
1050+
scenario = Scenario(name="checks_only").extend(check)
10521051
result = await scenario.run()
10531052
assert result.passed
10541053
assert len(result.steps) == 1

libs/giskard-checks/tests/integration/test_stateless.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,10 @@ async def adapter(message: agents.Message, trace: MessageTraces) -> agents.Messa
9191
async def test_single_message(
9292
adapter: Callable[[agents.Message, MessageTraces], Awaitable[agents.Message]],
9393
):
94-
scenario = Scenario[Any, Any, MessageTraces].from_sequence(
94+
scenario = Scenario[Any, Any, MessageTraces](
95+
name="test_single_message",
96+
trace_type=MessageTraces,
97+
).extend(
9598
WithSpy(
9699
interaction_generator=Interact(
97100
inputs=agents.Message(
@@ -122,8 +125,6 @@ async def test_single_message(
122125
expected_value="Hello, I want to apply for a job.",
123126
key="trace.interactions[-1].metadata['tests.integration.test_stateless.mock_apply_tool']['call_args'].args[1]",
124127
),
125-
name="test_single_message",
126-
trace_type=MessageTraces,
127128
)
128129
result = await scenario.run()
129130
assert result.failed # No tool call is made somehow

0 commit comments

Comments
 (0)