Контрольні точки
Enable the Vertex AI API
/ 25
Extract the content of the image
/ 25
Create prompts with text
/ 25
Create conversations with chat prompt
/ 25
Get Started with Vertex AI Studio
GSP1154
Overview
Vertex AI is a comprehensive machine learning development platform that provides both predictive and generative AI capabilities. It allows you to train, evaluate, and deploy predictive machine learning models for forecasting purposes. Additionally, you can utilize the platform to discover, tune, and serve generative AI models to produce content.
Vertex AI Studio lets you quickly test and customize generative AI models so you can leverage their capabilities in your applications. It provides a variety of tools and resources including both UI (user interface) and coding examples that make it easy to start with generative AI, even if you don't have a background in machine learning.
This lab guides you through Vertex AI Studio, where you'll unlock the potential of cutting-edge generative AI models. You'll explore Gemini and use it to analyze images, design prompts, and generate conversations directly on the Google Cloud console. No need for API or Python SDKs - it's all accessible through the intuitive user interface.
Objectives
In this lab, you will learn how to:
- Analyze images with Gemini
- Explore Vertex AI Studio Freeform mode
- Design text prompts for zero-shot, one-shot, and few-shot prompting
- Generate conversations with chat prompts
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.
Task 1. Analyze images with Gemini in Freeform mode
In this section, you will use Gemini to analyze an image and extract information from it. In Freeform mode, you can design prompts for various tasks such as classification, extraction, and generation. There is no conversation history in Freeform mode, so every prompt is a brand-new request to the model.
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 & APIs.
-
Click Enable.
Analyze images with Gemini
- In the Google Cloud console, from the Navigation menu (), select Vertex AI > Vertex AI Studio > Overview.
- Under Generate with Gemini, click Open Freeform.
The UI contains three main sections:
- Prompt (located in the center): Here, you can create a prompt that utilizes multimodal capabilities.
- Configuration (located on the right): This section allows you to select models, configure parameters, and obtain the corresponding code.
- Response (located at the bottom): This section displays the results of your prompt.
-
On the top left, click Untitled Prompt and rename your prompt as
Image Analysis
. -
In the Configuration section on the top right, click on the Model dropdown then select the gemini-1.5-pro model.
-
Download the sample image. Right-click the timetable image and then save it to your desktop.
- On the top right of the Prompt section, click Insert media > Upload. Upload the timetable image you downloaded. The media can be in the form of an image, video, text, or audio file.
- The image will be displayed inside of the Prompt section. Copy the following text and paste it under the image and click on the Submit button on the bottom right of the Prompt section.
Or be more specific:
Does the title meet your expectations? Try to modify the prompt to see if you get different results.
- Describe the image. Replace the previous prompt with the following and click the Submit button.
- Tune the parameter. In the Configuration section, adjust the temperature by scrolling from left (0) to right (2). Resubmit the prompt to observe any changes in the outcome compared to the previous result.
- Extract the text from the image. Replace the previous prompt with the following:
Further on, if you want to format the output to a list, replace the previous prompt with the following:
Your turn - try out some different prompts! How do these results differ from before?
- Analyze the information on the image. Replace the previous prompt with the following:
Does the result meet your expectations? You are highly encouraged to try different prompts for various tasks. You are also encouraged to experiment with different temperature settings to observe the changes in the result.
-
Once you finish the prompt design, save the prompt by clicking Save on the top right of the Configuration section. For the region, select
from the dropdown and then confirm by clicking Save. -
To find your saved prompts, on the left-hand navigation menu, navigate to Prompt Management.
Click Check my progress to verify the objectives.
Task 2. Explore multimodal capabilities
In addition to images, text, and audio, Gemini is capable of accepting videos as inputs and generating text as an output.
-
Navigate to Cloud Storage > Buckets and copy the name of your Cloud Storage bucket and save it to use in the further step.
-
Click Activate Cloud Shell at the top of the Google Cloud console.
-
In your Cloud Shell terminal, run the command below to copy the sample video
gs://spls/gsp154/video/train.mp4
(preview) to your Cloud Storage bucket. Replace<Your-Cloud-Storage-Bucket>
with the bucket name you copied earlier.
<Your-Cloud-Storage-Bucket>
with your bucket name.-
From the Navigation menu (), select Vertex AI > Vertex AI Studio > Overview.
-
Under Generate with Gemini, click Open Freeform.
-
Click Inset Media > Import from Cloud Storage.
-
Click on your bucket name and then click on the sample video i.e.,
train.mp4
and click Select. -
Generate information about the video by inserting the following prompt and clicking the Submit button.
Freeform mode offers many capabilities such as writing stories from images, analyzing videos, and generating multimedia ads. Explore more freeform use cases by clicking Prompt gallery. Check out more information about design multimodal prompts.
Task 3. Design text prompts
In this section, you will explore designing text prompts in Vertex AI Studio. You will explore zero-shot, one-shot, and few-shot prompting.
Prompt design
You can feed your desired input text, e.g. a question, to the model. The model will then provide a response based on how you structured your prompt. The process of figuring out and designing the best input text (prompt) to get the desired response back from the model is called Prompt Design.
Prompt design methods
There are three main methods to design prompts:
- Zero-shot prompting - This is a method where the LLM is given only a prompt that describes the task and no additional data. For example, if you want the LLM to answer a question, you just prompt "what is prompt design?".
- One-shot prompting - This is a method where the LLM is given a single example of the task that it is being asked to perform. For example, if you want the LLM to write a poem, you might give it a single example poem.
- Few-shot prompting - This is a method where the LLM is given a small number of examples of the task that it is being asked to perform. For example, if you want the LLM to write a news article, you might give it a few news articles to read.
Parameters
Temperature and Token limit are two important parameters that you can adjust to influence the model's response.
-
Temperature controls the randomness in token selection. A lower temperature is good when you expect a true or correct response. A temperature of 0 means the highest probability token is always selected. A higher temperature can lead to diverse, unexpected, or potentially biased results. The
gemini-1.5-pro
model has a temperature range of 0 - 2 and a default of 1. - Output token limit determines the maximum amount of text output from one prompt. A token is approximately four characters.
Zero-shot prompting
Try zero-shot prompting in Free-form mode.
-
Navigate back to the Vertex AI Studio > Overview page and click Open Freeform.
-
On the top right under Model, select the gemini-1.5-pro model.
- Copy the following over to the prompt input field:
- Click on the Submit button.
The model will respond to a comprehensive definition of the term prompt gallery.
Here are some exploratory exercises to explore.
- Adjust the
Output Token limit
parameter to1024
and click the SUBMIT button. - Adjust the
Temperature
parameter to0.5
and click the SUBMIT button. - Adjust the
Temperature
parameter to2.0
and click the SUBMIT button.
Inspect how the responses change as to change the parameters.
One-shot prompting
You can design prompts in more organized ways. You can provide Context and Examples in their respective input fields. One-shot prompting is a method where the model is given a single example of the task that it is being asked to perform. In this section, you will ask the model to complete a sentence.
-
Start by removing any text from the Prompt box.
-
Inside of the Prompt box, click Add examples. This will open a new window where you can add examples for the prompt.
- Add this to the INPUT field:
- Add this to the OUTPUT field:
-
Click on the Add examples button.
-
In the Test field, copy the following in the Input field.
- Click on the Submit button. You should receive a response from the model similar to the following:
Instead of completing the sentence, the model gave a full sentence as a response since you provided an example for the model to base its output from. To change the response to simply complete the sentence, you can adjust the example provided in the OUTPUT field.
- Click the Examples button in the Prompt box and change the OUTPUT field to:
-
Click on the Add examples button.
-
In the Test field, copy the following in the Input field.
- Click on the Submit button. You should receive a response from the model similar to the following:
You can see that the model now completes the sentence based on the example you provided. You have successfully influenced the way the model produces response.
Few-shot prompting
For the next practice, you will use the model to perform sentiment analysis on a sentence, such as determining whether a movie review is positive or negative using few-shot prompting.
- In the Prompt field, delete your examples from the previous section. To delete your examples, hover over the Examples and click the X (Remove File) button.
-
Click the Add examples button to add more examples.
-
Add the following examples:
INPUT | OUTPUT |
---|---|
A well-made and entertaining film | positive |
I fell asleep after 10 minutes | negative |
The movie was ok | neutral |
- Once you have added the examples, click on the Add examples button.
- In the Test field, copy the following in the Input field.
- Click on the Submit button.
The model now provides a sentiment for the input text. For the text It was a time well spent!, the sentiment is labeled as positive.
- Once you finish the prompt design, save the prompt by clicking Save on the top right of the Configuration section. Name the prompt as
Sentiment Analysis
. For the region, selectfrom the dropdown and then confirm by clicking Save.
Click Check my progress to verify the objectives.
Task 4. Generate conversations
Chat mode is a conversational mode that allows you to have a freeform chat with the model. The model uses the conversation history as context for future responses. In this section, you will create a chat prompt and have a conversation with the model.
-
From the left menu, navigate to Chat to create a new chat prompt.
-
On the top right under Model, select the gemini-1.5-flash model.
For this section, you will add context to the chat and let the model respond based on the context provided.
- Add the following context to the System instructions field by clicking the Edit button.
-
Click Apply.
-
Insert the following prompt:
- Click the Submit button.
The model should respond with the following:
-
Next, edit the context of the existing System instructions field by clicking the Edit button.
-
Update the context with the following:
- Insert the following prompt:
- Click the Submit button.
The model should now be more helpful in its response to the user query.
Feel free to experiment with different prompts and context to see how the model responds. You can also add more context to the chat prompt to see how the model responds based on the context provided.
- Once you finish the prompt design, save the prompt by clicking Save on the top right of the Configuration section. Name the prompt as
Support Technician Helper
. For the region, selectfrom the dropdown and then confirm by clicking Save.
Click Check my progress to verify the objectives.
Congratulations!
You learned how to analyze an image with freeform, explore freeform capabilities, create and test a prompt, and generate a conversation. You have taken the first step to start your journey using Vertex AI Studio and Gemini Freeform!
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 October 8, 2024
Lab Last Tested October 8, 2024
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.