MCPcopy
hub / github.com/llmware-ai/llmware / token_counter

Method token_counter

llmware/models.py:5797–5804  ·  view source on GitHub ↗

Gets GPT2 tokenizer for fast approximate token counting.

(self, text_sample)

Source from the content-addressed store, hash-verified

5795 return self.api_key
5796
5797 def token_counter(self, text_sample):
5798
5799 """ Gets GPT2 tokenizer for fast approximate token counting. """
5800
5801 tokenizer = Utilities().get_default_tokenizer()
5802 toks = tokenizer.encode(text_sample).ids
5803
5804 return len(toks)
5805
5806 def prompt_engineer_chat(self, query, context, inference_dict=None):
5807

Callers

nothing calls this directly

Calls 3

UtilitiesClass · 0.90
get_default_tokenizerMethod · 0.80
encodeMethod · 0.80

Tested by

no test coverage detected