Skip to content

A lightweight and minimalized TS port for using OpenAI's Python pack tiktoken

License

Notifications You must be signed in to change notification settings

KevinKWZheng/Tokenizer-API

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

LLM-Tokenizer

A simple and minimalized TS port for using OpenAI's Python pack tiktoken. It is essentially a script runner for OpenAI's tiktoken package with TS. Hence, running this package requires you to have a Python runtime environment and tiktoken package installed.

You will need a Python runtime envrionment and tiktoken package installed in order to make this package work.

To install this package, run npm i llm-tokenizer.

Usage

import Tokenizer from "llm-tokenizer";

const tokenizer=new Tokenizer();

const result1=await tokenizer.countToken(`tiktoken is great!`);
// Output: 6

const result2=await tokenizer.encode(`tiktoken is great!`);
// Output: [83, 1609, 5963, 374, 2294, 0]

const result3=await tokenizer.decode([83, 1609, 5963, 374, 2294, 0]);
// Output: `tiktoken is great!`

Additionally, you could specify which encoding to defaultly use or for temporary usage by setting the encoding option in the constructor or setEncoding method.

About

A lightweight and minimalized TS port for using OpenAI's Python pack tiktoken

Resources

License

Stars

Watchers

Forks

Packages

No packages published