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

fix: Add validation and documentation for response modalities #416

Conversation

paulelliotco
Copy link
Contributor

This PR addresses issue #386 by adding input validation and clear documentation for response modalities in the live_api_starter.py file.
The changes include:

  • Added validate_config() function to check for invalid or unsupported response modalities.
  • Improved error handling in the run() method to provide clear feedback for invalid configurations.
  • Updated documentation comments to clarify the limitations of response modalities.

@github-actions github-actions bot added the status:awaiting review PR awaiting review from a maintainer label Jan 23, 2025
@markmcd
Copy link
Member

markmcd commented Jan 23, 2025

I like your idea here - however we don't typically show client-side validation of configuration for a few reasons.

  1. the truth is ultimately on the server-side, so client-side validation code can become incorrect over time (this creates a maintenance burden for us here in the cookbook, or broken samples).
  2. data validation is often different per-user, so in this example, a user (either a public user in the future, or a preview user now) would see a false validation error.
  3. some amount of validation can be done by using objects (i.e. proto derived types) instead of python dicts - e.g. types.LiveConnectConfig(response_modalities=[types.Modality.AUDIO]) (where types is google.genai.types). it doesn't apply to this specific case, but it's a general reason why we don't include validation in sample code.

So while ['AUDIO'] and ['TEXT'] are the only valid values right now, I don't think it's worth the extra validation code.

If you think that this particular tool is somewhere that people will get caught up, perhaps add a comment along the lines of # While Gemini 2.0 Flash is in experimental preview mode, only one of AUDIO or TEXT may be passed here.

Or if you have a better suggestion that would reach more users (e.g in the docs on ai.google.dev somewhere), please share.

I'll close this now but if you want to send a PR to add a comment, feel free.

@markmcd markmcd closed this Jan 23, 2025
@paulelliotco
Copy link
Contributor Author

Thank you Mark for the detailed feedback!

I completely understand the reasoning behind avoiding client-side validation. I'll add a comment to clarify the limitation of response modalities in the live_api_starter.py file and submit a PR with this update shortly.

@paulelliotco paulelliotco deleted the fix-response-modality-validation branch January 23, 2025 06:56
@AlipMagical

This comment was marked as spam.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:awaiting review PR awaiting review from a maintainer
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants