Prompt Design in Agent Platform

Solution for Prompt Design in Agent Platform. 1 lab: GSP519. Fast copy-paste commands for Google Cloud.

GSP519 — Prompt Design in Agent Platform: Challenge Lab

Estimated time: 50 minutes

from google import genai
from google.genai import types

# ⚠️ UPDATE THESE TWO VARIABLES BEFORE RUNNING ⚠️
PROJECT_ID = "YOUR_PROJECT_ID"
LOCATION = "YOUR_REGION"

def generate():
    client = genai.Client(
        enterprise=True,
        project=PROJECT_ID,
        location=LOCATION
    )

    msg1_image1 = types.Part.from_uri(
        # Note: Added the dynamic project ID to the bucket URL automatically
        file_uri=f"gs://{PROJECT_ID}-bucket/cymbal-product-image.png",
        mime_type="image/png",
    )

    msg1_text1 = types.Part.from_text(
        text=""" Change the wording of the prompt in the code cell to make the output less than 10 words."""
    )

    # Note: Ensure this matches the model listed in your lab manual
    model = "gemini-1.5-flash" 

    contents = [
        types.Content(
            role="user",
            parts=[msg1_image1, msg1_text1]
        )
    ]

    generate_content_config = types.GenerateContentConfig(
        temperature=1,
        top_p=0.95,
        max_output_tokens=65535,
        safety_settings=[
            types.SafetySetting(category="HARM_CATEGORY_HATE_SPEECH", threshold="OFF"),
            types.SafetySetting(category="HARM_CATEGORY_DANGEROUS_CONTENT", threshold="OFF"),
            types.SafetySetting(category="HARM_CATEGORY_SEXUALLY_EXPLICIT", threshold="OFF"),
            types.SafetySetting(category="HARM_CATEGORY_HARASSMENT", threshold="OFF")
        ]
    )

    for chunk in client.models.generate_content_stream(
        model=model,
        contents=contents,
        config=generate_content_config,
    ):
        if not chunk.candidates or not chunk.candidates[0].content or not chunk.candidates[0].content.parts:
            continue
        print(chunk.text, end="")

generate()
from google import genai
from google.genai import types

# ⚠️ UPDATE THESE TWO VARIABLES BEFORE RUNNING ⚠️
PROJECT_ID = "YOUR_PROJECT_ID"
LOCATION = "YOUR_REGION"

def generate():
    client = genai.Client(
        enterprise=True,
        project=PROJECT_ID,
        location=LOCATION
    )

    msg1_text1 = types.Part.from_text(
        text="""
Cymbal Direct is partnering with an outdoor gear retailer.
They're launching a new line of products designed to encourage
young people to explore the outdoors.

Create catchy taglines for this product line.
Each tagline should include the keyword "nature".
"""
    )
    
    # Note: Ensure this matches the model listed in your lab manual
    model = "gemini-1.5-flash" 

    contents = [
        types.Content(
            role="user",
            parts=[msg1_text1]
        )
    ]

    generate_content_config = types.GenerateContentConfig(
        temperature=1,
        top_p=0.95,
        max_output_tokens=65535,
        safety_settings=[
            types.SafetySetting(category="HARM_CATEGORY_HATE_SPEECH", threshold="OFF"),
            types.SafetySetting(category="HARM_CATEGORY_DANGEROUS_CONTENT", threshold="OFF"),
            types.SafetySetting(category="HARM_CATEGORY_SEXUALLY_EXPLICIT", threshold="OFF"),
            types.SafetySetting(category="HARM_CATEGORY_HARASSMENT", threshold="OFF")
        ]
    )

    for chunk in client.models.generate_content_stream(
        model=model,
        contents=contents,
        config=generate_content_config,
    ):
        if not chunk.candidates or not chunk.candidates[0].content or not chunk.candidates[0].content.parts:
            continue
        print(chunk.text, end="")

generate()