MCPcopy Index your code
hub / github.com/Codeplain-ai/codeplain / _count_tokens

Method _count_tokens

plain2code_console.py:114–121  ·  view source on GitHub ↗

Count tokens using tiktoken if available, otherwise estimate from character count.

(self, text)

Source from the content-addressed store, hash-verified

112 return tree
113
114 def _count_tokens(self, text):
115 """Count tokens using tiktoken if available, otherwise estimate from character count."""
116 if self.llm_encoding is not None:
117 try:
118 return len(self.llm_encoding.encode(text))
119 except Exception:
120 pass
121 return len(text) // CHARACTERS_TO_TOKENS_RULE_OF_THUMB_RATIO
122
123 def print_resources(self, resources_list, linked_resources):
124 if len(resources_list) == 0:

Callers 2

print_resourcesMethod · 0.95

Calls 1

encodeMethod · 0.80

Tested by

no test coverage detected