-
-
Notifications
You must be signed in to change notification settings - Fork 522
feat(checks): add Trace.steps() helper for step-based grouping #2481
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
Open
harsh21234i
wants to merge
8
commits into
Giskard-AI:main
Choose a base branch
from
harsh21234i:feat/trace-steps-helper
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
78f876f
feat(checks): add trace step grouping helper
02081f5
refactor(checks): simplify trace step tagging
084bb21
fix(checks): stamp step metadata during interaction generation
46c91d2
Merge branch 'main' into feat/trace-steps-helper
harsh21234i df2b819
Merge branch 'main' into feat/trace-steps-helper
kevinmessiaen f4b4c5b
Merge branch 'main' into feat/trace-steps-helper
harsh21234i 55cea1a
Merge branch 'main' into feat/trace-steps-helper
henchaves 1406f5f
Merge main into trace steps helper
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,54 @@ | ||
| import pytest | ||
| from giskard.checks import Equals, Interaction, Scenario, Trace | ||
| from giskard.checks.scenarios.runner import ScenarioRunner | ||
|
|
||
|
|
||
| def test_trace_steps_returns_empty_list_for_empty_trace(): | ||
| trace = Trace[str, str]() | ||
|
|
||
| assert trace.steps() == [] | ||
|
|
||
|
|
||
| def test_trace_steps_groups_single_step_without_metadata(): | ||
| trace = Trace[str, str]( | ||
| interactions=[ | ||
| Interaction(inputs="a", outputs="A"), | ||
| Interaction(inputs="b", outputs="B"), | ||
| ] | ||
| ) | ||
|
|
||
| assert trace.steps() == [trace.interactions] | ||
|
|
||
|
|
||
| def test_trace_steps_groups_multiple_steps_by_step_index(): | ||
| first = Interaction(inputs="a", outputs="A", metadata={"step_index": 0}) | ||
| second = Interaction(inputs="b", outputs="B", metadata={"step_index": 0}) | ||
| third = Interaction(inputs="c", outputs="C", metadata={"step_index": 1}) | ||
| fourth = Interaction(inputs="d", outputs="D", metadata={"step_index": 2}) | ||
|
|
||
| trace = Trace[str, str](interactions=[first, second, third, fourth]) | ||
|
|
||
| assert trace.steps() == [ | ||
| [first, second], | ||
| [third], | ||
| [fourth], | ||
| ] | ||
|
|
||
|
|
||
| @pytest.mark.asyncio | ||
| async def test_scenario_runner_tags_trace_interactions_with_step_index(): | ||
| scenario = ( | ||
| Scenario("multi_step") | ||
| .interact("hello", "HELLO") | ||
| .check(Equals(expected_value="HELLO", key="trace.last.outputs")) | ||
| .interact("world", "WORLD") | ||
| ) | ||
|
|
||
| result = await ScenarioRunner().run(scenario) | ||
|
|
||
| assert result.final_trace.steps() == [ | ||
| [result.final_trace.interactions[0]], | ||
| [result.final_trace.interactions[1]], | ||
| ] | ||
| assert result.final_trace.interactions[0].metadata["step_index"] == 0 | ||
| assert result.final_trace.interactions[1].metadata["step_index"] == 1 |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.