56 行
2 KiB
Python
56 行
2 KiB
Python
"""Transport-safe results for conversational workflow candidate feedback."""
|
|
|
|
from __future__ import annotations
|
|
|
|
from dataclasses import dataclass
|
|
from typing import Any
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class WorkflowFeedbackCandidateRef:
|
|
"""A candidate resolved through a caller-owned display-code whitelist."""
|
|
|
|
candidate_id: str
|
|
display_code: str
|
|
|
|
def to_dict(self) -> dict[str, str]:
|
|
return {
|
|
"candidate_id": self.candidate_id,
|
|
"display_code": self.display_code,
|
|
}
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class WorkflowFeedbackInterpretation:
|
|
"""Validated feedback actions extracted from one conversational message."""
|
|
|
|
liked: tuple[WorkflowFeedbackCandidateRef, ...] = ()
|
|
rejected: tuple[WorkflowFeedbackCandidateRef, ...] = ()
|
|
strict_rejected: tuple[WorkflowFeedbackCandidateRef, ...] = ()
|
|
final: WorkflowFeedbackCandidateRef | None = None
|
|
material_intent: str | None = None
|
|
next_round_prompt_patch: str | None = None
|
|
positive_patch: str | None = None
|
|
negative_patch: str | None = None
|
|
source: str = "deterministic"
|
|
source_text: str = ""
|
|
metadata: dict[str, Any] | None = None
|
|
|
|
@property
|
|
def has_candidate_feedback(self) -> bool:
|
|
return bool(self.liked or self.rejected or self.strict_rejected or self.final)
|
|
|
|
def to_dict(self) -> dict[str, Any]:
|
|
return {
|
|
"liked": [candidate.to_dict() for candidate in self.liked],
|
|
"rejected": [candidate.to_dict() for candidate in self.rejected],
|
|
"strict_rejected": [candidate.to_dict() for candidate in self.strict_rejected],
|
|
"final": self.final.to_dict() if self.final else None,
|
|
"material_intent": self.material_intent,
|
|
"next_round_prompt_patch": self.next_round_prompt_patch,
|
|
"positive_patch": self.positive_patch or self.next_round_prompt_patch,
|
|
"negative_patch": self.negative_patch,
|
|
"source": self.source,
|
|
"source_text": self.source_text,
|
|
"metadata": dict(self.metadata or {}),
|
|
}
|