-
Notifications
You must be signed in to change notification settings - Fork 10
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
Bump anthropic from 0.37.1 to 0.39.0 #355
Conversation
client = anthropic.Anthropic() | ||
prompt_tokens = client.count_tokens(prompt) | ||
completion_tokens = client.count_tokens(completion) | ||
# count_tokens is removed from the API in 0.39.0, consider to deprecate anthropic completion |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
anthropic 0.39.0 removed "legacy client.count_tokens() method". We only call create_tokens_usage for message using legacy completion model, like claude-2.1. Tried to use a new API beta.messages.count_tokens
but got 400 error from the API.
https://github.com/anthropics/anthropic-sdk-python/releases
Consider the rare usage of legacy models, I set the token to 0 and we could discuss if we want to deprecate the support in future.
@@ -24,10 +24,11 @@ def test_chat_openai_messages(session, openai_model): | |||
_LogAssertion(completion_id=session.last_completion_id(), message_content=content).assert_chat_response() | |||
|
|||
|
|||
@pytest.mark.skip(reason="Anthropic API removed count_tokens in 0.39.0, langchain_community not updated") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
error in langchain-community:
cls = <class 'langchain_community.chat_models.anthropic.ChatAnthropic'>
values = {'AI_PROMPT': '\n\nAssistant:', 'HUMAN_PROMPT': '\n\nHuman:', 'anthropic_api_key': SecretStr('**********'), 'anthropic_api_url': 'https://api.anthropic.com', ...}
@pre_init
def validate_environment(cls, values: Dict) -> Dict:
"""Validate that api key and python package exists in environment."""
values["anthropic_api_key"] = convert_to_secret_str(
get_from_dict_or_env(values, "anthropic_api_key", "ANTHROPIC_API_KEY")
)
# Get custom api url from environment.
values["anthropic_api_url"] = get_from_dict_or_env(
values,
"anthropic_api_url",
"ANTHROPIC_API_URL",
default="https://api.anthropic.com",
)
try:
import anthropic
check_package_version("anthropic", gte_version="0.3")
values["client"] = anthropic.Anthropic(
base_url=values["anthropic_api_url"],
api_key=values["anthropic_api_key"].get_secret_value(),
timeout=values["default_request_timeout"],
max_retries=values["max_retries"],
)
values["async_client"] = anthropic.AsyncAnthropic(
base_url=values["anthropic_api_url"],
api_key=values["anthropic_api_key"].get_secret_value(),
timeout=values["default_request_timeout"],
max_retries=values["max_retries"],
)
values["HUMAN_PROMPT"] = anthropic.HUMAN_PROMPT
values["AI_PROMPT"] = anthropic.AI_PROMPT
> values["count_tokens"] = values["client"].count_tokens
E AttributeError: 'Anthropic' object has no attribute 'count_tokens'
venv/lib/python3.12/site-packages/langchain_community/llms/anthropic.py:108: AttributeError
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
discussed offline that the test will be enabled with a follow up to upgrade the langchain anthropic 0.3.
Bumps [anthropic](https://github.com/anthropics/anthropic-sdk-python) from 0.37.1 to 0.39.0. - [Release notes](https://github.com/anthropics/anthropic-sdk-python/releases) - [Changelog](https://github.com/anthropics/anthropic-sdk-python/blob/main/CHANGELOG.md) - [Commits](anthropics/anthropic-sdk-python@v0.37.1...v0.39.0) --- updated-dependencies: - dependency-name: anthropic dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] <[email protected]>
39ba0c3
to
0f2a949
Compare
Bumps anthropic from 0.37.1 to 0.39.0.
updated-dependencies: