Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

refactor(client)!: remove legacy client.count_tokens() method #726

Merged
merged 1 commit into from
Nov 4, 2024

Conversation

RobertCraigie
Copy link
Collaborator

@RobertCraigie RobertCraigie commented Nov 4, 2024

This functionality has been replaced by the client.beta.messages.count_tokens() API which supports newer models and all content functionality, such as images and PDFs.

Additionally, the tokenizers dependency is blocking Python 3.13 support.

@RobertCraigie RobertCraigie marked this pull request as ready for review November 4, 2024 10:52
@RobertCraigie RobertCraigie requested a review from a team as a code owner November 4, 2024 10:52
@RobertCraigie RobertCraigie merged commit 14e4244 into next Nov 4, 2024
5 checks passed
@RobertCraigie RobertCraigie deleted the remove-legacy-count-tokens branch November 4, 2024 15:14
@stainless-app stainless-app bot mentioned this pull request Nov 4, 2024
ccurme added a commit to langchain-ai/langchain that referenced this pull request Nov 12, 2024
Last week Anthropic released version 0.39.0 of its python sdk, which
enabled support for Python 3.13. This release deleted a legacy
`client.count_tokens` method, which we currently access during init of
the `Anthropic` LLM. Anthropic has replaced this functionality with the
[client.beta.messages.count_tokens()
API](anthropics/anthropic-sdk-python#726).

To enable support for `anthropic >= 0.39.0` and Python 3.13, here we
drop support for the legacy token counting method, and add support for
the new method via `ChatAnthropic.get_num_tokens_from_messages`.

To fully support the token counting API, we update the signature of
`get_num_tokens_from_message` to accept tools everywhere.

---------

Co-authored-by: Bagatur <[email protected]>
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