|
1 | 1 | from typing import List |
2 | 2 |
|
3 | | -from eval_protocol.models import EvaluationRow |
| 3 | +from eval_protocol.models import EvaluationRow, Message |
4 | 4 | from eval_protocol.pytest.default_no_op_rollout_processor import NoOpRolloutProcessor |
5 | 5 | from tests.pytest.test_markdown_highlighting import markdown_dataset_to_evaluation_row |
6 | 6 |
|
@@ -37,5 +37,61 @@ def eval_fn(row: EvaluationRow) -> EvaluationRow: |
37 | 37 | for params in completion_params_list: |
38 | 38 | await eval_fn(dataset_path=[ds_path], completion_params=params) |
39 | 39 |
|
| 40 | + # Second invocation to ensure that IDs are stable across multiple invocations |
| 41 | + for ds_path in input_dataset: |
| 42 | + for params in completion_params_list: |
| 43 | + await eval_fn(dataset_path=[ds_path], completion_params=params) |
| 44 | + |
40 | 45 | # Assertions on IDs generated by the decorator logic |
41 | 46 | assert len(row_ids) == 19 # from the markdown dataset |
| 47 | + |
| 48 | + |
| 49 | +async def test_evaluation_test_generated_row_ids_without_dataset_keys(): |
| 50 | + from eval_protocol.pytest.evaluation_test import evaluation_test |
| 51 | + |
| 52 | + # Adapter that does NOT set row_id; lets evaluation_test generate IDs |
| 53 | + def markdown_dataset_no_row_id_adapter(data: List[dict]) -> List[EvaluationRow]: |
| 54 | + return [ |
| 55 | + EvaluationRow( |
| 56 | + messages=[Message(role="user", content=row["prompt"])], |
| 57 | + ground_truth=str(row["num_highlights"]), |
| 58 | + ) |
| 59 | + for row in data |
| 60 | + ] |
| 61 | + |
| 62 | + row_ids = set() |
| 63 | + |
| 64 | + input_dataset = ["tests/pytest/data/markdown_dataset.jsonl", "tests/pytest/data/markdown_dataset.jsonl"] |
| 65 | + completion_params = [ |
| 66 | + {"temperature": 0.0, "model": "dummy/local-model"}, |
| 67 | + {"temperature": 1.0, "model": "dummy/local-model"}, |
| 68 | + ] |
| 69 | + |
| 70 | + @evaluation_test( |
| 71 | + input_dataset=input_dataset, |
| 72 | + completion_params=completion_params, |
| 73 | + dataset_adapter=markdown_dataset_no_row_id_adapter, |
| 74 | + rollout_processor=NoOpRolloutProcessor(), |
| 75 | + mode="pointwise", |
| 76 | + combine_datasets=False, |
| 77 | + num_runs=5, |
| 78 | + ) |
| 79 | + def eval_fn(row: EvaluationRow) -> EvaluationRow: |
| 80 | + # row_id should be auto-generated by evaluation_test/InputMetadata |
| 81 | + assert row.input_metadata is not None |
| 82 | + assert row.input_metadata.row_id is not None and isinstance(row.input_metadata.row_id, str) |
| 83 | + row_ids.add(row.input_metadata.row_id) |
| 84 | + return row |
| 85 | + |
| 86 | + # Single invocation (one dataset, one param set) with multiple runs |
| 87 | + for ds_path in input_dataset: |
| 88 | + for params in completion_params: |
| 89 | + await eval_fn(dataset_path=[ds_path], completion_params=params) |
| 90 | + |
| 91 | + # Second invocation to ensure that IDs are stable across multiple invocations |
| 92 | + for ds_path in input_dataset: |
| 93 | + for params in completion_params: |
| 94 | + await eval_fn(dataset_path=[ds_path], completion_params=params) |
| 95 | + |
| 96 | + # Even with multiple runs, generated row_ids should be stable within the invocation |
| 97 | + assert len(row_ids) == 19 # equals dataset size when IDs are generated once and preserved across runs |
0 commit comments