Skip to content

feat(genaisdk): update samples nested objects for better readability #5318

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

CadillacBurgess1
Copy link
Contributor

Description

Fixes #

Note: Before submitting a pull request, please open an issue for discussion if you are not associated with Google.

Checklist

  • I have followed Contributing Guidelines from CONTRIBUTING.MD
  • Tests pass: go test -v ./.. (see Testing)
  • Code formatted: gofmt (see Formatting)
  • Vetting pass: go vet (see Formatting)
  • These samples need a new API enabled in testing projects to pass (let us know which ones)
  • These samples need a new/updated env vars in testing projects set to pass (let us know which ones)
  • This sample adds a new sample directory, and I updated the CODEOWNERS file with the codeowners for this sample
  • This sample adds a new Product API, and I updated the Blunderbuss issue/PR auto-assigner with the codeowners for this sample
  • Please merge this PR for me once it is approved

@CadillacBurgess1 CadillacBurgess1 requested review from a team as code owners May 12, 2025 18:27
@product-auto-label product-auto-label bot added the samples Issues that are directly related to samples. label May 12, 2025
Copy link

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

Choose a reason for hiding this comment

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

Hello @CadillacBurgess1, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

Summary of Changes

This pull request focuses on improving the readability of the content cache samples in the genaisdk by adjusting the structure of nested objects within the code. Specifically, the changes involve reformatting the cacheContents and SystemInstruction configurations in contentcache_create_with_txt_gcs_pdf.go to enhance clarity. Additionally, a minor update was made to the license URL in contentcache_delete.go.

Highlights

  • Code Readability: The primary focus is to enhance the readability of the code by restructuring nested objects, particularly within the createContentCache function.
  • Configuration Changes: The cacheContents and SystemInstruction configurations in contentcache_create_with_txt_gcs_pdf.go have been modified to improve clarity.
  • License URL Update: A minor update was made to the license URL in contentcache_delete.go to ensure it points to the correct location.

Changelog

  • genai/content_cache/contentcache_create_with_txt_gcs_pdf.go
    • Reformatted the cacheContents array to improve readability by explicitly labeling each FileData part.
    • Restructured the CreateCachedContentConfig to enhance clarity, specifically for Contents and SystemInstruction.
    • Added comments to delineate parts within the cacheContents array for better understanding.
  • genai/content_cache/contentcache_delete.go
    • Updated the license URL from https://www.apache.org/licenses/LICENSE-2.0 to https://www.apache.org/licenses/LICENSE-2.0.
Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point in your pull request via creating an issue comment (i.e. comment on the pull request page) using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in issue comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist is currently in preview and may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments to provide feedback.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.


In code's deep forest, clarity's the guide,
Where nested forms can often hide.
A touch of grace,
A structured space,
For minds to wander, side by side.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

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

Choose a reason for hiding this comment

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

Code Review

The pull request updates the samples for nested objects, aiming for better readability. The changes primarily involve reformatting the structure of the cacheContents in contentcache_create_with_txt_gcs_pdf.go to improve clarity. Overall, the changes seem reasonable and contribute to better code organization.

Summary of Findings

  • MIME Type Consistency: The MIME type string literal should be defined as a constant to avoid duplication and potential typos. This applies to both contentcache_create_with_txt_gcs_pdf.go and other files where MIME types are used.
  • Code Comment Style: The code comments Part 1 and Part 2 are useful, but consider standardizing the comment style across the codebase for consistency.
  • HTTP Option Struct Initialization: The initialization of the HTTPOptions struct can be simplified by directly assigning the APIVersion field during struct creation.

Merge Readiness

The pull request is in good shape and improves the readability of the code. However, addressing the comments regarding MIME type consistency and HTTP option struct initialization would further enhance the quality of the code. I am unable to directly approve this pull request, and recommend that others review and approve this code before merging. At a minimum, the high severity issues should be addressed before merging.

Comment on lines 51 to 55
{ // Part 1
FileData: &genai.FileData{
FileURI: "gs://cloud-samples-data/generative-ai/pdf/2312.11805v3.pdf",
MIMEType: "application/pdf",
},

Choose a reason for hiding this comment

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

high

Consider defining application/pdf as a constant to avoid duplication and potential typos. This could be defined at the package level, e.g., const pdfMIMEType = "application/pdf".

FileData: &genai.FileData{
						FileURI:  "gs://cloud-samples-data/generative-ai/pdf/2312.11805v3.pdf",
						MIMEType: pdfMIMEType, // Use the constant here
					},

Comment on lines 57 to 61
{ // Part 2
FileData: &genai.FileData{
FileURI: "gs://cloud-samples-data/generative-ai/pdf/2403.05530.pdf",
MIMEType: "application/pdf",
},

Choose a reason for hiding this comment

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

high

Consider defining application/pdf as a constant to avoid duplication and potential typos. This could be defined at the package level, e.g., const pdfMIMEType = "application/pdf".

FileData: &genai.FileData{
						FileURI:  "gs://cloud-samples-data/generative-ai/pdf/2403.05530.pdf",
						MIMEType: pdfMIMEType, // Use the constant here
					},

Comment on lines 33 to 35
HTTPOptions: genai.HTTPOptions{
APIVersion: "v1",
},

Choose a reason for hiding this comment

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

medium

Consider initializing the HTTPOptions struct directly with the APIVersion to improve readability and conciseness.

For example:

HTTPOptions: genai.HTTPOptions{APIVersion: "v1"},
HTTPOptions: genai.HTTPOptions{
			APIVersion: "v1",
			},

Comment on lines 32 to 34
HTTPOptions: genai.HTTPOptions{
APIVersion: "v1",
},

Choose a reason for hiding this comment

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

medium

Consider initializing the HTTPOptions struct directly with the APIVersion to improve readability and conciseness.

For example:

HTTPOptions: genai.HTTPOptions{APIVersion: "v1"},
HTTPOptions: genai.HTTPOptions{
			APIVersion: "v1",
			},

@CadillacBurgess1 CadillacBurgess1 added the do not merge Indicates a pull request not ready for merge, due to either quality or timing. label May 14, 2025
@telpirion
Copy link
Collaborator

Hey @CadillacBurgess1 -- If you're still working on this PR, let's switch it to a draft. Thanks!

@telpirion telpirion self-assigned this May 15, 2025
@telpirion telpirion marked this pull request as draft May 15, 2025 17:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
do not merge Indicates a pull request not ready for merge, due to either quality or timing. samples Issues that are directly related to samples.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants