usageRatio method
- Iterable<
AiChatMessage> messages
How much of the budget the conversation is using, in 0..1.
Useful for a context meter in a chat UI: users are far less frustrated by trimming when they can see it coming.
Implementation
double usageRatio(Iterable<AiChatMessage> messages) {
final available = availableTokens;
if (available == 0) return 1;
return (estimateConversationTokens(messages) / available).clamp(0.0, 1.0);
}