Module: Myrr::Tokenizer
- Defined in:
- lib/myrr/tokenizer.rb
Overview
Token counting for agent responses.
Uses OpenAI's cl100k_base encoding via tiktoken_ruby to count tokens in rendered markdown responses.
Constant Summary collapse
- ENCODING_MODEL =
Uses cl100k_base encoding
"gpt-4"
Class Method Summary collapse
-
.count(text) ⇒ Integer
Count the number of tokens in the given text.
Class Method Details
.count(text) ⇒ Integer
Count the number of tokens in the given text.
Uses OpenAI's cl100k_base encoding via tiktoken_ruby.
21 22 23 24 25 |
# File 'lib/myrr/tokenizer.rb', line 21 def count(text) return 0 if text.nil? || text.strip.empty? enc = Tiktoken.encoding_for_model(ENCODING_MODEL) enc.encode(text).length end |