- Notifications
You must be signed in to change notification settings - Fork 1.2k
feat(genai): add provisioned throughput and controlled generation samples #3278
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
base: main
Are you sure you want to change the base?
feat(genai): add provisioned throughput and controlled generation samples #3278
Conversation
| Here is the summary of changes. You are about to add 2 region tags.
This comment is generated by snippet-bot.
|
Summary of ChangesHello @jdomingr, 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! This pull request expands the Generative AI C# samples by introducing two new functionalities: controlled generation, which guides model output to specific enum values, and provisioned throughput, which optimizes performance for text generation. Additionally, it includes minor documentation improvements by fixing typos in existing sample comments. Highlights
Using Gemini Code AssistThe 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 by creating a comment using either
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 Limitations & Feedback Gemini Code Assist 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. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here. 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. Footnotes
|
There was a problem hiding this comment.
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 adds two new C# samples for the GenAI library, demonstrating provisioned throughput and controlled generation, along with their corresponding tests. It also includes minor typo fixes in existing files. The new samples are a good addition. My review focuses on improving the correctness and robustness of these new samples. I've pointed out that the provisioned throughput sample is misleadingly configured for the pay-as-you-go model. Additionally, I've suggested changes to make the response handling safer in both new samples to avoid potential runtime exceptions.
genai/api/GenAI.Samples/ProvisionedThroughput/ProvisionedThroughputWithTxt.cs Outdated Show resolved Hide resolved
genai/api/GenAI.Samples/ControlledGeneration/ControlledGenWithEnumSchema.cs Show resolved Hide resolved
genai/api/GenAI.Samples/ProvisionedThroughput/ProvisionedThroughputWithTxt.cs Show resolved Hide resolved
genai/api/GenAI.Samples/ControlledGeneration/CtrlGenWithEnumSchema.cs Outdated Show resolved Hide resolved
genai/api/GenAI.Samples/ProvisionedThroughput/ProvisionedThroughputWithTxt.cs Outdated Show resolved Hide resolved
genai/api/GenAI.Samples/ProvisionedThroughput/ProvisionedThroughputWithTxt.cs Outdated Show resolved Hide resolved
genai/api/GenAI.Samples.Tests/ControlledGeneration/CtrlGenWithEnumSchemaTest.cs Outdated Show resolved Hide resolved
genai/api/GenAI.Samples/ControlledGeneration/CtrlGenWithEnumSchema.cs Outdated Show resolved Hide resolved
| string projectId = "your-project-id", | ||
| string location = "us-central1", | ||
| string model = "gemini-2.5-flash") | ||
| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some of the samples have a try-catch to catch the errors. I think that we should aim for that here as well just to 1. showcase some simple error handling, and 2. keep consistency with other languages that have a try-catch as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the suggestion, but as far as I know, it is not necessary to implement exception handling in the samples, unless there are specific error handling cases that we need to show, which, in my opinion, does not apply in this case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
in general, we recommend it so that if there is some kind of issue with the service that you can print that out rather than the user assuming something is broken with the sample. This reduces frustration and gives the user a path to move forward.
…lled generation sample file name
Add new samples:
Also, I fixed some comments in TextGenWithPdf.cs and TextGenWithPdf.cs.
All local tests have passed