Skip to content

Conversation

@dqbd
Copy link
Owner

@dqbd dqbd commented Aug 9, 2025

Reopens #136

noseworthy and others added 2 commits August 9, 2025 02:49
The `tiktoken-js` library includes a very helpful function,
`getEncodingNameForModel()`. This function is buried in the
implementation of `encoding_for_model()` in the rust based
`tiktoken` package.

This function is very useful when implementing an encoding cache based
on the model used. In this case, having a mapping from model ->
encoding and then caching based on the encoding name conserves
resources since so many models re-use the same encoding.

I've exposed a new `get_encoding_name_for_model()` function
that behaves similarly to the one in the `tiktoken-js` package, and used
it inside of `encoding_for_model()`.

Finally, I've also added a test to ensure that this function can be
called properly from typescript code, and that it properly throws
exceptions in the case of invalid model names.

Fixes: #123
@dqbd dqbd merged commit 7304466 into main Aug 9, 2025
1 check passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants