16 lines
539 B
Python
16 lines
539 B
Python
from typing import Any
|
|
from collections import Counter
|
|
from fusionagi._logger import logger
|
|
|
|
def consensus_vote(answers: list, key=None):
|
|
if not answers:
|
|
return None
|
|
values = [a.get(key, a) if isinstance(a, dict) else a for a in answers] if key else list(answers)
|
|
return Counter(values).most_common(1)[0][0]
|
|
|
|
def arbitrate(proposals: list, arbitrator="coordinator"):
|
|
if not proposals:
|
|
return {}
|
|
logger.info("Arbitrate", extra={"arbitrator": arbitrator, "count": len(proposals)})
|
|
return proposals[0]
|