Token Count
Token Count is a command-line utility that counts the number of tokens in a text string, file, or directory, similar to the Unix wc utility. It uses the OpenAI tiktoken library for tokenization and is compatible with GPT-3.5-turbo or any other OpenAI model token counts.
Installation
To install Token Count, run the following command in your terminal:
pip install token-count
Usage - Python Library
from token_count import TokenCount
tc = TokenCount(model_name="gpt-3.5-turbo")
text = "Your text here"
tokens = tc.num_tokens_from_string(text)
print(f"Tokens in the string: {tokens}")
file_path = "path/to/your/file.txt"
tokens = tc.num_tokens_from_file(file_path)
print(f"Tokens in the file: {tokens}")
dir_path = "path/to/your/directory"
tokens = tc.num_tokens_from_directory(dir_path)
print(f"Tokens in the directory: {tokens}")
Usage - Command Line
Token Count has three main options:
Count tokens in a text string:
token-count --text "Your text here"
Count tokens in a file:
token-count --file path/to/your/file.txt
Count tokens in a directory (recursively):
token-count --directory path/to/your/directory
You can provide any combination of these options. Token Count will print the token count for each input type.
Additionally, you can provide any OpenAI model(gpt-4) to get token count according to the model. By default it uses "gpt-3.5-turbo".
token-count --model_name "gpt-4"
License
This project is licensed under the MIT License.
Release files for token-count 0.2.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| token-count-0.2.1.tar.gz | 4.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| token_count-0.2.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 8.9 kB
Release files / token-count-0.2.1.tar.gz
| Download URL | token-count-0.2.1.tar.gz |
|---|---|
| Size | 4.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
f6462985a5ca2b925cc869932c3a2f64f57d91e78d9f5dc04dfdf717c206293a
|
|
BLAKE2b-256 checksum How to use checksums |
207ff779c0ef6b683c3b9c104b64e0b83f0435950a8d692eb7e0db1e443fbe98
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.4
|
Release files / token_count-0.2.1-py3-none-any.whl
| Download URL | token_count-0.2.1-py3-none-any.whl |
|---|---|
| Size | 4.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
b71fd116e8e5f15002570e00c1aa1c8a5e11e3b76599f70d81bfb98b2daf6bb4
|
|
BLAKE2b-256 checksum How to use checksums |
9553010fcaf4021799d74452eddeec9ad6bb244e41b98485d036cf6253172d2f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.2 CPython/3.10.4
|