最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

api key - Python LangChain with Google google_vertexai or google_genai using API KEY? - Stack Overflow

programmeradmin1浏览0评论

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?

Share Improve this question asked Mar 8 at 5:10 khtehkhteh 4,06610 gold badges59 silver badges104 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

No shortcut. Have to authenticate using the google cloud cli, setup a project and call `vertexai.init()`

发布评论

评论列表(0)

  1. 暂无评论