MCPcopy Create free account
hub / github.com/Emmimal/control-layer / count

Method count

control_layer.py:317–321  ·  view source on GitHub ↗

Exact token count via tiktoken, or char/4 heuristic if offline.

(self, text: str)

Source from the content-addressed store, hash-verified

315 self._slots: Dict[str, int] = {}
316
317 def count(self, text: str) -> int:
318 """Exact token count via tiktoken, or char/4 heuristic if offline."""
319 if self._enc is not None:
320 return len(self._enc.encode(text))
321 return max(1, len(text) // 4)
322
323 def reserve(self, name: str, text: str) -> bool:
324 tokens = self.count(text)

Callers 2

reserveMethod · 0.95
test_accurate_countMethod · 0.95

Calls

no outgoing calls

Tested by 1

test_accurate_countMethod · 0.76