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

Bump anthropic from 0.37.1 to 0.39.0 #355

Merged
merged 3 commits into from
Nov 15, 2024
Merged

Conversation

wenzhe-log10
Copy link
Collaborator

Bumps anthropic from 0.37.1 to 0.39.0.


updated-dependencies:

  • dependency-name: anthropic dependency-type: direct:production update-type: version-update:semver-minor ...

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
Copy link
Collaborator Author

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")
Copy link
Collaborator Author

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

Copy link
Collaborator

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.

@wenzhe-log10 wenzhe-log10 requested a review from kxtran November 14, 2024 23:58
@wenzhe-log10 wenzhe-log10 merged commit f4a2f1c into main Nov 15, 2024
4 checks passed
@wenzhe-log10 wenzhe-log10 deleted the pip/anthropic-0.39.0 branch November 15, 2024 18:09
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