Schritt 1: Projekt und Quell-Repository einrichten

In diesem Schritt richten Sie Ihr Cloud de Confiance by S3NS -Projekt und Ihre Python-Umgebung in Cloud Shell ein, aktivieren die erforderlichen APIs und weisen die IAM-Rollen (Identity and Access Management) zu, die Sie für die Durchführung der Anleitung benötigen. Außerdem richten Sie ein GitHub-Repository mit den Quellcode-Dateien der App ein, indem Sie das Repository GoogleCloudPlatform/generative-ai forken und klonen. Nachdem Sie diese Schritte ausgeführt haben, können Sie die Einrichtung prüfen, indem Sie die App lokal in Cloud Shell ausführen und testen.

Hinweis

  1. In the Cloud de Confiance console, on the project selector page, select or create a Cloud de Confiance project.

    Roles required to select or create a project

    • Select a project: Selecting a project doesn't require a specific IAM role—you can select any project that you've been granted a role on.
    • Create a project: To create a project, you need the Project Creator role (roles/resourcemanager.projectCreator), which contains the resourcemanager.projects.create permission. Learn how to grant roles.

    Go to project selector

  2. Verify that billing is enabled for your Cloud de Confiance project.

  3. Enable the Agent Platform, Compute Engine, Artifact Registry, Identity-Aware Proxy (IAP), Cloud Run Admin, Cloud Build, Identity and Access Management (IAM) API, and Gemini for Google Cloud APIs, if any are not already enabled.

    Roles required to enable APIs

    To enable APIs, you need the serviceusage.services.enable permission. If you created the project, then you likely already have this permission through the Owner role (roles/owner). Otherwise, you can get this permission through the Service Usage Admin role (roles/serviceusage.serviceUsageAdmin). Learn how to grant roles.

    Enable the APIs

  4. Make sure that you have the following role or roles on the project: Agent Platform User, Cloud Build Editor, Cloud Run Admin, Artifact Registry Admin, Compute Load Balancer Admin, Service Account User, IAP Policy Admin, OAuth Config Editor, and Service Usage Admin.

    Check for the roles

    1. In the Cloud de Confiance console, go to the IAM page.

      Go to IAM
    2. Select the project.
    3. In the Principal column, find all rows that identify you or a group that you're included in. To learn which groups you're included in, contact your administrator.

    4. For all rows that specify or include you, check the Role column to see whether the list of roles includes the required roles.

    Grant the roles

    1. In the Cloud de Confiance console, go to the IAM page.

      Go to IAM
    2. Select the project.
    3. Click Grant access.
    4. In the New principals field, enter your user identifier. This is typically the identifier for a user in a workforce identity pool. For details, see Represent workforce pool users in IAM policies, or contact your administrator.

    5. Click Select a role, then search for the role.
    6. To grant additional roles, click Add another role and add each additional role.
    7. Click Save.

Quell-Repository einrichten

  1. Führen Sie in GitHub einen Fork des Repositorys GoogleCloudPlatform/generative-ai aus. Weitere Informationen zum Forken von Repositories auf GitHub

    Repository auf GitHub forken

  1. Aktivieren Sie Cloud Shell in der Cloud de Confiance Console.

    Cloud Shell aktivieren

    Unten in der Cloud de Confiance Console wird eine Cloud Shell-Sitzung gestartet und eine Eingabeaufforderung angezeigt. Cloud Shell ist eine Shell-Umgebung, in der das Google Cloud CLI bereits installiert ist und Werte für Ihr aktuelles Projekt bereits festgelegt sind. Das Initialisieren der Sitzung kann einige Sekunden dauern.

  2. Führen Sie im Cloud Shell-Terminal die folgenden Befehle aus, um den Fork des Repositorys zu klonen und das Verzeichnis gemini-streamlit-cloudrun als aktives Verzeichnis festzulegen:
    cd
    git clone https://github.com/GIT_USER_NAME/FORK_NAME/
    cd FORK_NAME/gemini/sample-apps/gemini-streamlit-cloudrun

    Ersetzen Sie dabei Folgendes:

    • GIT_USER_NAME: Ihr GitHub-Nutzername
    • FORK_NAME: Der Name des Fork-Repositorys, das Sie gerade in GitHub erstellt haben.

Umgebung und Abhängigkeiten einrichten

  1. Führen Sie im Cloud Shell-Terminal die folgenden Befehle aus, um eine virtuelle Umgebung einzurichten:

    python3 -m venv gemini-streamlit
    source gemini-streamlit/bin/activate
    pip install -r requirements.txt
    
  2. Führen Sie die folgenden Befehle aus, um die Umgebungsvariablen festzulegen, die für die Initialisierung der Agent Platform erforderlich sind:

    export GCP_PROJECT=$GOOGLE_CLOUD_PROJECT
    export GCP_REGION='us-central1' 
    

App lokal testen

  1. Führen Sie die App im Cloud Shell-Terminal mit dem folgenden Befehl aus:

    streamlit run app.py \
      --browser.serverAddress=localhost \
      --server.enableCORS=false \
      --server.enableXsrfProtection=false \
      --server.port 8080
    
  2. Wenn Sie eine Vorschau der App ansehen möchten, klicken Sie in der Cloud Shell-Taskleiste auf Button für Webvorschau und dann auf Vorschau auf Port 8080.

    Weitere Informationen zur Verwendung der Webvorschau finden Sie unter Web-Apps in der Vorschau ansehen.