langchain-ai / langchain-google

MIT License
76 stars 79 forks source link

ChatAnthropicVertex not working with `credentials` param #344

Open mattsalt123 opened 4 days ago

mattsalt123 commented 4 days ago

When service account credentials are passed to ChatAnthropicVertex they are not used during the client setup (AnthropicVertex/AsyncAnthropicVertex) which results in the following error:

ERROR:root:Your default credentials were not found. To set up Application Default Credentials, see https://cloud.google.com/docs/authentication/external/set-up-adc for more information.

AnthropicVertex was recently updated (v0.30.0) to now accept credentials as a parameter.

Example non-working code:

credentials = service_account.Credentials.from_service_account_info(json_credentials)
return ChatAnthropicVertex(
        model=model,
        location=location,
        credentials=credentials,
        project=project_id,
    )

I believe the code that will require changes is here: https://github.com/langchain-ai/langchain-google/blob/e7b45726adc15e17f75f018f4542ec11aecdaeb3/libs/vertexai/langchain_google_vertexai/model_garden.py#L154-L166