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

Adds one trick to pytest README #489

Merged
merged 1 commit into from
Dec 28, 2024
Merged
Changes from all commits
Commits
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
21 changes: 21 additions & 0 deletions examples/pytest/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,27 @@ def test_an_agent_e2e_with_tracker(input_state, expected_state, results_bag, tra
# place any asserts at the end of the test
assert exact_match
```
# One trick we like - run things multiple times

LLMs are inherently generative. So one way to explore and determine how the variance of a single prompt + data input leads to different outputs, is to run it multiple times.

With pytest this can take the form of a test that runs an action multiple times, and then aggregates the responses to see how different they are. Using this approach can help you better tweak prompts to reduce variance.

```python
def test_an_actions_stability():
"""Let's run it a few times to see output variability."""
audio = ...
outputs = [run_our_action(State({"audio": audio}))
for _ in range(5)]
# Check for consistency - for each key create a set of values
variances = {}
for key in outputs[0].keys():
all_values = set(json.dumps(output[key]) for output in outputs)
if len(all_values) > 1:
variances[key] = list(all_values)
variances_str = json.dumps(variances, indent=2)
assert len(variances) == 0, "Outputs vary across iterations:\n" + variances_str
```

# An example
Here in this directory we have:
Expand Down
Loading