Count tokens using tiktoken if available, otherwise estimate from character count.
(self, text)
| 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: |
no test coverage detected