Learn how to build and deploy your own proof of concept based on the deployed Generative AI Document Summarization Jump Start Solution. You can customize the Jump Start Solution deployment by creating a copy of the source code. You can modify the infrastructure and application code as needed and redeploy the solution with the changes.
To avoid conflicts, only one user should modify and deploy a solution in a single Google Cloud project.
Open the directory where the repository is cloned as a workspace in the editor, follow the steps based on whether you are using the Cloud Shell Editor in Preview Mode or Legacy Mode.
Legacy Cloud Shell Editor
- Go to the
File
menu. - Select
Open Workspace
. - Choose the directory where the repository has been cloned. This directory is the current directory in the cloud shell terminal.
New Cloud Shell Editor
- Go the hamburger icon located in the top left corner of the editor.
- Go to the
File
Menu. - Select
Open Folder
. - Choose the directory where the repository has been cloned. This directory is the current directory in the cloud shell terminal.
Before editing the solution, you should be aware of the following information:
- Cloud Functions webhook is present under
./webhook
directory. Theentrypoint
function in the ./webhook/main.py gets triggered when we send a document summarization request. This function is event driven and is called using Cloud Functions. - Terraform / infrastructure code is available in the
*.tf
files.
We also strongly recommend that you familiarize yourself with the Generative AI Document Summarization solution by reading the solution guide.
For example, edit ./webhook/main.py and replace the value of temperature
parameter to 0.9
. Increasing the temperature parameter leads to more diverse responses from the model.
NOTE: A change in the infrastructure code might cause a reduction or increase in the incurred cost.
Create an automated deployment
Optional: If you want to learn individual steps involved in the script, you can skip this step and continue with the rest of the tutorial. However, if you want an automated deployment without following the full tutorial, run the deploy_solution.sh script.
./deploy_solution.sh
Project ID
Get the Project ID:
gcloud config get project
Use the output to set the <var>PROJECT_ID</var>
Deployment region
For <var>REGION</var>, provide the region (e.g. us-central1) where you created the deployment resources.
Deployment name
gcloud infra-manager deployments list --location <var>REGION</var> --filter="labels.goog-solutions-console-deployment-name:* AND labels.goog-solutions-console-solution-id:generative-ai-document-summarization"
Use the output value of name to set the <var>DEPLOYMENT_NAME</var>
Create the cloud storage bucket if it does not exist already
Verify if the Cloud Storage bucket exists
gsutil ls gs://<var>PROJECT_ID</var>_infra_manager_staging
If the command returns an error indicating a non-existing bucket, create the bucket by running below command. Otherwise move on to the next step.
gsutil mb gs://<var>PROJECT_ID</var>_infra_manager_staging/
Fetch Deployment details
gcloud infra-manager deployments describe <var>DEPLOYMENT_NAME</var> --location <var>REGION</var>
From the output, note down the following:
- The values of the existing deployment available in the
terraformBlueprint.inputValues
section. - The service account has the following format:
projects/<var>PROJECT_ID</var>/serviceAccounts/<service-account>@<var>PROJECT_ID</var>.iam.gserviceaccount.com
Note <service-account> part and set the <var>SERVICE_ACCOUNT</var> value.
You can also set it to any existing service account.
Assign the required roles to the service account
CURRENT_POLICY=$(gcloud projects get-iam-policy <var>PROJECT_ID</var> --format=json)
MEMBER="serviceAccount:<var>SERVICE_ACCOUNT</var>@<var>PROJECT_ID</var>.iam.gserviceaccount.com"
while IFS= read -r role || [[ -n "$role" ]]
do \
if echo "$CURRENT_POLICY" | jq -e --arg role "$role" --arg member "$MEMBER" '.bindings[] | select(.role == $role) | .members[] | select(. == $member)' > /dev/null; then \
echo "IAM policy binding already exists for member ${MEMBER} and role ${role}"
else \
gcloud projects add-iam-policy-binding <var>PROJECT_ID</var> \
--member="$MEMBER" \
--role="$role" \
--condition=None
fi
done < "roles.txt"
Create a Terraform input file
Get the existing region being used for terraform resources.
echo $(gcloud infra-manager deployments describe <var>DEPLOYMENT_NAME</var> --location <var>REGION</var> --format json) | jq -r '.terraformBlueprint.inputValues.region.inputValue'
Create an input.tfvars
file in the current directory with the following contents. Update the region fetched above in the TF_REGION
variable:
region="<var>TF_REGION</var>"
project_id = "<var>PROJECT_ID</var>"
bucket_name="genai-webhook"
webhook_name="webhook"
webhook_path="webhook"
gcf_timeout_seconds=900
time_to_enable_apis="180s"
labels = {
"goog-solutions-console-deployment-name" = "<var>DEPLOYMENT_NAME</var>",
"goog-solutions-console-solution-id" = "generative-ai-document-summarization"
}
Deploy the solution
Trigger the re-deployment.
gcloud infra-manager deployments apply projects/<var>PROJECT_ID</var>/locations/<var>REGION</var>/deployments/<var>DEPLOYMENT_NAME</var> --service-account projects/<var>PROJECT_ID</var>/serviceAccounts/<var>SERVICE_ACCOUNT</var>@<var>PROJECT_ID</var>.iam.gserviceaccount.com --local-source="." --inputs-file=./input.tfvars --labels="modification-reason=make-it-mine,goog-solutions-console-deployment-name=<var>DEPLOYMENT_NAME</var>,goog-solutions-console-solution-id=generative-ai-document-summarization,goog-config-partner=sc"
Monitor the deployment
Get the deployment details.
gcloud infra-manager deployments describe <var>DEPLOYMENT_NAME</var> --location <var>REGION</var>
Monitor your deployment at Solution deployments page.
Use any of the following methods to save your edits to the solution
Download the solution
To download your solution, in the File
menu, select Download Workspace
. The solution is downloaded in a compressed format.
Save the solution to your Git repository
Set the remote URL to your Git repository
git remote set-url origin [git-repo-url]
Review the modified files, commit and push to your remote repository branch.
Optional: Use one of the below options in case you want to delete the deployed solution
- Go to Solution deployments page.
- Click on the link under "Deployment name". It will take you to the deployment details page for the solution.
- Click on the "DELETE" button located at the top right corner of the page.