# Google VertexAI

## Prerequisites

1. [Start your GCP](https://cloud.google.com/docs/get-started)
2. Install the [Google Cloud CLI](https://cloud.google.com/sdk/docs/install-sdk)

## Setup

### Enable vertex AI API

1. Go to Vertex AI on GCP and click **"ENABLE ALL RECOMMENDED API"**

<figure><img src="https://823733684-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F00tYLwhz5RyR7fJEhrWy%2Fuploads%2Fgit-blob-7fa3cc1976669c8e948275249b91570e48cee11a%2Fvertex_AI_enable.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

## Create credential file *(Optional)*

There are 2 ways to create credential file

### No. 1 : Use GCP CLI

1. Open terminal and run the following command

```bash
gcloud auth application-default login
```

2. Login to your GCP account
3. Check your credential file. You can find your credential file in `~/.config/gcloud/application_default_credentials.json`

### No. 2 : Use GCP console

1. Go to GCP console and click **"CREATE CREDENTIALS"**

<figure><img src="https://823733684-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F00tYLwhz5RyR7fJEhrWy%2Fuploads%2Fgit-blob-2f971263504cc787cc565a4f1004b24057cfebf1%2Fcreate_credential.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

2. Create service account

<figure><img src="https://823733684-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F00tYLwhz5RyR7fJEhrWy%2Fuploads%2Fgit-blob-cf02cf123e7aefe6ad16204eb785ba06c8f6dcd1%2Fcreate_service_account.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

3. Fill in the form of Service account details and click **"CREATE AND CONTINUE"**
4. Select proper role (for example Vertex AI User) and click **"DONE"**

<figure><img src="https://823733684-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F00tYLwhz5RyR7fJEhrWy%2Fuploads%2Fgit-blob-d8eb25fa99414ebacb7c125ab50727f529699816%2Fselect_role.png?alt=media" alt=""><figcaption></figcaption></figure>

5. Click service account that you created and click **"ADD KEY" -> "Create new key"**

<figure><img src="https://823733684-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F00tYLwhz5RyR7fJEhrWy%2Fuploads%2Fgit-blob-f5bc8779f7e367b45726282f8d9c373c9968957b%2Fadd_key.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

6. Select JSON and click **"CREATE"** then you can download your credential file

<figure><img src="https://823733684-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F00tYLwhz5RyR7fJEhrWy%2Fuploads%2Fgit-blob-f3ae424f0c75d31762eb02f764cb1ee4f6fce50a%2Fcreate_key.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

## Flowise

<figure><img src="https://823733684-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F00tYLwhz5RyR7fJEhrWy%2Fuploads%2Fgit-blob-ea118f463e99e1f31691f273e78801d70ddfd1e8%2Fimage%20(4)%20(1)%20(1)%20(1)%20(1)%20(1)%20(1)%20(1)%20(1)%20(1)%20(1)%20(1)%20(1)%20(1).png?alt=media" alt=""><figcaption></figcaption></figure>

### Without credential file

If you are using a GCP service like Cloud Run, or if you have installed default credentials on your local machine, you do not need to set this credential.

### With credential file

1. Go to Credential page on Flowise and click **"Add credential"**
2. Click Google Vertex Auth

<figure><img src="https://823733684-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F00tYLwhz5RyR7fJEhrWy%2Fuploads%2Fgit-blob-8d85044420f2585d55569103e48fbaa633f3a36c%2Fgoogle_vertex_auth.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

3. Register your credential file. There are 2 ways to register your credential file.

<figure><img src="https://823733684-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2F00tYLwhz5RyR7fJEhrWy%2Fuploads%2Fgit-blob-4eb2ee5842aa280dec3952b70a4fc76a0259630f%2Fregister_credential.png?alt=media" alt="" width="563"><figcaption></figcaption></figure>

* **Option 1 : Enter path of your credential file**
  * If you have credential file on your machine, you can enter the path of your credential file into `Google Application Credential File Path`
* **Option 2 : Paste text of your credential file**
  * Or you can copy all text in the credential file and paste it into `Google Credential JSON Object`

4. Finally, click "Add" button.
5. **🎉**You can now use ChatGoogleVertexAI with the credential in Flowise now!

### Resources

* [LangChain JS GoogleVertexAI](https://js.langchain.com/docs/api/llms_googlevertexai/classes/GoogleVertexAI)
* [Google Service accounts overview](https://cloud.google.com/iam/docs/service-account-overview?)
* [Try Google Vertex AI Palm 2 with Flowise: Without Coding to Leverage Intuition](https://tech.beatrust.com/entry/2023/08/22/Try_Google_Vertex_AI_Palm_2_with_Flowise%3A_Without_Coding_to_Leverage_Intuition)
