Spaces:
Sleeping
Sleeping
Download utils.py from CintraAI/code-chunker: direct link, hf CLI and curl.
- Browser
- Download file 358 Bytes
-
https://huggingface.co/spaces/CintraAI/code-chunker/resolve/5cf511f1ffee17b80b65c1fa2c3003c28d375e45/utils.py
- Command line
-
hf download hf://spaces/CintraAI/code-chunker@5cf511f1ffee17b80b65c1fa2c3003c28d375e45/utils.py
-
curl -L -o utils.py https://huggingface.co/spaces/CintraAI/code-chunker/resolve/5cf511f1ffee17b80b65c1fa2c3003c28d375e45/utils.py
358 Bytes
| import tiktoken | |
| import json | |
| def count_tokens(string: str, encoding_name: str) -> int: | |
| """Returns the number of tokens in a text string.""" | |
| encoding = tiktoken.encoding_for_model(encoding_name) | |
| num_tokens = len(encoding.encode(string)) | |
| return num_tokens | |
| def load_json(json_file): | |
| with open(json_file) as f: | |
| return json.load(f) | |