GitHub

API reference for Service.

The in-memory tracker make builds; mutable, so make gives a fresh one each run.

Functions

__init__

__init__() -> None
def __init__(self) -> None:
    self._sent: dict[int, tuple[object, str]] = {}

clear_unsafe

clear_unsafe() -> None

Forget 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) -> None

Remember that the messages parts (by identity) were sent with the response response_id; a message marked again takes the new id.

ParameterTypeDescription
partsSequence[object]
response_idstr
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 | 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.

ParameterTypeDescription
promptP.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