cache_key

def cache_key(content: MessageContentType, *args: Hashable) -> str

Calculates the cache key for the given message content and any other hashable args.

Arguments:

  • content MessageContentType - The message content to calculate the cache key for.
  • *args - Any additional hashable args to include in the cache key.

cache_content_get

def cache_content_get(cache: Optional[AbstractCache],
                      key: str) -> Optional[tuple[MessageContentType, ...]]

Retrieves cachedd content from the cache.

Arguments:

  • cache None or AbstractCache - The cache to retrieve the content from. If None, the cache is ignored.
  • key str - The key to retrieve the content from.

cache_content_set

def cache_content_set(cache: Optional[AbstractCache], key: str,
                      content: MessageContentType, *extra_values)

Sets content into the cache.

Arguments:

  • cache None or AbstractCache - The cache to set the content into. If None, the cache is ignored.
  • key str - The key to set the content into.
  • content MessageContentType - The message content to set into the cache.
  • *extra_values - Additional values to be passed to the cache.

min_tokens_reached

def min_tokens_reached(messages: list[dict],
                       min_tokens: Optional[int]) -> bool

Returns True if the total number of tokens in the messages is greater than or equal to the specified value.

Arguments:

  • messages List[Dict] - A list of messages to check.

count_text_tokens

def count_text_tokens(content: MessageContentType) -> int

Calculates the number of text tokens in the given message content.

Arguments:

  • content MessageContentType - The message content to calculate the number of text tokens for.

is_content_right_type

def is_content_right_type(content: Any) -> bool

A helper function to check if the passed in content is of the right type.

is_content_text_empty

def is_content_text_empty(content: MessageContentType) -> bool

Checks if the content of the message does not contain any text.

Arguments:

  • content MessageContentType - The message content to check.

should_transform_message

def should_transform_message(message: dict[str, Any],
                             filter_dict: Optional[dict[str, Any]],
                             exclude: bool) -> bool

Validates whether the transform should be applied according to the filter dictionary.

Arguments:

  • message Dict[str, Any] - The message to validate.
  • filter_dict None or Dict[str, Any] - The filter dictionary to validate against. If None, the transform is always applied.
  • exclude bool - Whether to exclude messages that match the filter dictionary.