Skip to main content

TokenEstimator

Protocol for records that can estimate their own token count. Implement this on your record type and the TokenBatcher will call it automatically when no explicit estimated_tokens is passed to TokenBatcher.submit.

Methods


estimate_tokens()

@classmethod
def estimate_tokens() - > int

Estimates the token count for the record. Implement this method on your record type so that TokenBatcher can automatically call it when no explicit estimated_tokens is passed to TokenBatcher.submit.

Returns

TypeDescription
intThe estimated number of tokens for the record.