In order to use the Vertex AI SDK for Python for LLMs, complete the following steps:
- Create Service Credentials
- Create a Key for the Service Account
- Downloading Key as JSON File
- Set Google Application Credentials Environment Variable
- Install Requirements from via "pip install requirements.txt"
- Connecting Vertex API Python API Calls
-
Create Service Credentials
- Navigate to the Google Cloud Console: Access the Google Cloud Console and search for 'API & Services'.
- Access Credentials: In the left menu, select 'Credentials'.
- Create Service Account: Click on 'Create Credentials' and choose 'Service Account'.
- Configure Service Account:
- Enter a name for the Service Account.
- Optionally, provide a description.
- Click 'Create and Continue'.
-
Configure Service Account Permissions (Optional)
- Assign Roles: If needed, assign roles to the service account. For using Vertex AI, consider selecting the 'Vertex AI Service Agent' role.
- Add Users: Optionally, grant other users access to this service account.
- Complete Setup: Click 'Done'.
-
Generate Service Account Key
- Find the Service Account: Locate your new service account in the 'Service Accounts' section.
- Add Key: Select the service account, navigate to 'Keys', and choose to add a new key.
- Download Key: Select 'JSON' as the key type and click 'Create'. The key will download automatically—usually to your system's default download folder.
-
Set Up Environment for API Access
- Move Key to Working Directory: (Optional) Move the downloaded JSON key to your project's working directory for easier reference.
- Set Environment Variable: Configure the Google Application Credentials environment variable. On most systems, this can be set by running: