29 lines
979 B
Python
29 lines
979 B
Python
"""Shared input shaping for session-level evaluation runs."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from collections.abc import Iterable, Mapping
|
|
|
|
from .services import guardrail
|
|
|
|
|
|
def enriched_masked_turns(
|
|
masked_turns: Iterable[Mapping[str, object]],
|
|
*,
|
|
counselor_identity: str | None = None,
|
|
client_identity: str | None = None,
|
|
) -> list[dict[str, object]]:
|
|
"""Attach turn sequence and role-safe identity tokens to evaluation input."""
|
|
enriched: list[dict[str, object]] = []
|
|
for index, turn in enumerate(masked_turns, start=1):
|
|
item = dict(turn)
|
|
speaker = str(item.get("speaker") or "")
|
|
item["text"] = guardrail.mask_role_identities(
|
|
str(item.get("text") or ""),
|
|
counselor_identity=counselor_identity,
|
|
client_identity=client_identity,
|
|
synthetic_generated=speaker == "client",
|
|
).text_masked
|
|
item["seq"] = index
|
|
enriched.append(item)
|
|
return enriched
|