anthropic-sdk-python icon indicating copy to clipboard operation
anthropic-sdk-python copied to clipboard

pydantic 1.10.13 error on anthropic 0.26.1

Open dinnouti opened this issue 1 year ago • 4 comments

Just a heads up.

I am running the Anthropic 0.26.1 with pydantic version 1.10.13 and is throwing an error:

"ImportError: cannot import name 'version_short' from 'pydantic.version' (/opt/conda/lib/python3.10/site-packages/pydantic/version.cpython-310-x86_64-linux-gnu.so)" .

The pyproject.toml asks for "pydantic>=1.9.0, <3"

dinnouti avatar May 23 '24 15:05 dinnouti

Thanks for reporting, we'll take a look.

rattrayalex avatar May 26 '24 01:05 rattrayalex

Can you share a full stack trace? I can't reproduce this issue.

RobertCraigie avatar May 26 '24 18:05 RobertCraigie

I am running in a fresh SageMaker instance. Below the code and error stack trace.

!pip install -U anthropic[bedrock]
from anthropic import AnthropicBedrock

client = AnthropicBedrock()

message = client.messages.create(
    max_tokens=1024,
    messages=[
        {
            "role": "user",
            "content": "Hello!",
        }
    ],
    model="anthropic.claude-3-sonnet-20240229-v1:0",
)
print(message)

Error:

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
Cell In[2], line 1
----> 1 from anthropic import AnthropicBedrock
      3 client = AnthropicBedrock()
      5 message = client.messages.create(
      6     max_tokens=1024,
      7     messages=[
   (...)
     13     model="anthropic.claude-3-sonnet-20240229-v1:0",
     14 )

File [/opt/conda/lib/python3.10/site-packages/anthropic/__init__.py:3](https://obpbqemsvcpvmub.studio.us-east-1.sagemaker.aws/opt/conda/lib/python3.10/site-packages/anthropic/__init__.py#line=2)
      1 # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
----> 3 from . import types
      4 from ._types import NOT_GIVEN, NoneType, NotGiven, Transport, ProxiesTypes
      5 from ._utils import file_from_path

File [/opt/conda/lib/python3.10/site-packages/anthropic/types/__init__.py:5](https://obpbqemsvcpvmub.studio.us-east-1.sagemaker.aws/opt/conda/lib/python3.10/site-packages/anthropic/types/__init__.py#line=4)
      1 # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
      3 from __future__ import annotations
----> 5 from .usage import Usage as Usage
      6 from .message import Message as Message
      7 from .completion import Completion as Completion

File [/opt/conda/lib/python3.10/site-packages/anthropic/types/usage.py:5](https://obpbqemsvcpvmub.studio.us-east-1.sagemaker.aws/opt/conda/lib/python3.10/site-packages/anthropic/types/usage.py#line=4)
      1 # File generated from our OpenAPI spec by Stainless. See CONTRIBUTING.md for details.
----> 5 from .._models import BaseModel
      7 __all__ = ["Usage"]
     10 class Usage(BaseModel):

File [/opt/conda/lib/python3.10/site-packages/anthropic/_models.py:21](https://obpbqemsvcpvmub.studio.us-east-1.sagemaker.aws/opt/conda/lib/python3.10/site-packages/anthropic/_models.py#line=20)
      7 from typing_extensions import (
      8     Unpack,
      9     Literal,
   (...)
     17     runtime_checkable,
     18 )
     20 import pydantic
---> 21 import pydantic.generics
     22 from pydantic.fields import FieldInfo
     24 from ._types import (
     25     Body,
     26     IncEx,
   (...)
     33     HttpxRequestFiles,
     34 )

File [/opt/conda/lib/python3.10/site-packages/pydantic/generics.py:2](https://obpbqemsvcpvmub.studio.us-east-1.sagemaker.aws/opt/conda/lib/python3.10/site-packages/pydantic/generics.py#line=1)
      1 """The `generics` module is a backport module from V1."""
----> 2 from ._migration import getattr_migration
      4 __getattr__ = getattr_migration(__name__)

File [/opt/conda/lib/python3.10/site-packages/pydantic/_migration.py:4](https://obpbqemsvcpvmub.studio.us-east-1.sagemaker.aws/opt/conda/lib/python3.10/site-packages/pydantic/_migration.py#line=3)
      1 import sys
      2 from typing import Any, Callable, Dict
----> 4 from .version import version_short
      6 MOVED_IN_V2 = {
      7     'pydantic.utils:version_info': 'pydantic.version:version_info',
      8     'pydantic.error_wrappers:ValidationError': 'pydantic:ValidationError',
   (...)
     13     'pydantic.generics:GenericModel': 'pydantic.BaseModel',
     14 }
     16 DEPRECATED_MOVED_IN_V2 = {
     17     'pydantic.tools:schema_of': 'pydantic.deprecated.tools:schema_of',
     18     'pydantic.tools:parse_obj_as': 'pydantic.deprecated.tools:parse_obj_as',
   (...)
     28     'pydantic.config:Extra': 'pydantic.deprecated.config:Extra',
     29 }

ImportError: cannot import name 'version_short' from 'pydantic.version' ([/opt/conda/lib/python3.10/site-packages/pydantic/version.cpython-310-x86_64-linux-gnu.so](https://obpbqemsvcpvmub.studio.us-east-1.sagemaker.aws/opt/conda/lib/python3.10/site-packages/pydantic/version.cpython-310-x86_64-linux-gnu.so))

dinnouti avatar May 28 '24 21:05 dinnouti

I think something is messed up with your environment, that error is coming from within pydantic's source code so I don't think this is related to something we're doing in the anthropic library.

RobertCraigie avatar May 29 '24 10:05 RobertCraigie