Prima di utilizzare LangChain in Vertex AI, devi assicurarti che il tuo ambiente sia configurato. Devi disporre di un progetto Google Cloud con la fatturazione abilitata, avere le autorizzazioni richieste, configurare un bucket Cloud Storage e installare l'SDK Vertex AI per Python. Consulta i seguenti argomenti per assicurarti di essere pronto per iniziare a lavorare con LangChain in Vertex AI.
Configurare il progetto 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.
Ottenere i ruoli richiesti
Per ottenere le autorizzazioni necessarie per utilizzare il motore di ragionamento, chiedi all'amministratore di concederti i seguenti ruoli IAM nel progetto:
-
Utente Vertex AI (
roles/aiplatform.user
) -
Amministratore archiviazione (
roles/storage.admin
)
Per saperne di più sulla concessione dei ruoli, consulta Gestire l'accesso a progetti, cartelle e organizzazioni.
Potresti anche riuscire a ottenere le autorizzazioni richieste tramite i ruoli personalizzati o altri ruoli predefiniti.
Configurare le autorizzazioni dell'agente di servizio
Le applicazioni di cui esegui il deployment nel motore di ragionamento vengono eseguite come account di servizio AI Platform Reasoning Engine Service Agent. Questo account dispone del ruolo Vertex AI Reasoning Engine Service Agent che concede le autorizzazioni di base richieste dall'applicazione del motore di ragionamento. Puoi visualizzare l'elenco completo delle autorizzazioni di base nella documentazione di IAM.
Se hai bisogno di autorizzazioni aggiuntive, puoi concedere all'agente di servizio altri ruoli svolgendo i seguenti passaggi:
Vai alla pagina IAM e seleziona la casella di controllo "Includi concessioni di ruoli fornite da Google".
Trova l'entità corrispondente a
service-PROJECT_NUMBER@gcp-sa-aiplatform-re.iam.gserviceaccount.com
.Aggiungi i ruoli richiesti all'entità facendo clic sul pulsante di modifica e poi sul pulsante di salvataggio.
Generare manualmente un agente di servizio del motore di ragionamento
Sebbene il provisioning dell'agente del servizio del motore di ragionamento venga eseguito automaticamente durante il deployment del motore di ragionamento, potrebbero verificarsi scenari in cui è necessario generarlo manualmente in precedenza. Questo è particolarmente importante quando devi concedere ruoli specifici all'agente di servizio del motore di ragionamento per assicurarti che il processo di implementazione disponga delle autorizzazioni necessarie ed eviti potenziali errori di implementazione.
Ecco i passaggi per generare manualmente un agente di servizio del motore di ragionamento:
Genera l'agente di servizio del motore di ragionamento utilizzando Google Cloud CLI.
gcloud beta services identity create --service=aiplatform.googleapis.com --project=PROJECT-ID-OR-PROJECT-NUMBER
Vai alla pagina IAM e fai clic su Concedi accesso.
Nella sezione Aggiungi entità, inserisci
service-PROJECT_NUMBER@gcp-sa-aiplatform-re.iam.gserviceaccount.com
nel campo Nuove entità.Nella sezione Assegna ruoli, trova e seleziona i ruoli di cui hai bisogno.
Fai clic sul pulsante Salva.
Crea un bucket Cloud Storage
Il motore di ragionamento posiziona gli artefatti delle applicazioni in un bucket Cloud Storage come parte del processo di deployment. Assicurati che il principale autenticato per utilizzare Vertex AI (tu o un account di servizio) abbia accesso Storage Admin
a questo bucket. Questo è necessario perché l'SDK Vertex AI per Python pacchettizza e scrive il codice in questo bucket.
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.
Riga di comando
-
Create a Cloud Storage bucket and configure it as follows:
-
Sostituisci
STORAGE_CLASS
con la classe di archiviazione che preferisci. -
Sostituisci
LOCATION
con la tua posizione preferita (ASIA
,EU
oUS
) -
Sostituisci
BUCKET_NAME
con un nome bucket che soddisfi i requisiti per i nomi dei bucket.
gcloud storage buckets create gs://BUCKET_NAME --default-storage-class STORAGE_CLASS --location LOCATION
Installa e inizializza l'SDK Vertex AI Python
Esegui il seguente comando per installare il pacchetto dell'engine di ragionamento dell'SDK Vertex AI per Python:
pip install google-cloud-aiplatform[reasoningengine,langchain]
Esegui il seguente codice per importare e inizializzare l'SDK per il Reasoning Engine:
import vertexai
from vertexai.preview import reasoning_engines
vertexai.init(
project="PROJECT_ID",
location="LOCATION",
staging_bucket="gs://BUCKET_NAME",
)
- PROJECT_ID: l'ID del tuo progetto.
- LOCATION: la tua regione. Al momento è supportato solo
us-central1
. - BUCKET_NAME: il tuo bucket Google Cloud .