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

anthropic[vertex] has missing requests dependency #738

Open
shobsi opened this issue Nov 6, 2024 · 3 comments
Open

anthropic[vertex] has missing requests dependency #738

shobsi opened this issue Nov 6, 2024 · 3 comments

Comments

@shobsi
Copy link

shobsi commented Nov 6, 2024

I install anthropic[vertex]

pip install anthropic[vertex]

Then write this code:

def anthropic_transformer(message: str) -> str:
  from anthropic import AnthropicVertex
  client = AnthropicVertex(region=LOCATION, project_id=PROJECT)

  message = client.messages.create(
              max_tokens=1024,
              messages=[
                  {
                      "role": "user",
                      "content": message,
                  }
              ],
              model="claude-3-5-sonnet@20240620",
          )
  content_text = message.content[0].text if message.content else ""
  return content_text

It is running into the following exception:

line 7, in anthropic_transformer
 File \"/layers/google.python.pip/pip/lib/python3.10/site-packages/anthropic/_utils/_utils.py\", 
line 275, in wrapper
 return func(*args, **kwargs)
 File \"/layers/google.python.pip/pip/lib/python3.10/site-packages/anthropic/resources/messages.py\", 
line 888, in create
 return self._post(
 File \"/layers/google.python.pip/pip/lib/python3.10/site-packages/anthropic/_base_client.py\", 
line 1277, in post
 return cast(ResponseT, self.request(cast_to, opts, stream=stream, stream_cls=stream_cls))
 File \"/layers/google.python.pip/pip/lib/python3.10/site-packages/anthropic/_base_client.py\", 
line 954, in request
 return self._request(
 File \"/layers/google.python.pip/pip/lib/python3.10/site-packages/anthropic/_base_client.py\", 
line 981, in _request
 self._prepare_request(request)
 File \"/layers/google.python.pip/pip/lib/python3.10/site-packages/anthropic/lib/vertex/_client.py\", 
line 159, in _prepare_request
 request.headers[\"Authorization\"] = f\"Bearer {self._ensure_access_token()}\"
 File \"/layers/google.python.pip/pip/lib/python3.10/site-packages/anthropic/lib/vertex/_client.py\", 
line 166, in _ensure_access_token
 self.credentials, project_id = load_auth(project_id=self.project_id)
 File \"/layers/google.python.pip/pip/lib/python3.10/site-packages/anthropic/lib/vertex/_auth.py\", 
line 19, in load_auth
 from google.auth.transport.requests import Request # type: ignore[import-untyped]
 File \"/layers/google.python.pip/pip/lib/python3.10/site-packages/google/auth/transport/requests.py\", 
line 28, in <module>
 raise ImportError(
ImportError: The requests library is not installed from please install the requests package to use the requests transport.
"} .

Looks like google-auth needs requests library:

https://github.com/googleapis/google-auth-library-python/blob/3fae8f8368d4651cd11d4af3d80f687eab033175/google/auth/transport/requests.py#L28

google-auth defined "requests" extra:

https://github.com/googleapis/google-auth-library-python/blob/3fae8f8368d4651cd11d4af3d80f687eab033175/setup.py#L33

But anthropic[vertex] uses plain google-auth dependency:

vertex = ["google-auth >=2, <3"]

@RobertCraigie
Copy link
Collaborator

RobertCraigie commented Nov 6, 2024

Thanks for the report, I think a previous version of the google-auth library must've included requests by default... do you know if that was the case and when this was changed?

edit: hmm I'm not seeing any mention of this in the changelog, maybe something was wrong with our env while testing

shobsi added a commit to googleapis/python-bigquery-dataframes that referenced this issue Nov 7, 2024
The latest anthropic release broke the notebook tests. More details in
anthropics/anthropic-sdk-python#738.
@shobsi
Copy link
Author

shobsi commented Nov 7, 2024

Thanks for the report, I think a previous version of the google-auth library must've included requests by default... do you know if that was the case and when this was changed?

edit: hmm I'm not seeing any mention of this in the changelog, maybe something was wrong with our env while testing

Yeah there isn't a change in their dependencies in last 3 months https://github.com/googleapis/google-auth-library-python/commits/3fae8f8368d4651cd11d4af3d80f687eab033175/setup.py

@shobsi
Copy link
Author

shobsi commented Nov 7, 2024

FWIW, I worked around by doing pip install google-auth[requests] in our environment.

shobsi added a commit to googleapis/python-bigquery-dataframes that referenced this issue Nov 7, 2024
* test: add `requests` dependecy to the anthropic remote function

The latest anthropic release broke the notebook tests. More details in
anthropics/anthropic-sdk-python#738.

* fix tupo
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

2 participants