Skip to content

Conversation

@danielsogl
Copy link
Contributor

Migrated from gpt-tokenizer to tiktoken for better maintenance, official OpenAI support, and native GPT-5 encoding support.

Why the change?

  • Better maintenance: tiktoken is actively maintained by OpenAI, ensuring compatibility with latest models
  • GPT-5 support: tiktoken natively supports GPT-5 encoding, eliminating the need for fallback encodings (gpt-tokenizer had an Add new GPT 5 and GPT OSS models niieani/gpt-tokenizer#73 for GPT-5
    support)
  • Official library: As OpenAI's official tokenization library, tiktoken provides the most accurate token counting for API rate limiting

@crisbeto crisbeto requested a review from devversion September 21, 2025 06:54
Copy link
Member

@devversion devversion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR! One minor suggestion

return tokens.length;
} finally {
encoding.free();
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: we may want to extract this into a helper? and pass the model name + prompt? (seems re-used 3 times)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

@danielsogl danielsogl force-pushed the refactor/replace_gpt_tokenizer branch from a7996a4 to c4e130f Compare September 21, 2025 17:20
Copy link
Member

@devversion devversion left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@devversion devversion merged commit 9298147 into angular:main Sep 21, 2025
3 checks passed
@danielsogl danielsogl deleted the refactor/replace_gpt_tokenizer branch September 21, 2025 18:07
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.

2 participants