How to use google_vertexai
or google_genai
with LangChain in Python? I get the following error:
USER_AGENT environment variable not set, consider setting it to identify your requests.
Traceback (most recent call last):
File "/home/khteh/.local/lib/python3.12/site-packages/google/cloud/aiplatform/initializer.py", line 365, in project
self._set_project_as_env_var_or_google_auth_default()
File "/home/khteh/.local/lib/python3.12/site-packages/google/cloud/aiplatform/initializer.py", line 112, in _set_project_as_env_var_or_google_auth_default
credentials, project = google.auth.default()
^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3/dist-packages/google/auth/_default.py", line 691, in default
raise exceptions.DefaultCredentialsError(_CLOUD_SDK_MISSING_CREDENTIALS)
google.auth.exceptions.DefaultCredentialsError: Your default credentials were not found. To set up Application Default Credentials, see for more information.
google.auth.exceptions.GoogleAuthError: Unable to find your project. Please provide a project ID by:
- Passing a constructor argument
- Using vertexai.init()
- Setting project using 'gcloud config set project my-project'
- Setting a GCP environment variable
- To create a Google Cloud project, please follow guidance at
How can I set up the auth to use either one of them? Which is better one to use between google_vertexai
and google_genai
?
How to use google_vertexai
or google_genai
with LangChain in Python? I get the following error:
USER_AGENT environment variable not set, consider setting it to identify your requests.
Traceback (most recent call last):
File "/home/khteh/.local/lib/python3.12/site-packages/google/cloud/aiplatform/initializer.py", line 365, in project
self._set_project_as_env_var_or_google_auth_default()
File "/home/khteh/.local/lib/python3.12/site-packages/google/cloud/aiplatform/initializer.py", line 112, in _set_project_as_env_var_or_google_auth_default
credentials, project = google.auth.default()
^^^^^^^^^^^^^^^^^^^^^
File "/usr/lib/python3/dist-packages/google/auth/_default.py", line 691, in default
raise exceptions.DefaultCredentialsError(_CLOUD_SDK_MISSING_CREDENTIALS)
google.auth.exceptions.DefaultCredentialsError: Your default credentials were not found. To set up Application Default Credentials, see https://cloud.google/docs/authentication/external/set-up-adc for more information.
google.auth.exceptions.GoogleAuthError: Unable to find your project. Please provide a project ID by:
- Passing a constructor argument
- Using vertexai.init()
- Setting project using 'gcloud config set project my-project'
- Setting a GCP environment variable
- To create a Google Cloud project, please follow guidance at https://developers.google/workspace/guides/create-project
How can I set up the auth to use either one of them? Which is better one to use between google_vertexai
and google_genai
?
1 Answer
Reset to default 0No shortcut. Have to authenticate using the google cloud cli, setup a project and call `vertexai.init()`