Skip to main content

A package to count tokens in input text using OpenAI's tiktoken library.

Project description

gptwc: wc for GPT tokens

A simple utility for counting tokens. It's like wc which counts words, except it uses tiktoken to count tokens.

It's useful for checking the number of tokens in a string, in order to remain under the token limit (eg. 4097 for the GPT3 API)

usage: gptwc [-h] [--files0-from F] [--model MODEL] [-c] [--version] [FILE ...]

Count tokens in text files using OpenAI's tiktoken library.

positional arguments:
  FILE             Text files to count tokens in

options:
  -h, --help       show this help message and exit
  --files0-from F  Read input from the files specified by NUL-terminated names in file F
  --model MODEL    Model name to use for tokenization (default: text-davinci-003)
  -c, --clipboard  Read input from the system clipboard
  --version        show program's version number and exit

Example Usage:

$ cat README.md  | wc -w
54

$ cat README.md  | gptwc
180


$ curl -s 'https://gist.githubusercontent.com/phillipj/4944029/raw/75ba2243dd5ec2875f629bf5d79f6c1e4b5a8b46/alice_in_wonderland.txt' | wc -w
26470

curl -s 'https://gist.githubusercontent.com/phillipj/4944029/raw/75ba2243dd5ec2875f629bf5d79f6c1e4b5a8b46/alice_in_wonderland.txt' | gptwc
40085


$ cat README.md | gptwc --model text-davinci-003
517
$ cat README.md | gptwc --model gpt-3.5-turbo
434


$ cat README.md | pbcopy
$ gptwc -c
517

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

gptwc-1.2.1.tar.gz (3.3 kB view details)

Uploaded Source

Built Distributions

gptwc-1.2.1-py3-none-any.whl (3.8 kB view details)

Uploaded Python 3

gptwc-1.2.1-py2.py3-none-any.whl (3.8 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file gptwc-1.2.1.tar.gz.

File metadata

  • Download URL: gptwc-1.2.1.tar.gz
  • Upload date:
  • Size: 3.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for gptwc-1.2.1.tar.gz
Algorithm Hash digest
SHA256 b041cfec3dcdf9d4aabb65742f15769c3edff70a384ec4d64e60b440b5306786
MD5 df1b5a75e96d4ff19a2a7beee63a9b3d
BLAKE2b-256 7cd8aa3ca1f5f77b9692d47ffa93366375a3515cbacff4c5ff65632265ff16c6

See more details on using hashes here.

File details

Details for the file gptwc-1.2.1-py3-none-any.whl.

File metadata

  • Download URL: gptwc-1.2.1-py3-none-any.whl
  • Upload date:
  • Size: 3.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for gptwc-1.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4448ba591f23ac5a154147e5302f4103a3cb4ab6352b98727f7e4c53d1c195a3
MD5 c48094c955d759ac9d498f2d96d85087
BLAKE2b-256 d5cbae3ea721025a63735c50ca89f62dbdc8c8e9b5de95b0da735a1c64cea88e

See more details on using hashes here.

File details

Details for the file gptwc-1.2.1-py2.py3-none-any.whl.

File metadata

  • Download URL: gptwc-1.2.1-py2.py3-none-any.whl
  • Upload date:
  • Size: 3.8 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.6

File hashes

Hashes for gptwc-1.2.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 0b8e4d4350aed617292cdac9063b077965dbf78dafde2f3f9b7631e532d768b8
MD5 2032f29307a648ef5030818ac65d6d60
BLAKE2b-256 be3f78ac1f27ca540ad6ba778b22b1b13243181664de3abe380481b5faa3f1de

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