Skip to content

feat(genai): Add new samples for the Interactions API - #14640

Open
holtskinner wants to merge 4 commits into
mainfrom
interactions
Open

holtskinner wants to merge 4 commits into
mainfrom
interactions

Conversation

@holtskinner

Copy link
Copy Markdown
Contributor

Description

Fixes #

Checklist

Testing

  • I have tested this change on a live environment and verified it works as intended.

Compliance & Style


Post-Approval Actions

  • Please merge this PR for me once it is approved

@holtskinner
holtskinner requested review from a team as code owners October 13, 2026 15:14
@product-auto-label product-auto-label Bot added the samples Issues that are directly related to samples. label Oct 13, 2026
@snippet-bot

snippet-bot Bot commented Oct 13, 2026

Copy link
Copy Markdown

Here is the summary of changes.

You are about to add 49 region tags.

This comment is generated by snippet-bot.
If you find problems with this result, please file an issue at:
https://github.com/googleapis/repo-automation-bots/issues.
To update this comment, add snippet-bot:force-run label or use the checkbox below:

  • Refresh this comment

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request updates the google-genai dependency to version 2.29.0 and introduces a comprehensive suite of new example scripts and tests demonstrating the interactions API across multiple capabilities, including bounding boxes, code execution, controlled generation, image generation, text generation, thinking, and tools. Feedback on the new code highlights a potential hang in headless environments due to the use of im.show() in the bounding box example, as well as several potential FileNotFoundError crashes across multiple image generation examples where output files are saved to a directory (output_folder) without first ensuring its creation.

# Position the text at the top-left corner of the box
draw.text((abs_x_min + 8, abs_y_min + 6), bbox.label, fill=color)

im.show()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Using im.show() can cause issues or hang in headless environments (such as CI/CD pipelines) where no display server or default image viewer is available. To make this sample more robust and consistent with other image-processing samples in this repository, consider saving the output image to a file instead of calling im.show().

Suggested change
im.show()
import os
output_dir = "output_folder"
os.makedirs(output_dir, exist_ok=True)
im.save(os.path.join(output_dir, "socks-bounding-box.png"))

Comment on lines +42 to +44
if interaction.output_image:
image = Image.open(BytesIO(base64.b64decode(interaction.output_image.data)))
image.save("output_folder/bw-example-image.png")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Saving the image directly to "output_folder/bw-example-image.png" without ensuring that output_folder exists will raise a FileNotFoundError if the directory does not already exist. Ensure the directory is created before saving the image.

Suggested change
if interaction.output_image:
image = Image.open(BytesIO(base64.b64decode(interaction.output_image.data)))
image.save("output_folder/bw-example-image.png")
if interaction.output_image:
import os
image = Image.open(BytesIO(base64.b64decode(interaction.output_image.data)))
output_dir = "output_folder"
os.makedirs(output_dir, exist_ok=True)
image.save(os.path.join(output_dir, "bw-example-image.png"))

Comment on lines +44 to +46
if interaction.output_image:
image = Image.open(BytesIO(base64.b64decode(interaction.output_image.data)))
image.save("output_folder/video-image.png")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Saving the image directly to "output_folder/video-image.png" without ensuring that output_folder exists will raise a FileNotFoundError if the directory does not already exist. Ensure the directory is created before saving the image.

Suggested change
if interaction.output_image:
image = Image.open(BytesIO(base64.b64decode(interaction.output_image.data)))
image.save("output_folder/video-image.png")
if interaction.output_image:
import os
image = Image.open(BytesIO(base64.b64decode(interaction.output_image.data)))
output_dir = "output_folder"
os.makedirs(output_dir, exist_ok=True)
image.save(os.path.join(output_dir, "video-image.png"))

Comment on lines +35 to +37
if interaction.output_image:
image = Image.open(BytesIO(base64.b64decode(interaction.output_image.data)))
image.save("output_folder/example-breakfast-meal.png")

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Saving the image directly to "output_folder/example-breakfast-meal.png" without ensuring that output_folder exists will raise a FileNotFoundError if the directory does not already exist. Ensure the directory is created before saving the image.

Suggested change
if interaction.output_image:
image = Image.open(BytesIO(base64.b64decode(interaction.output_image.data)))
image.save("output_folder/example-breakfast-meal.png")
if interaction.output_image:
import os
image = Image.open(BytesIO(base64.b64decode(interaction.output_image.data)))
output_dir = "output_folder"
os.makedirs(output_dir, exist_ok=True)
image.save(os.path.join(output_dir, "example-breakfast-meal.png"))

Comment on lines +35 to +55
saved_files = []
image_counter = 1

for step in interaction.steps:
if step.type == "model_output":
for content in step.content:
if content.type == "text":
print(content.text)
elif content.type == "image":
image = Image.open(BytesIO(base64.b64decode(content.data)))
filename = f"output_folder/example-cats-0{image_counter}.png"
image.save(filename)
saved_files.append(filename)
image_counter += 1

# Fallback to output_image if no step-level images collected
if not saved_files and interaction.output_image:
image = Image.open(BytesIO(base64.b64decode(interaction.output_image.data)))
filename = "output_folder/example-cats-01.png"
image.save(filename)
saved_files.append(filename)

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

Saving images directly to "output_folder/" without ensuring that the directory exists will raise a FileNotFoundError if the directory does not already exist. Ensure the directory is created before saving the images.

    import os
    output_dir = "output_folder"
    os.makedirs(output_dir, exist_ok=True)
    saved_files = []
    image_counter = 1

    for step in interaction.steps:
        if step.type == "model_output":
            for content in step.content:
                if content.type == "text":
                    print(content.text)
                elif content.type == "image":
                    image = Image.open(BytesIO(base64.b64decode(content.data)))
                    filename = os.path.join(output_dir, f"example-cats-0{image_counter}.png")
                    image.save(filename)
                    saved_files.append(filename)
                    image_counter += 1

    # Fallback to output_image if no step-level images collected
    if not saved_files and interaction.output_image:
        image = Image.open(BytesIO(base64.b64decode(interaction.output_image.data)))
        filename = os.path.join(output_dir, "example-cats-01.png")
        image.save(filename)
        saved_files.append(filename)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

samples Issues that are directly related to samples.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant