mellea.helpers.chat_helpers
Backend-neutral helpers for inspecting assembled chat conversations.
Functions
FUNC has_user_content
has_user_content(messages: list[Message]) -> bool
Whether the assembled conversation carries real user-role content.
Guards against sending a chat request whose user turns are all empty:
SimpleContext intentionally discards recorded turns from
view_for_generation(), so a caller who chains .add(...) and then
passes an empty action would otherwise hit the model with no user-role
content at all. Some chat models spin on empty prompts and burn tokens
silently. Whitespace-only text counts as empty; images, audio, and
documents count as content.
Args:
messages: The chat messages about to be sent to the model.
Returns:
- True if any user-role message has non-whitespace text, images,
- audio, or documents; False otherwise.