Checkpoints
Enable the Vertex AI API
/ 20
Sample text prompts
/ 50
Sample chat prompts
/ 30
Vertex AI PaLM API: Qwik Start
GSP1155
Overview
The Vertex AI PaLM API enables you to test, customize, and deploy instances of Google's PaLM large language models (LLM) so that you can leverage the capabilities of PaLM in your applications. The PaLM family of models supports text completion and multi-turn chat.
In this lab, you will explore how to leverage Vertex AI for the use cases mentioned above.
Objectives
In this lab, you will learn how to use the PaLM family of models to suport:
- Text completion use cases
- Multi-turn chat integration
Setup and requirements
Before you click the Start Lab button
Read these instructions. Labs are timed and you cannot pause them. The timer, which starts when you click Start Lab, shows how long Google Cloud resources will be made available to you.
This hands-on lab lets you do the lab activities yourself in a real cloud environment, not in a simulation or demo environment. It does so by giving you new, temporary credentials that you use to sign in and access Google Cloud for the duration of the lab.
To complete this lab, you need:
- Access to a standard internet browser (Chrome browser recommended).
- Time to complete the lab---remember, once you start, you cannot pause a lab.
How to start your lab and sign in to the Google Cloud console
-
Click the Start Lab button. If you need to pay for the lab, a pop-up opens for you to select your payment method. On the left is the Lab Details panel with the following:
- The Open Google Cloud console button
- Time remaining
- The temporary credentials that you must use for this lab
- Other information, if needed, to step through this lab
-
Click Open Google Cloud console (or right-click and select Open Link in Incognito Window if you are running the Chrome browser).
The lab spins up resources, and then opens another tab that shows the Sign in page.
Tip: Arrange the tabs in separate windows, side-by-side.
Note: If you see the Choose an account dialog, click Use Another Account. -
If necessary, copy the Username below and paste it into the Sign in dialog.
{{{user_0.username | "Username"}}} You can also find the Username in the Lab Details panel.
-
Click Next.
-
Copy the Password below and paste it into the Welcome dialog.
{{{user_0.password | "Password"}}} You can also find the Password in the Lab Details panel.
-
Click Next.
Important: You must use the credentials the lab provides you. Do not use your Google Cloud account credentials. Note: Using your own Google Cloud account for this lab may incur extra charges. -
Click through the subsequent pages:
- Accept the terms and conditions.
- Do not add recovery options or two-factor authentication (because this is a temporary account).
- Do not sign up for free trials.
After a few moments, the Google Cloud console opens in this tab.
Enable the Vertex AI API
-
In the Google Cloud Console, enter Vertex AI API in the top search bar.
-
Click on the result for Vertex AI API under Marketplace.
-
Click Enable.
Click Check my progress to verify the objectives.
Text Prompts
The following table shows the parameters that you need to configure for the Vertex AI PaLM API for text:
Parameter | Description | Acceptable values |
---|---|---|
|
Text input to generate model response. Prompts can include preamble, questions, suggestions, instructions, or examples. | Text |
|
The temperature is used for sampling during the response generation, which occurs when topP and topK are applied. Temperature controls the degree of randomness in token selection. Lower temperatures are good for prompts that require a more deterministic and less open-ended or creative response, while higher temperatures can lead to more diverse or creative results. A temperature of 0 is deterministic: the highest probability response is always selected. For most use cases, try starting with a temperature of 0.2. |
|
|
Maximum number of tokens that can be generated in the response. Specify a lower value for shorter responses and a higher value for longer responses. A token may be smaller than a word. A token is approximately four characters. 100 tokens correspond to roughly 60-80 words. |
|
|
Top-k changes how the model selects tokens for output. A top-k of 1 means the selected token is the most probable among all tokens in the model's vocabulary (also called greedy decoding), while a top-k of 3 means that the next token is selected from among the 3 most probable tokens (using temperature). For each token selection step, the top K tokens with the highest probabilities are sampled. Then tokens are further filtered based on topP with the final token selected using temperature sampling.Specify a lower value for less random responses and a higher value for more random responses. |
|
|
Top-p changes how the model selects tokens for output. Tokens are selected from most K (see topK parameter) probable to least until the sum of their probabilities equals the top-p value. For example, if tokens A, B, and C have a probability of 0.3, 0.2, and 0.1 and the top-p value is 0.5, then the model will select either A or B as the next token (using temperature) and doesn't consider C. The default top-p value is 0.95. Specify a lower value for less random responses and a higher value for more random responses. |
|
Task 1. Sample text prompts
You will perform the tasks in this lab using curl within Cloud Shell.
- In the Google Cloud Console, open Cloud Shell.
Summarization prompt example
- Run the following curl command in Cloud Shell:
You should see a response that summarizes the content using the parameters defined earlier in this lab. The maxOutputTokens
parameter can be modified to shorten or lengthen the content summary that the PaLM API generates for the reply.
Ideation prompt example
The Vertex AI PaLM API can be used for ideation in addition to summarization.
- Run the following curl command in Cloud Shell to review the output that the PaLM API responds with.
You should see a response from the API call that provides ten questions related to the role of program manager.
- Run the following commands to save response values of the API to a text file:
- Run the following command to copy these file to a pre-created Cloud Storage bucket to track your progress:
Click Check my progress to verify the objectives.
Task 2. Sample chat prompts
For chat API calls, the context
, examples
, and messages
combine to form the prompt. The following table shows the parameters that you need to configure for the Vertex AI PaLM API for text:
Parameter | Description | Acceptable values |
---|---|---|
(optional) |
Context shapes how the model responds throughout the conversation. For example, you can use context to specify words the model can or cannot use, topics to focus on or avoid, or the response format or style. | Text |
(optional) |
List of structured messages to the model to learn how to respond to the conversation. |
List[Structured Message] "input": {"content": "provide content"}, "output": {"content": "provide content"} |
(required) |
Conversation history provided to the model in a structured alternate-author form. Messages appear in chronological order: oldest first, newest last. When the history of messages causes the input to exceed the maximum length, the oldest messages are removed until the entire prompt is within the allowed limit. |
List[Structured Message] "author": "user", "content": "user message", |
|
The temperature is used for sampling during the response generation, which occurs when topP and topK are applied. Temperature controls the degree of randomness in token selection. Lower temperatures are good for prompts that require a more deterministic and less open-ended or creative response, while higher temperatures can lead to more diverse or creative results. A temperature of 0 is deterministic: the highest probability response is always selected. For most use cases, try starting with a temperature of 0.2. |
|
|
Maximum number of tokens that can be generated in the response. Specify a lower value for shorter responses and a higher value for longer responses. A token may be smaller than a word. A token is approximately four characters. 100 tokens correspond to roughly 60-80 words. |
|
|
Top-k changes how the model selects tokens for output. A top-k of 1 means the selected token is the most probable among all tokens in the model's vocabulary (also called greedy decoding), while a top-k of 3 means that the next token is selected from among the 3 most probable tokens (using temperature). For each token selection step, the top K tokens with the highest probabilities are sampled. Then tokens are further filtered based on topP with the final token selected using temperature sampling.Specify a lower value for less random responses and a higher value for more random responses. |
|
|
Top-p changes how the model selects tokens for output. Tokens are selected from most K (see topK parameter) probable to least until the sum of their probabilities equals the top-p value. For example, if tokens A, B, and C have a probability of 0.3, 0.2, and 0.1 and the top-p value is 0.5, then the model will select either A or B as the next token (using temperature) and doesn't consider C. The default top-p value is 0.95. Specify a lower value for less random responses and a higher value for more random responses. |
|
- Run the following curl call to query the model of the PaLM API for the chat prompt provided:
You should see a response from the PaLM API confirming that your favorite movies are based on a book series. You can modify the inputs and the content of the curl call to experiment with this API further.
- Run the following command to save response values of the API to a text file:
- Run the following command to copy this file to a pre-created Cloud Storage bucket to track your progress:
Click Check my progress to verify the objectives.
Congratulations!
In this lab you learned how to use the Vertex AI PaLM API to create text and chat responses. You have taken the first step to start your journey using Vertex AI's PaLM API and other Generative AI development tools!
Next Steps
- Learn more about prompting for design for text and chat.
- Learn more about text embedding.
Google Cloud training and certification
...helps you make the most of Google Cloud technologies. Our classes include technical skills and best practices to help you get up to speed quickly and continue your learning journey. We offer fundamental to advanced level training, with on-demand, live, and virtual options to suit your busy schedule. Certifications help you validate and prove your skill and expertise in Google Cloud technologies.
Manual Last Updated November 21, 2023
Lab Last Tested: November 21, 2023
Copyright 2024 Google LLC All rights reserved. Google and the Google logo are trademarks of Google LLC. All other company and product names may be trademarks of the respective companies with which they are associated.