Skip to content

Instantly share code, notes, and snippets.

@misho-kr
Last active November 7, 2023 19:25
Show Gist options
  • Save misho-kr/610e681a166759788633fbda74943f62 to your computer and use it in GitHub Desktop.
Save misho-kr/610e681a166759788633fbda74943f62 to your computer and use it in GitHub Desktop.
Generative AI Explorer game

Create and test a prompt, create a conversation, and explore the prompt gallery, all while having fun! Explore Generative AI Studio in Vertex AI. You will compete to see who can finish the game with the highest score. Earn the points by completing the steps in the lab.... and get bonus points for speed!

In this lab, you will use BigQuery for data processing and exploratory data analysis and the Vertex AI platform to train and deploy a custom TensorFlow Regressor model to predict customer lifetime value. The goal of the lab is to introduce to Vertex AI through a high value real world use case - predictive CLV.

  1. Enable Google Cloud services
  2. Create Vertex AI custom service account for Vertex Tensorboard integration
$ gcloud iam service-accounts create vertex-custom-training-sa
$ gcloud projects add-iam-policy-binding $PROJECT_ID \
    --member=serviceAccount:$SERVICE_ACCOUNT_ID@$PROJECT_ID.iam.gserviceaccount.com \
    --role="roles/storage.admin" \
    --role="roles/storage.admin" \
    --role="roles/aiplatform.user"    
  1. Launch Vertex AI Workbench notebook
  2. Clone the lab repository
$ git clone --depth=1 https://github.com/GoogleCloudPlatform/training-data-analyst
$ cd training-data-analyst/self-paced-labs/vertex-ai/vertex-ai-qwikstart
$ pip3 install --user -r requirements.txt
  1. Navigate to lab notebook

training-data-analyst > self-paced-labs > vertex-ai > vertex-ai-qwikstart > lab_exercise.ipynb

PaLM 2 is Google's next generation Large Language Model (LLM) that builds on Google's legacy of breakthrough research in machine learning and responsible AI. PaLM 2 excels at tasks like advanced reasoning, translation, and code generation because of how it was built.

Generative AI Studio and the Vertex AI PaLM API is powered by PaLM 2.

In this lab, you will learn how to get started with Generative AI Studio and the Vertex AI PaLM API:

Creating different types of prompts and getting responses in a jupyter notebook
How to use the Vertex AI PaLM API & Python SDK
  1. Vertex AI Workbench
  2. Open the generative-ai folder
  • Click on intro_palm_api.ipynb
  • Follow the steps in the notebook and run each cell one at a time
    • Installing the Python SDK
    • Using Vertex AI PaLM API
    • Text generation model with text-bison@001
      • Understanding model parameters (temperature, max_output_token, top_k, top_p)
    • Chat model with chat-bison@001
    • Embeddings model with textembedding-gecko@001

The Vertex AI PaLM API for text enables you to structure prompts however you like. You can add contextual information, instructions, examples, questions, lists, and any other types of text content that you can think of.

In this lab, you will learn about prompt design and various text generation use cases using the Vertex AI PaLM API. What you will learn:

How to get started with prompt engineering with the PaLM API:

Best practices
Zero-, one- and few-shot prompting

How to explore some text generation use cases with the PaLM API:

Ideation
Q&A
Text classification
Text extraction
Text summarization
  1. Vertex AI Workbench
  2. Open generative-ai/language/prompts folder
  3. Explore the notebooks
Notebook Description
intro_prompt_design.ipynb Best practices for prompt design
examples/ideation.ipynb PaLM APIs for idea generation, brainstorming, writing
examples/question_answering.ipynb PaLM APIs for question-answering
examples/text_classification.ipynb PaLM APIs for classifying text
examples/text_extraction.ipynb PaLM APIs for extracting information from text
examples/text_summarization.ipynb PaLM APIs for summarizing text

Vertex AI is an end-to-end machine learning platform that helps you build, deploy, and scale machine learning models faster and easier. It provides a unified experience for managing all aspects of the machine learning lifecycle, from data preparation to model deployment.

Vertex AI Generative AI Studio is a cloud-based platform that allows users to create and experiment with generative AI models. The platform provides a variety of tools and resources that make it easy to get started with generative AI, even if you don't have a background in machine learning.

In this lab, you use Generative AI Studio with Vertex AI to create prompts and conversations on Google Cloud console, without using the API or Python SDKs. Objectives

In this lab, you learn how to perform the following tasks:

Create prompts with free-form and structured mode.
Create conversations.
Explore the prompt gallery.
  1. Enable the Vertex AI API
  2. Create prompts
  • Create Prompt lets you designs prompts for tasks relevant to your business use case including code generation
  • Prompt design
    • Zero-shot prompting - This is a method where the LLM is given no additional data on the specific task that it is being asked to perform
    • 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
    • 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
  • FREE-FORM - This mode provides a free and easy approach to design your prompt. It is suitable for small and experimental prompts with no additional examples. You will be using this to explore zero-shot prompting.
  • STRUCTURED - This mode provides an easy-to-use template approach to prompt design. Context and multiple examples can be added to the prompt in this mode. This is especially useful for one-shot and few-shot prompting methods which you will be exploring later.
  1. Create conversations
  • Create Chat Prompt lets you have a freeform chat with the model, which tracks what was previously said and responds based on context
  1. Explore prompt gallery
  • In the Generative AI Studio menu, click on Language to find Prompt Gallery on the Get Started page
  • Prompt Gallery lets you explore how generative AI models can work for a variety of use cases
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment