services/tokens/tokens
Token estimation for context window awareness. Uses character-based heuristics: ~4 chars per token for English/Latin, ~1 char per token for CJK and other dense scripts. Directionally correct for overflow warnings — not a tiktoken port.
Values
pub fn context_usage_percent(
estimated_tokens: Int,
context_window: Int,
) -> Int
pub fn context_window_warning(
tokens_used: Int,
context_window: Int,
warn_percent: Int,
) -> String
pub fn estimate_messages(
messages: List(completions.Message),
) -> Int
pub fn estimate_request(
system_prompt: String,
messages: List(completions.Message),
tool_definitions: List(completions.ToolDefinition),
) -> Int
pub fn estimate_string(text: String) -> Int
pub fn service() -> shapes.Service