Hash nested model fields by immutable value
This commit is contained in:
parent
a79c65757f
commit
48324403bb
1 changed files with 29 additions and 1 deletions
26
tests/test_output_hashing.py
Normal file
26
tests/test_output_hashing.py
Normal file
|
|
@ -0,0 +1,26 @@
|
|||
from great_ai import ClassificationOutput, MultiLabelClassificationOutput, Trace
|
||||
|
||||
|
||||
def test_output_models_hash_nested_mutable_fields_by_value() -> None:
|
||||
first = MultiLabelClassificationOutput(
|
||||
labels=[
|
||||
ClassificationOutput(
|
||||
label="a", confidence=0.5, explanation={"tokens": ["a", "b"]}
|
||||
)
|
||||
]
|
||||
)
|
||||
second = first.model_copy(deep=True)
|
||||
assert hash(first) == hash(second)
|
||||
assert len({first, second}) == 1
|
||||
|
||||
|
||||
def test_trace_hash_supports_its_dictionary_and_list_fields() -> None:
|
||||
trace: Trace = Trace(
|
||||
trace_id="id",
|
||||
created="2026-01-01",
|
||||
original_execution_time_ms=0,
|
||||
logged_values={"x": [1, 2]},
|
||||
models=[],
|
||||
tags=["online"],
|
||||
)
|
||||
assert hash(trace) == hash(trace.model_copy(deep=True))
|
||||
Loading…
Reference in a new issue