39 lines
1.3 KiB
Python
39 lines
1.3 KiB
Python
from dataclasses import dataclass
|
|
from hashlib import sha256
|
|
|
|
from app.llm.schemas import Classification
|
|
|
|
|
|
@dataclass(frozen=True)
|
|
class ProactiveDecision:
|
|
respond: bool
|
|
reason: str
|
|
fingerprint: str
|
|
|
|
|
|
def decide(
|
|
mode: str,
|
|
classification: Classification,
|
|
*,
|
|
is_mention: bool,
|
|
duplicate: bool,
|
|
cooldown: bool,
|
|
threshold: float,
|
|
) -> ProactiveDecision:
|
|
fingerprint = sha256(repr(classification).encode()).hexdigest()
|
|
if mode == "off":
|
|
return ProactiveDecision(False, "mode_off", fingerprint)
|
|
if mode == "mentions" and not is_mention:
|
|
return ProactiveDecision(False, "not_mentioned", fingerprint)
|
|
if duplicate or cooldown:
|
|
return ProactiveDecision(False, "anti_spam", fingerprint)
|
|
if not classification.is_question or classification.rhetorical:
|
|
return ProactiveDecision(False, "not_actionable_question", fingerprint)
|
|
if not classification.project_related:
|
|
return ProactiveDecision(False, "not_project_related", fingerprint)
|
|
if classification.asks_new_decision:
|
|
return ProactiveDecision(False, "requires_human_decision", fingerprint)
|
|
if classification.confidence < threshold:
|
|
return ProactiveDecision(False, "low_confidence", fingerprint)
|
|
return ProactiveDecision(True, "confirmed_fact_candidate", fingerprint)
|