The in-memory tracker make builds; mutable, so make gives a
fresh one each run.
Functions#
__init__#
__init__() -> Nonedef __init__(self) -> None:
self._sent: dict[int, tuple[object, str]] = {}clear_unsafe#
clear_unsafe() -> NoneForget every message marked so far.
def clear_unsafe(self) -> None:
"""Forget every message marked so far."""
self._sent.clear()mark_parts#
mark_parts(parts, response_id) -> NoneRemember that the messages parts (by identity) were sent with
the response response_id; a message marked again takes the new
id.
| Parameter | Type | Description |
|---|---|---|
parts | Sequence[object] | |
response_id | str |
def mark_parts(self, parts: Sequence[object], response_id: str) -> None:
"""Remember that the messages ``parts`` (by identity) were sent with
the response ``response_id``; a message marked again takes the new
id."""
for part in parts:
self._sent[id(part)] = (part, response_id)prepare_unsafe#
prepare_unsafe(prompt) -> PrepareResult | NoneThe previous response id and the messages after prompt's last
assistant message, when every message before that assistant message
was marked (the id is the last of theirs) and some message follows
it. Otherwise None, and everything marked is forgotten.
| Parameter | Type | Description |
|---|---|---|
prompt | P.Prompt |
Returns PrepareResult | None
def prepare_unsafe(self, prompt: P.Prompt) -> PrepareResult | None:
"""The previous response id and the messages after ``prompt``'s last
assistant message, when every message before that assistant message
was marked (the id is the last of theirs) and some message follows
it. Otherwise ``None``, and everything marked is forgotten."""
messages = prompt.content
result = self._prepare(messages)
if result is None:
self._sent.clear()
return result