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

Count Tokens for Bedrock #353

Closed
14gaurav16 opened this issue Feb 28, 2024 · 5 comments
Closed

Count Tokens for Bedrock #353

14gaurav16 opened this issue Feb 28, 2024 · 5 comments
Assignees

Comments

@14gaurav16
Copy link

I am getting following when I am trying to calculate tokens in bedrock.

AttributeError: 'AnthropicBedrock' object has no attribute 'count_tokens'

It seems like there is no implementation for it.

Thanks.

@rattrayalex
Copy link
Collaborator

That's right; we're now deprecating token-counting in the client because the tokenization algorithms in Claude 3 are different (see deprecation notes on the count_tokens() method). The new recommendation is to look at usage in the return value.

@Smuglix
Copy link

Smuglix commented Mar 6, 2024

@rattrayalex will there be a way to calculate how much tokens a given text takes without making a chat completion call?

@rattrayalex
Copy link
Collaborator

Not at this time, unfortunately. You can continue to use count_tokens() or other third-party libraries as a rough estimate for the time being. A better solution may be added in the future.

@opyate
Copy link

opyate commented Mar 7, 2024

or other third-party libraries as a rough estimate

Thanks for the suggestion.

Would you recommend tiktoken (and if so, cl100k_base?), sentencepiece, or the rough heuristic as per OpenAI?

I.e.

1 token ~= 4 chars in English
1 token ~= ¾ words
100 tokens ~= 75 words

@rattrayalex rattrayalex assigned x5a and unassigned RobertCraigie Mar 9, 2024
@rattrayalex
Copy link
Collaborator

@x5a might be better positioned to answer that.

This issue was closed.
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

No branches or pull requests

6 participants