Comments (7)
Hello, I've been working on JS bindings for tiktoken, found here: https://github.com/dqbd/tiktoken. Core methods are implemented, some methods are missing for now.
You can install it as such:
npm install tiktoken
If it is desired, I could try to wrangle the changes and create an upstream PR.
Note: Couldn't secure the tiktoken
NPM package name, as it is currently owned by @gmpetrov
EDIT: Pure JS port is also available as
npm install js-tiktoken
from tiktoken.
Thanks for the suggestion! I'm not currently planning on implementing this, but it is likely that at some point we will.
If other people encountering this also have this feature request, please thumbs up the original post.
Note that the third party gpt-3-encoder library will not work exactly right for any of the Codex or GPT-3.5 series models, including code-cushman-001, code-davinci-002, text-davinci-002, text-davinci-003, etc. It will also not work at all for e.g. the recent embeddings models, like text-embedding-ada-002
from tiktoken.
Hey, I also made a simple alternative for tiktoken on Node.js! A lot of features are missing too, but I plan to make a 1:1 library with the python version.
Link: https://github.com/ceifa/tiktoken-node
Because it relies on node addon instead of webassembly, it is 5-6x faster than @dqbd approach.
from tiktoken.
If you just want to get tokens and USD consumed by messages,you can try it : )
npm install gpt-tokens
import { GPTTokens } from 'gpt-tokens'
const gptTokens = new GPTTokens({
model : 'gpt-3.5-turbo',
messages: [
{ 'role': 'system', 'content': 'You are a helpful assistant' },
{ 'role': 'user', 'content': '' },
],
})
// 18
console.log('Tokens: ', gptTokens.usedTokens)
// 0.000036
console.log('USD: ', gptTokens.usedUSD)
from tiktoken.
Just published a new version of tiktoken that includes a mapping from model to tokeniser. Anything not using r50k is liable to be incorrect (sometimes subtly, sometimes majorly, sometimes majorly but you won't notice) with the third party gpt-3-encoder library: https://github.com/openai/tiktoken/blob/main/tiktoken/model.py#L7
from tiktoken.
Could someone help me understand the pros and cons of using Xenova/text-embedding-ada-002 with Transformers.js vs one of the other project listed above?
from tiktoken.
there is another one https://github.com/niieani/gpt-tokenizer
that seems like a full Node port, without a wrapper around Python tiktoker.
from tiktoken.
Related Issues (20)
- Optimize _byte_pair_merge function in BPE implementation
- Tiktoken not installing on a macbook pro with m2 chip HOT 2
- Exception has occurred: ConnectionError HTTPSConnectionPool(host='openaipublic.blob.core.windows.net', port=443): Max retries exceeded with url: /encodings/cl100k_base.tiktoken (Caused by NewConnectionError('<urllib3.connection.HTTPSConnection object at 0x000001F4D42B0EE0>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed'))
- Understanding the intended behaviour of `_encode_bytes`
- Custom tokenizer fails to encode despite characters being in mergeable_ranks HOT 2
- Use a custom exception ValueError subclass for the special tokens warning
- Error
- Combining marks and indic vowel marks within words are being split breaking all indic languages and most languages except English and CJKs HOT 4
- I need tiktoken win32 python3.8 version, can anyone provide it? HOT 1
- A character is splited into two tokens HOT 1
- gpt-4o tokenizer HOT 1
- Or
- GPT4o出现低级bug:发现最新token中的垃圾语料及实测GPT4o胡言乱语出现幻觉 HOT 3
- `o200k_base` pretokenizer - regex error? HOT 2
- Tiktoken educational BPE trainer takes long time to train with vocab size 30k HOT 2
- tiktoken 0.7.0 isn't compatible with python 3.11.* HOT 3
- Unknown encoding gpt2 HOT 1
- I want to modify the code in self._core_bpe.decode_bytes(tokens).decode("utf-8", errors=errors) HOT 1
- TikToken Tokenizer from scratch ?
- Support for GPT 4o HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tiktoken.