Skip to main content

A simple token counter for Llama 3.2 models.

Project description

Llama 3.2 Token Counter

Python Version License

A simple and efficient token counter for Llama 3.2 models.

Description

The Llama 3.2 Token Counter is a Python package that provides an easy way to count tokens generated by Llama 3.2 models. This tool is essential for developers and researchers working with large language models, helping them manage token limits and optimize their use of the Llama 3.2 architecture.

Features

  • Accurate token counting for Llama 3.2 models
  • Easy-to-use Python API
  • Supports both string and list of strings inputs
  • Asynchronous token counting support
  • Lightweight and efficient

Installation

You can install the Llama 3.2 Token Counter using pip:

pip install llama3.2-token-counter

Usage

Here's a quick example of how to use the Llama 3.2 Token Counter:

from llama_token_counter import LlamaTokenCounter
import asyncio

# Initialize the token counter
counter = LlamaTokenCounter()

# Synchronous token counting
text = "Hello, world! This is a sample text for token counting."
token_count = counter.count_tokens(text)
print(f"The text contains {token_count} tokens.")

# Asynchronous token counting
async def count_async():
    text = "This is an async token counting example."
    token_count = await counter.count_tokens(text, async_mode=True)
    print(f"The async text contains {token_count} tokens.")

asyncio.run(count_async())

# Count tokens in a list of strings
texts = ["Hello, world!", "This is another sample.", "Multiple strings can be processed."]
token_count = counter.count_tokens(texts)
print(f"The list of texts contains {token_count} tokens in total.")

# Get the maximum token limit
max_tokens = counter.get_max_tokens()
print(f"The maximum token limit is {max_tokens}.")

# Batch processing for large lists
large_list = ["Text " + str(i) for i in range(10000)]
token_count = counter.count_tokens(large_list, batch_size=500)
print(f"The large list contains {token_count} tokens in total.")

Contributing

We welcome contributions to the Llama 3.2 Token Counter! If you'd like to contribute, please look at CONTRIBUTING.md for more information.

License

This project is licensed under the MIT License - see the LICENSE file for details.

Contact

Anthony - @anthoeknee

Project Link: https://github.com/anthoeknee/llama3.2-token-counter

Running Tests

To run the tests, follow these steps:

  1. Clone the repository:

    git clone https://github.com/yourusername/llama3.2-token-counter.git
    cd llama3.2-token-counter
    
  2. Install the development dependencies:

    pip install -r requirements.txt
    
  3. Run the tests:

    python -m unittest discover tests
    

Make sure you have the necessary tokenizer files in the src/tokenizer directory before running the tests.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

llama3_2_token_counter-0.2.0.tar.gz (5.6 MB view details)

Uploaded Source

Built Distribution

llama3.2_token_counter-0.2.0-py3-none-any.whl (3.3 MB view details)

Uploaded Python 3

File details

Details for the file llama3_2_token_counter-0.2.0.tar.gz.

File metadata

File hashes

Hashes for llama3_2_token_counter-0.2.0.tar.gz
Algorithm Hash digest
SHA256 b19fb986601e65947eb996411fc8a57d0959809a8360aac5493554518be45cb0
MD5 ce9a195b411ac005b08dc472b9d7abaf
BLAKE2b-256 92fce608fbccb2d6f6accb8c5cedaa3f7d65dc988fbda6a9e6eef6dfeb3f12e4

See more details on using hashes here.

File details

Details for the file llama3.2_token_counter-0.2.0-py3-none-any.whl.

File metadata

File hashes

Hashes for llama3.2_token_counter-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3ed4e992f9f71f642f4b29b4197f69b903fd342c7a35d85302abe17b6b579ae8
MD5 5ad94ab8dd1bb80f955952e2f6dab975
BLAKE2b-256 58168c84f22aa5cba27ee6b61224c82a89d2c23f96bebe7e2e2a9677dad204a6

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page