1. Introduction
In this codelab, you can find instructions to create a summarization service in a Slack Workspace by providing an integration with the Slack Slash Command.
The user invokes a Slash Command /summarize
and enters the text to be summarized. Then the Slack application invokes the associated Cloud Function that accepts the text and invokes the PaLM API for summarization. The summarized text is then returned back to the Slack Slash Command and displayed as a response in the Slack Application.
. The list of Google Cloud services used are:
- Cloud Functions
- Vertex AI PaLM API
- Cloud Logging
What you'll build
You'll create
- A Cloud Function that invokes the PaLM API for text summarization on the text that is coming from Slack using the Slash Command
- Slack Application that invokes the above Cloud Function for summarization.
2. Requirements
3. Before you begin
- In the Google Cloud Console, on the project selector page, select or create a Google Cloud project
- Ensure that billing is enabled for your Google Cloud project. Learn how to check if billing is enabled on a project
- Ensure that the Cloud Functions API and Vertex AI APIs are enabled.
- Activate Cloud Shell from Google Cloud console by following the instructions here
- If your project is not set, use the following command to set it:
gcloud config set project <YOUR_PROJECT_ID>
- In the Cloud Shell, set the following environment variables:
export GCP_PROJECT=<YOUR_PROJECT_ID>
export GCP_REGION=us-central1
4. Deploying the Cloud Function
To create and deploy Cloud Functions, follow these steps:
- Clone code from repo https://github.com/rominirani/genai-apptemplates-googlecloud by executing the following command in your Cloud Shell terminal:
git clone https://github.com/rominirani/genai-apptemplates-googlecloud
- This command will clone the repo contents into the folder genai-templates-googlecloud.
- Navigate to the folder of the project we care about by executing the following command from the Cloud Shell Terminal:
cd genai-apptemplates-googlecloud/summarization-slack
- You should see both the files main.py and requirements.txt in the summarization-slack folder either by executing the dir command or by navigating to the Cloud Shell Editor.
- To deploy the Cloud Function, run the gcloud functions deploy command:
gcloud functions deploy summarizeText \
--gen2 \
--runtime=python311 \
--source=. \
--region=$GCP_REGION \
--project=$GCP_PROJECT \
--entry-point=summarizeText \
--trigger-http \
--set-env-vars=GCP_PROJECT=$GCP_PROJECT,GCP_REGION=$GCP_REGION \
--max-instances=1
After you have deployed the Cloud Function, the URL of the Cloud Function that has been deployed is displayed on the Cloud Shell Terminal. The URL is in the following format:
https://$GCP_REGION-$GCP_PROJECT.cloudfunctions.net/summarizeText
Note the URL that was displayed, it will be required to create the Slack Slash Command.
5. Create the Slack Slash Command
Let's create a custom Slash Command in Slack. This custom command /summarize
invokes the Cloud Function that we have deployed in the previous section.
To create a Slash Command, perform the following steps:
- Go to api.slack.com/apps.
- Click Create New App.
- In the Create an app window, choose From scratch option.
- Enter a name for your app. For example,
Summarization Slack Application.
Select the Slack Workspace for your app development. - Click Create App. The Settings page opens.
- In the Settings page, click Basic Information > Slash Commands. Click Create New Command.
- In the Create New Command form, provide the following values:
- Command: give a slash command. For example,
/summarize.
- Request URL: provide the full URL of the Cloud Function that we deployed. For example,
https://$GCP_REGION-$GCP_PROJECT.cloudfunctions.net/summarizeText
- Enter a Short Description, Usage Hint and save.
- Go back to Settings > Basic Information. Click Install your app and then click Install to Workspace. The app is installed into your workspace.
This completes the creation of the custom Slack App that is now installed in your Slack Workspace and has a custom Slash command (/summarize
) that helps a user summarize the text that they provide in the message.
6. Test the Slash Command
- Go to the Slack Workspace where you have installed the Summarization Slack Application:
Go to https://slack.com/intl/en-in/workspace-signin and enter "Find your workspaces" to spot your workspace name. Select that.
- In the chat, nter the text prefixed by the slash command "/summarize ". A sample invocation is shown below:
- Click the Send button, to invoke the Cloud Function and display the summarization response as shown below:
7. Clean up
To avoid incurring charges to your Google Cloud account for the resources used in this post, follow these steps:
- In the Google Cloud console, go to the Manage resources page.
- In the project list, select the project that you want to delete, and then click Delete.
- In the dialog, type the project ID, and then click Shut down to delete the project.
- If you want to keep your project, skip the above steps and delete the Cloud Function by navigating to Cloud Functions and from the list of functions, check the one you want to delete and click DELETE.
8. Congratulations
Congratulations! You have successfully created a text summarization service in the Slack Application.