langchain-ai / langchain-google

MIT License
120 stars 150 forks source link

Running gemini 1.5 pro producing error with langchain 0.2.0 and langchain-google-vertexai 1.0.4 #284

Closed Subham0793 closed 5 months ago

Subham0793 commented 5 months ago

I am loading the model using ChatVertexAI function. Also the credentials i am loading from a dictionary with

from langchain_google_vertexai import ChatVertexAI
import google.auth

info = {
            "type": "service_account",
            "project_id": "",
            "private_key_id": "",
            "private_key": "",
            "client_email": "",
            "client_id": "",
            "auth_uri": "",
            "token_uri": "",
            "auth_provider_x509_cert_url": "",
            "client_x509_cert_url": "",
            "universe_domain": "",
        }

self.credentials, self.project_id = google.auth.load_credentials_from_dict(info)

model = ChatVertexAI(
            model_name="gemini-1.5-pro-001",
            project=self.project_id,
            credentials=self.credentials,
            convert_system_message_to_human=False,
            temperature=self.config.temperature,
            max_retries=self.config.max_retries,
            max_tokens=self.config.max_tokens,
            streaming=True
        )

chain = prompt | model

response = chain.ainvoke() --> giving error

following is the traceback:


Traceback (most recent call last):

    response = await chain.ainvoke(
               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\subhamnagar\AppData\Local\miniconda3\envs\test_nia_v2\Lib\site-packages\langchain_core\runnables\base.py", line 2446, in ainvoke
    input = await step.ainvoke(
            ^^^^^^^^^^^^^^^^^^^
  File "C:\Users\subhamnagar\AppData\Local\miniconda3\envs\test_nia_v2\Lib\site-packages\langchain_core\language_models\chat_models.py", line 191, in ainvoke
    llm_result = await self.agenerate_prompt(
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\subhamnagar\AppData\Local\miniconda3\envs\test_nia_v2\Lib\site-packages\langchain_core\language_models\chat_models.py", line 609, in agenerate_prompt
    return await self.agenerate(
           ^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\subhamnagar\AppData\Local\miniconda3\envs\test_nia_v2\Lib\site-packages\langchain_core\language_models\chat_models.py", line 569, in agenerate
    raise exceptions[0]
  File "C:\Users\subhamnagar\AppData\Local\miniconda3\envs\test_nia_v2\Lib\site-packages\langchain_core\language_models\chat_models.py", line 754, in _agenerate_with_cache
    result = await self._agenerate(
             ^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\subhamnagar\AppData\Local\miniconda3\envs\test_nia_v2\Lib\site-packages\langchain_google_vertexai\chat_models.py", line 865, in _agenerate
    return await self._agenerate_gemini(
           ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\subhamnagar\AppData\Local\miniconda3\envs\test_nia_v2\Lib\site-packages\langchain_google_vertexai\chat_models.py", line 751, in _agenerate_gemini
    self.async_prediction_client.generate_content,
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\subhamnagar\AppData\Local\miniconda3\envs\test_nia_v2\Lib\site-packages\langchain_google_vertexai\_base.py", line 104, in async_prediction_client
    self.async_client = v1beta1PredictionServiceAsyncClient(
                        ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\subhamnagar\AppData\Local\miniconda3\envs\test_nia_v2\Lib\site-packages\google\cloud\aiplatform_v1beta1\services\prediction_service\async_client.py", line 266, in __init__
    self._client = PredictionServiceClient(
                   ^^^^^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\subhamnagar\AppData\Local\miniconda3\envs\test_nia_v2\Lib\site-packages\google\cloud\aiplatform_v1beta1\services\prediction_service\client.py", line 713, in __init__
    self._transport = Transport(
                      ^^^^^^^^^^
  File "C:\Users\subhamnagar\AppData\Local\miniconda3\envs\test_nia_v2\Lib\site-packages\google\cloud\aiplatform_v1beta1\services\prediction_service\transports\grpc_asyncio.py", line 199, in __init__
    super().__init__(
  File "C:\Users\subhamnagar\AppData\Local\miniconda3\envs\test_nia_v2\Lib\site-packages\google\cloud\aiplatform_v1beta1\services\prediction_service\transports\base.py", line 103, in __init__
    credentials, _ = google.auth.default(
                     ^^^^^^^^^^^^^^^^^^^^
  File "C:\Users\subhamnagar\AppData\Local\miniconda3\envs\test_nia_v2\Lib\site-packages\google\auth\_default.py", line 694, in default
    raise exceptions.DefaultCredentialsError(_CLOUD_SDK_MISSING_CREDENTIALS)
google.auth.exceptions.DefaultCredentialsError: Your default credentials were not found.

I don't want to put the default credentials as I am getting the credentials from the info dictionary.

Following is the versioning


python==3.11
google-api-python-client==2.131.0
google-cloud-aiplatform==1.53.0
langchain==0.2.0
langchain-google-community==1.0.4
langchain_google_vertexai==1.0.4

Same code is working fine with following versions:

python==3.10
langchain==0.1.17
google-api-python-client==2.127.0
google-cloud-aiplatform==1.50.0
langchain-google-community==1.0.3
langchain_google_vertexai==1.0.3

But i want to upgrade the langchain to keep up with the updates.

Subham0793 commented 5 months ago

Hi @gmogr, I saw your comment in some other issue. Would be great if you can help me resolve this issue too. I am not able to use ChatVertexAI with upgraded langchain versions. Getting the error as specified in the above query.

lkuligin commented 5 months ago

It should be fixed with the recent version on main.