Skip to content

[VertexAI] Add new Schema options #1242

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

Merged
merged 1 commit into from
May 2, 2025
Merged

[VertexAI] Add new Schema options #1242

merged 1 commit into from
May 2, 2025

Conversation

a-maurice
Copy link
Collaborator

Description

Provide details of the change, and generalize the change in the PR title above.

Add Schema support for: Title, MinItems, MaxItems, Minimum, Maximum, PropertyOrdering, AnyOf


Testing

Describe how you've tested these changes.

Added some new test cases


Type of Change

Place an x the applicable box:

  • Bug fix. Add the issue # below if applicable.
  • New feature. A non-breaking change which adds functionality.
  • Other, such as a build process or documentation change.

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 @a-maurice, 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 introduces new schema options to enhance the functionality of the VertexAI integration. Specifically, it adds support for Title, MinItems, MaxItems, Minimum, Maximum, PropertyOrdering, and AnyOf schema properties. These additions provide more control and flexibility when defining data schemas for generative models. The changes include modifications to the Schema.cs file to incorporate these new properties and their corresponding logic for serialization. Additionally, a new test case, TestAnyOfSchemaResponse, has been added to UIHandlerAutomated.cs to validate the functionality of the AnyOf schema option.

Highlights

  • Schema Enhancements: The pull request introduces several new schema options, including Title, MinItems, MaxItems, Minimum, Maximum, PropertyOrdering, and AnyOf, to provide more control over data generation.
  • Nullable SchemaType: The Type property in the Schema class is now nullable (SchemaType?) to accommodate the AnyOf schema, which doesn't have a specific schema type.
  • New Test Case: A new test case, TestAnyOfSchemaResponse, has been added to verify the functionality of the AnyOf schema option.
  • Numeric Schema Constraints: The Int, Long, Double, and Float schema types now support minimum and maximum constraints to guide the model in generating values within a specific range.
  • Object Schema Ordering: The Object schema now supports propertyOrdering, allowing developers to suggest the order of keys in the generated JSON string.

Changelog

Click here to see the changelog
  • vertexai/src/Schema.cs
    • Added null case to SchemaType enum conversion to string.
    • Made the Type property nullable (SchemaType?).
    • Added Title property to the Schema class.
    • Added MinItems and MaxItems properties for array schemas.
    • Added Minimum and Maximum properties for numeric schemas.
    • Added PropertyOrdering property for object schemas.
    • Added AnyOfSchemas property to support multiple schema types for a single field.
    • Modified the Schema constructor to accept new parameters.
    • Updated the Int, Long, Double, and Float methods to accept minimum and maximum parameters.
    • Updated the Object method to accept propertyOrdering and title parameters.
    • Updated the Array method to accept minItems and maxItems parameters.
    • Added the AnyOf method to create a schema that conforms to any of the provided sub-schemas.
    • Updated the ToJson method to include the new properties in the JSON serialization.
  • vertexai/testapp/Assets/Firebase/Sample/VertexAI/UIHandlerAutomated.cs
    • Added TestAnyOfSchemaResponse to the list of automated tests.
    • Added minimum constraint to basicParameterIntName in CreateGenerativeModelWithBasicFunctionCall.
    • Added maximum constraint to basicParameterObjectFloat in CreateGenerativeModelWithBasicFunctionCall.
    • Added a new test case TestAnyOfSchemaResponse to test the AnyOf schema response.
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.


A schema's tale,
New options now prevail,
Data's form refined,
With constraints aligned,
A model's output, no longer frail.

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

This pull request introduces new schema options for VertexAI, enhancing the flexibility and expressiveness of the schema definitions. The changes include adding support for Title, MinItems, MaxItems, Minimum, Maximum, PropertyOrdering, and AnyOf. The addition of new test cases is also a good practice. Overall, the changes look good, but there are a few areas that could be improved.

Summary of Findings

  • Nullable SchemaType: Changing SchemaType Type to SchemaType? Type allows for a null SchemaType, which is used in the AnyOf schema. This is a good approach to handle the absence of a specific type for AnyOf.
  • ReadOnlyCollection Initialization: Using ?.ToList().AsReadOnly() for initializing ReadOnlyCollection is a concise way to handle null IEnumerable values. However, consider using CollectionExtensions.AsReadOnlySafe() to avoid creating a new list when the input is already a ReadOnlyCollection.
  • Minimum and Maximum Parameters: The addition of minimum and maximum parameters to the Int, Long, Double, and Float schema types enhances the ability to specify constraints on numeric values. Ensure that these parameters are correctly handled and validated in the backend.
  • AnyOf Schema: The implementation of the AnyOf schema allows for specifying multiple possible structures or types for a single field. This is a powerful feature that can improve the flexibility of schema definitions.

Merge Readiness

The pull request introduces valuable new features and schema options. However, addressing the identified issues, particularly the potential for code duplication and the handling of nullable types, would further enhance the quality and maintainability of the code. I am unable to approve this pull request, and recommend that another reviewer approves this code before merging. I recommend that the pull request not be merged until the high severity issues are addressed.

@a-maurice a-maurice merged commit f835c5d into main May 2, 2025
5 checks passed
@a-maurice a-maurice deleted the am-vertexai_newschemas branch May 2, 2025 20:19
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants