feat(firebaseai): Add ability for Schema class to export to json schema#18131
feat(firebaseai): Add ability for Schema class to export to json schema#18131cynthiajoan wants to merge 10 commits intomainfrom
Conversation
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. |
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request introduces a significant enhancement to the firebase_ai package by adding support for full JSON Schema in function declarations. The changes are well-implemented, with updates to the Schema and FunctionDeclaration classes to generate standard JSON Schema, comprehensive tests, and a detailed example demonstrating the new capabilities, including complex schemas and references. The code quality is high. I have one minor suggestion to improve the documentation for clarity.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
…/firebase/flutterfire into firebaseai/schema_to_json_schema
| this.minProperties, | ||
| this.maxProperties, | ||
| this.minLength, | ||
| this.maxLength, | ||
| this.pattern, | ||
| this.example, | ||
| this.defaultValue, |
There was a problem hiding this comment.
Have we tested that the model supports these fields? I can't find Vertex AI's documentation for JSON Schema and the Gemini Developer API does not list them.
Notes:
- These fields have been added to
Schema(OpenAPI) but, without testing, I'm unsure if the Gemini actually uses them.- I'm unsure if the Gemini supports these in JSON Schema format since they aren't in the supported list and the API documentation doesn't list them.
- It should be safe to add them since
While the full JSON Schema may be sent, not all features are supported.- It may be somewhat misleading to developers if Gemini ignores them though.
There was a problem hiding this comment.
I did a rough verification and seems even when those fields exist in the proto definition of Schema, model is not respecting them. Good catch and I will remove them.
| this.optionalProperties, | ||
| this.propertyOrdering, | ||
| this.anyOf, | ||
| this.ref, |
There was a problem hiding this comment.
We should add defs since ref could only reference self (#) without it.
Notes:
- In JSON Schema format it would need to use the key
"$defs", rather than"defs". - The Gemini API docs don't list
$defsor$refas being supported but they contradict themselves by showing it in the Recursive Structures example.- We're using
$defsor$refheavily in the Swift SDK and they're working well. It seems unlikely that they're only working by chance (i.e., I don't think Gemini is ignoring them).
- We're using
| expect(schema.toJson(), { | ||
| r'$ref': '#/components/schemas/User', |
There was a problem hiding this comment.
IIUC, toJson() returns the OpenAPI Schema format. In that case, it needs to be ref.
Note: In OpenAPI format, defs and ref only exist in Vertex AI.
Description
Replace this paragraph with a description of what this PR is doing. If you're modifying existing behavior, describe the existing behavior, how this PR is changing it, and what motivated the change.
Related Issues
Replace this paragraph with a list of issues related to this PR from the issue database. Indicate, which of these issues are resolved or fixed by this PR. Note that you'll have to prefix the issue numbers with flutter/flutter#.
Checklist
Before you create this PR confirm that it meets all requirements listed below by checking the relevant checkboxes (
[x]).This will ensure a smooth and quick review process. Updating the
pubspec.yamland changelogs is not required.///).melos run analyze) does not report any problems on my PR.Breaking Change
Does your PR require plugin users to manually update their apps to accommodate your change?