
Security News
npm Adopts OIDC for Trusted Publishing in CI/CD Workflows
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
gpt-token-utils
Advanced tools
Isomorphic utilities for GPT-3 tokenization and prompt building.
Supply Chain Security
Vulnerability
Quality
Maintenance
License
AI-detected possible typosquat
Supply chain riskThere is a package with a similar name that is downloaded much more often.
Did you mean |
---|
gpt-tokenizer |
Unpopular package
QualityThis package is not very popular.
Found 1 instance in 1 package
GPT Token Utilities is a small library for encoding and decoding text to and from the tokenized format used by OpenAI's GPT models.
Our token encoder/decoder is optimized for a balance of speed and ease of use. No external dependencies are required.
Everything is written in TypeScript and includes type definitions with full documentation. This library is isomorphic and can be used in both Node and the browser!
GPT Token Utils balances a small footprint with a full-featured API. It's also tree-shakeable, so you can import only the functions you need.
yarn add gpt-token-utils
# or
npm install --save gpt-token-utils
The encode
and decode
exports are the main functions you'll use to work with GPT tokens.
import { encode, decode } from 'gpt-token-utils'
// Encode a string to a list of tokens...
const tokens = encode('Humans are strange creatures, and ever so curious too!')
// You've got a list of tokens!
console.log(tokens) // [32661, 504, 389, 6283, 8109, 11, 290, 1683, 523, 11040, 1165, 0]
// How many tokens are there?
console.log(tokens.length) // 6
// Can we decode it back to text?
console.log(decode(tokens)) // "Humans are strange creatures...."
If you're working with Codex-based models optimized for strings of code, you can also use the encodeCodex
and decodeCodex
exports.
import { encodeCodex, decodeCodex } from 'gpt-token-utils'
const codeExample = [
'function deeplyNested () {',
' return {',
' the: {',
' quick: {',
' brown: {',
' fox: {',
' jumps: {',
' over: {',
' the: {',
' lazy: {',
' dog: {',
' }',
' }',
' }',
' }',
' }',
' }',
' }',
' }',
' }',
' }',
'}',
].join('\n')
const tokens = encodeCodex(codeExample)
By default, GPT Token Utils includes a sizable vocabulary and encoder. Alternatively, you can pass in your own to customize the encoding/decoding process.
import {BytePairEncoder} from 'gpt-token-utils/BytePairEncoder'
const tokenEncoder = new BytePairEncoder({...})
import {BytePairDecoder} from 'gpt-token-utils/BytePairDecoder'
const tokenDecoder = new TokenDecoder({...})
GPT Token Utils is licensed under the MIT License. If you've got something cool to share that's built with this library, let us know at @SisterSoftware! We would love to see it!
FAQs
Isomorphic utilities for GPT-3 tokenization and prompt building.
The npm package gpt-token-utils receives a total of 521 weekly downloads. As such, gpt-token-utils popularity was classified as not popular.
We found that gpt-token-utils demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
npm now supports Trusted Publishing with OIDC, enabling secure package publishing directly from CI/CD workflows without relying on long-lived tokens.
Research
/Security News
A RubyGems malware campaign used 60 malicious packages posing as automation tools to steal credentials from social media and marketing tool users.
Security News
The CNA Scorecard ranks CVE issuers by data completeness, revealing major gaps in patch info and software identifiers across thousands of vulnerabilities.