raise ValueError("a history item may contain only selected_id and outcome")
clean_history.append({k: _text(v, f"history {k}", 160) for k, v in entry.items()})
candidates = request.get("candidates")
if not isinstance(candidates, list) or not 2 <= len(candidates) <= MAX_CANDIDATES:
raise ValueError(f"candidates must hold between 2 and {MAX_CANDIDATES} actions")
table: Dict[str, str] = {}
for candidate in candidates:
if not isinstance(candidate, Mapping) or set(candidate) != {"id", "description"}:
raise ValueError("a candidate must contain exactly id and description")
identifier = candidate["id"]
if not isinstance(identifier, str) or not _ID.fullmatch(identifier) or identifier in table:
raise ValueError("candidate ids must be unique and use only letters, digits and . _ : -")
table[identifier] = _text(candidate["description"], "candidate description", 600)
if not {"reobserve", "abstain"} <= set(table):
raise ValueError("candidates must include `reobserve` and `abstain`")
return {"goal": _text(request.get("goal"), "goal", 2000), "observation_id": str(request.get("observation_id", ""))[:256],
"regions": clean_regions, "history": clean_history, "table": table}
def choose(request: Mapping[str, Any], *, timeout: float = 3.0, mock: bool = False,
transport: Optional[client.Transport] = None) -> Dict[str, Any]:
"""Raises ValueError for a bad request. A Jev failure returns ``reobserve``, never a guess."""
root@213-238-170-219:/home/hermes#