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 Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distributions

gptwc-1.2.0-py3.10.egg (4.1 kB view details)

Uploaded Source

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

Uploaded Python 2 Python 3

File details

Details for the file gptwc-1.2.0-py3.10.egg.

File metadata

  • Download URL: gptwc-1.2.0-py3.10.egg
  • Upload date:
  • Size: 4.1 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.0-py3.10.egg
Algorithm Hash digest
SHA256 935b4a69b12eefc70daee7d7dad545e52f0f321ba2d40b4831af5d3f9096e1e0
MD5 a5271d5e0dc37e4f92b7cd6c6eb0a210
BLAKE2b-256 c9144bd06d65bbfb4dcd7f24190630217b6674fd44bfdb1ebc03294dccd8d69c

See more details on using hashes here.

File details

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

File metadata

  • Download URL: gptwc-1.2.0-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.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 20452d4ebfb2b76b771599a7764869c946fd38d49412a8e85e8514821120717d
MD5 3513944655b65dfe809064b27eec56c5
BLAKE2b-256 3c7572f10e1fb27014dd8324dbdbe581294a535134b2d0eba8ad73e95d37c763

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