Sebelum menggunakan LangChain di Vertex AI, Anda harus memastikan lingkungan Anda sudah disiapkan. Anda harus memiliki project Google Cloud dengan penagihan diaktifkan, memiliki izin yang diperlukan, menyiapkan bucket Cloud Storage, dan menginstal Vertex AI SDK untuk Python. Gunakan topik berikut untuk memastikan Anda siap mulai menggunakan LangChain di Vertex AI.
Menyiapkan project Google Cloud
- Sign in to your Google Cloud account. If you're new to Google Cloud, create an account to evaluate how our products perform in real-world scenarios. New customers also get $300 in free credits to run, test, and deploy workloads.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Make sure that billing is enabled for your Google Cloud project.
-
Enable the Vertex AI and Cloud Storage APIs.
-
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
-
Make sure that billing is enabled for your Google Cloud project.
-
Enable the Vertex AI and Cloud Storage APIs.
Mendapatkan peran yang diperlukan
Untuk mendapatkan izin yang Anda perlukan untuk menggunakan mesin penalaran, minta administrator untuk memberi Anda peran IAM berikut di project Anda:
-
Pengguna Vertex AI (
roles/aiplatform.user
) -
Storage Admin (
roles/storage.admin
)
Untuk mengetahui informasi selengkapnya tentang cara memberikan peran, lihat Mengelola akses ke project, folder, dan organisasi.
Anda mungkin juga bisa mendapatkan izin yang diperlukan melalui peran khusus atau peran bawaan lainnya.
Menyiapkan izin agen layanan
Aplikasi yang Anda deploy di mesin penalaran berjalan sebagai akun layanan AI Platform Reasoning Engine Service Agent. Akun ini memiliki peran Vertex AI Reasoning Engine Service Agent yang memberikan izin dasar yang diperlukan aplikasi mesin penalaran Anda. Anda dapat melihat daftar lengkap izin dasar di dokumentasi IAM.
Jika memerlukan izin tambahan, Anda dapat memberikan peran tambahan kepada Agen Layanan ini dengan melakukan langkah-langkah berikut:
Buka halaman IAM, lalu centang kotak "Sertakan pemberian peran yang disediakan Google".
Temukan akun utama yang cocok dengan
service-PROJECT_NUMBER@gcp-sa-aiplatform-re.iam.gserviceaccount.com
.Tambahkan peran yang diperlukan ke akun utama dengan mengklik tombol edit, lalu tombol simpan.
Membuat Agen Layanan Reasoning Engine secara Manual
Meskipun Agen Layanan Mesin Penalaran disediakan secara otomatis selama deployment mesin penalaran, mungkin ada skenario saat Anda perlu membuatnya secara manual terlebih dahulu. Hal ini sangat penting saat Anda perlu memberikan peran tertentu ke Agen Layanan Reasoning Engine untuk memastikan proses deployment memiliki izin yang diperlukan dan menghindari potensi kegagalan deployment.
Berikut adalah langkah-langkah untuk membuat Agen Layanan Mesin Penalaran secara manual:
Buat Agen Layanan Reasoning Engine menggunakan Google Cloud CLI.
gcloud beta services identity create --service=aiplatform.googleapis.com --project=PROJECT-ID-OR-PROJECT-NUMBER
Buka halaman IAM, lalu klik Berikan Akses.
Di bagian Tambahkan akun utama, di kolom New principals, masukkan
service-PROJECT_NUMBER@gcp-sa-aiplatform-re.iam.gserviceaccount.com
.Di bagian Assign roles, cari dan pilih peran yang Anda butuhkan.
Klik tombol Save.
Membuat bucket Cloud Storage
Mesin penalaran melakukan staging artefak aplikasi Anda di bucket Cloud Storage sebagai bagian dari proses deployment. Pastikan
prinsipal yang diautentikasi untuk menggunakan Vertex AI (baik Anda sendiri maupun
akun layanan) memiliki akses Storage Admin
ke bucket ini. Hal ini diperlukan
karena Vertex AI SDK untuk Python mengemas dan menulis kode Anda ke bucket ini.
Google Cloud console
- In the Google Cloud console, go to the Cloud Storage Buckets page.
- Click Create.
- On the Create a bucket page, enter your bucket information. To go to the next
step, click Continue.
-
In the Get started section, do the following:
- Enter a globally unique name that meets the bucket naming requirements.
- To add a
bucket label,
expand the Labels section ( ),
click add_box
Add label, and specify a
key
and avalue
for your label.
-
In the Choose where to store your data section, do the following:
- Select a Location type.
- Choose a location where your bucket's data is permanently stored from the Location type drop-down menu.
- If you select the dual-region location type, you can also choose to enable turbo replication by using the relevant checkbox.
- To set up cross-bucket replication, select
Add cross-bucket replication via Storage Transfer Service and
follow these steps:
Set up cross-bucket replication
- In the Bucket menu, select a bucket.
In the Replication settings section, click Configure to configure settings for the replication job.
The Configure cross-bucket replication pane appears.
- To filter objects to replicate by object name prefix, enter a prefix that you want to include or exclude objects from, then click Add a prefix.
- To set a storage class for the replicated objects, select a storage class from the Storage class menu. If you skip this step, the replicated objects will use the destination bucket's storage class by default.
- Click Done.
-
In the Choose how to store your data section, do the following:
- Select a default storage class for the bucket or Autoclass for automatic storage class management of your bucket's data.
- To enable hierarchical namespace, in the Optimize storage for data-intensive workloads section, select Enable hierarchical namespace on this bucket.
- In the Choose how to control access to objects section, select whether or not your bucket enforces public access prevention, and select an access control method for your bucket's objects.
-
In the Choose how to protect object data section, do the
following:
- Select any of the options under Data protection that you
want to set for your bucket.
- To enable soft delete, click the Soft delete policy (For data recovery) checkbox, and specify the number of days you want to retain objects after deletion.
- To set Object Versioning, click the Object versioning (For version control) checkbox, and specify the maximum number of versions per object and the number of days after which the noncurrent versions expire.
- To enable the retention policy on objects and buckets, click the Retention (For compliance) checkbox, and then do the following:
- To enable Object Retention Lock, click the Enable object retention checkbox.
- To enable Bucket Lock, click the Set bucket retention policy checkbox, and choose a unit of time and a length of time for your retention period.
- To choose how your object data will be encrypted, expand the Data encryption section (Data encryption method. ), and select a
- Select any of the options under Data protection that you
want to set for your bucket.
-
In the Get started section, do the following:
- Click Create.
Command line
-
Create a Cloud Storage bucket and configure it as follows:
-
Ganti
STORAGE_CLASS
dengan kelas penyimpanan pilihan Anda. -
Ganti
LOCATION
dengan lokasi pilihan Anda (ASIA
,EU
, atauUS
) -
Ganti
BUCKET_NAME
dengan nama bucket yang memenuhi persyaratan nama bucket.
gcloud storage buckets create gs://BUCKET_NAME --default-storage-class STORAGE_CLASS --location LOCATION
Menginstal dan melakukan inisialisasi Vertex AI SDK untuk Python
Jalankan perintah berikut untuk menginstal paket mesin penalaran Vertex AI SDK untuk Python:
pip install google-cloud-aiplatform[reasoningengine,langchain]
Jalankan kode berikut untuk mengimpor dan melakukan inisialisasi SDK untuk Reasoning Engine:
import vertexai
from vertexai.preview import reasoning_engines
vertexai.init(
project="PROJECT_ID",
location="LOCATION",
staging_bucket="gs://BUCKET_NAME",
)
- PROJECT_ID: Project ID Anda.
- LOCATION: Region Anda. Saat ini, hanya
us-central1
yang didukung. - BUCKET_NAME: Bucket Google Cloud Anda.