-
Notifications
You must be signed in to change notification settings - Fork 118
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
AttributeError: 'Anthropic' object has no attribute 'count_tokens' #314
Comments
is there a version of the anthropic py lib that is compatible with langchain without this issue? |
The I tried downgrading to v0.38.0, but anthropic threw the same error noted in #297, which requires the package to be upgraded for resolution. So we probably do need to update the code to use the new |
Took a look into fixing this, but there isn't a clear-cut resolution path at the moment. The built-in token counting functionality in Anthropic Python SDK has been removed entirely in favor of an server-side implementation in the Messages API. This means that users are now required to provide a separate Anthropic API key. And while the A possible future solution may lie with the Anthropic SDK's Bedrock client, which is able to interface with the base Messages API using only AWS credentials. However, Bedrock does not yet support the |
Any solution for this? |
We have a fix pending in #341. As a temporary workaround, please run:
|
Getting this error when using anthropic models from bedrock.py module of langchain.
The error comes from this module.
Looking at the anthropic code, the api for count_tokens has been changed and it needs to be updated in the utils.py for bedrock.
import anthropic
client = anthropic.Anthropic()
response = client.messages.count_tokens(
model="claude-3-5-sonnet-20241022",
system="You are a scientist",
messages=[{
"role": "user",
"content": "Hello, Claude"
}],
)
print(response.json())
The text was updated successfully, but these errors were encountered: