Exact token count via tiktoken, or char/4 heuristic if offline.
(self, text: str)
| 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) |
no outgoing calls