Skip to content
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

feat(genai sdk): text generation samples (2nd batch) #5125

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

Conversation

Valeriy-Burlaka
Copy link
Member

@Valeriy-Burlaka Valeriy-Burlaka commented Feb 4, 2025

Description

Based on #5124, which should be merged first.

Adds samples for text generation using the new GenAI SDK (2nd batch). Added region tags:

  • googlegenaisdk_textgen_with_txt_img
  • googlegenaisdk_textgen_config_with_txt
  • googlegenaisdk_textgen_sys_instr_with_txt
  • googlegenaisdk_textgen_with_txt_stream

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

@Valeriy-Burlaka Valeriy-Burlaka self-assigned this Feb 4, 2025
@Valeriy-Burlaka Valeriy-Burlaka requested review from a team as code owners February 4, 2025 13:50
Copy link

snippet-bot bot commented Feb 4, 2025

Here is the summary of changes.

You are about to add 2 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

@product-auto-label product-auto-label bot added the samples Issues that are directly related to samples. label Feb 4, 2025
Copy link

@code-review-assist code-review-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.

Hi team,

I'm currently reviewing this pull request and will post my feedback in a few minutes. In the meantime, here's a summary of the changes for you and other reviewers to quickly get up to speed:

This pull request, authored by Valeriy-Burlaka, aims to add samples for text generation using the new GenAI SDK (second batch). The changes include:

  • Go version update: The go.mod files across numerous directories have been updated from go 1.22.0 to go 1.23.0.
  • New GenAI SDK samples: New code has been added for text generation, including:
    • text_generation/text_generation_test.go: Unit tests for the text generation functionality. (Lines 1-54)
    • text_generation/textgen_with_txt.go: A sample demonstrating text generation using a text prompt. (Lines 1-61)
    • text_generation/textgen_with_txt_img.go: A sample demonstrating text generation using both text and image prompts. (Lines 1-68)
  • go.work update: The go.work file has been updated to include the new genai directory. (Line 87)

The author has also completed a checklist ensuring tests pass, code is formatted, and relevant files (CODEOWNERS and blunderbuss) are updated. There is a request to merge the PR once approved.

I'll provide a more detailed review shortly.

Meanwhile, a little verse to lighten the mood:

Code flows like a river,
Tests run, a green light appears,
Bugs flee in the night.

Thanks,
Gemini

@Valeriy-Burlaka Valeriy-Burlaka marked this pull request as draft February 4, 2025 13:50
Copy link

@code-review-assist code-review-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.

This pull request adds samples for text generation using the GenAI SDK. The code is well-structured and includes appropriate tests. The samples demonstrate generating text with both text prompts and text/image prompts. The use of internal/testutil for testing is correct. However, there are a few minor improvements that can be made, particularly around error handling and documentation, and updating the Go version in the go.mod files.

I've summarized the relevant elements from the contributing guidelines below:

  • Print to an io.Writer: Snippets should print to an io.Writer passed as an argument.
  • Declare a context.Context: Declare a context.Context within the sample function.
  • Function arguments: Keep function arguments minimal.
  • Return errors: Return errors with context using fmt.Errorf.
  • Testing: Tests are required and should use testutil.SystemTest.
  • Go Version: Use the minimum Go version supported by the repo.

return fmt.Errorf("unable to create genai client: %w", err)
}

resp, err := client.Models.GenerateContent(ctx, modelName, genai.Text("How does AI work?"), nil)

Choose a reason for hiding this comment

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

medium

It's good practice to handle potential errors when calling GenerateContent. Consider adding an error check and returning an appropriate error if the call fails.

Suggested change
resp, err := client.Models.GenerateContent(ctx, modelName, genai.Text("How does AI work?"), nil)
resp, err := client.Models.GenerateContent(ctx, modelName, genai.Text("How does AI work?"), nil)
if err != nil {
return fmt.Errorf("GenerateContent: %w", err)
}

Copy link
Member Author

Choose a reason for hiding this comment

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

Displays a wrong diff, the error is handled.

}},
}},
}
resp, err := client.Models.GenerateContent(ctx, modelName, contents, nil)

Choose a reason for hiding this comment

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

medium

Similar to the previous suggestion, it's good practice to handle potential errors when calling GenerateContent. Consider adding an error check and returning an appropriate error if the call fails.

Suggested change
resp, err := client.Models.GenerateContent(ctx, modelName, contents, nil)
resp, err := client.Models.GenerateContent(ctx, modelName, contents, nil)
if err != nil {
return fmt.Errorf("GenerateContent: %w", err)
}

Copy link
Member Author

Choose a reason for hiding this comment

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

ditto

@Valeriy-Burlaka Valeriy-Burlaka changed the title feat(genai sdk): text generation samples feat(genai sdk): text generation samples (2nd batch) Feb 6, 2025
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