Skip to content

fix(ai): fix serialization for Content with no parts field #6964

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

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

thatfiredev
Copy link
Member

In the Gemini Dev API, Content#parts is optional, while in the Vertex AI API it is marked as required.
This PR should settle the difference by exposing a list of parts with at least 1 element whenever Content#parts is not present.

Golden file PR: FirebaseExtended/vertexai-sdk-test-data#40

Copy link
Contributor

github-actions bot commented May 15, 2025

📝 PRs merging into main branch

Our main branch should always be in a releasable state. If you are working on a larger change, or if you don't want this change to see the light of the day just yet, consider using a feature branch first, and only merge into the main branch when the code complete and ready to be released.

Copy link
Contributor

github-actions bot commented May 15, 2025

Test Results

 12 files   -  12  12 suites   - 12   19s ⏱️ -15s
103 tests +  1  98 ✅  -   4  0 💤 ±0  5 ❌ +5 
103 runs   - 101  98 ✅  - 106  0 💤 ±0  5 ❌ +5 

For more details on these failures, see this check.

Results for commit 75e5e14. ± Comparison against base commit af24598.

♻️ This comment has been updated with latest results.

@google-oss-bot
Copy link
Contributor

google-oss-bot commented May 15, 2025

@google-oss-bot
Copy link
Contributor

google-oss-bot commented May 15, 2025

Size Report 1

Affected Products

  • firebase-ai

    TypeBase (af24598)Merge (8c73fb4)Diff
    aar825 kB825 kB+136 B (+0.0%)
    apk (aggressive)1.55 MB1.55 MB+84 B (+0.0%)
    apk (release)9.52 MB9.52 MB+92 B (+0.0%)

Test Logs

  1. https://storage.googleapis.com/firebase-sdk-metric-reports/i6dKMWRlS1.html

@thatfiredev thatfiredev requested a review from rlazo May 27, 2025 14:29
@@ -90,7 +90,7 @@ constructor(public val role: String? = "user", public val parts: List<Part>) {
@Serializable
internal data class Internal(
@EncodeDefault val role: String? = "user",
val parts: List<InternalPart>
@EncodeDefault val parts: List<InternalPart> = emptyList()
Copy link
Collaborator

Choose a reason for hiding this comment

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

can you add a comment here noting why we need the encodeDefault in this case, as it's not immediately apparent.

Copy link
Member Author

Choose a reason for hiding this comment

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

I actually can't remember why I added this here 😳 the tests still pass even if we don't use encodeDefault.

Copy link
Collaborator

Choose a reason for hiding this comment

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

Devs can send a request with an empty list, so makes sense that @EncodeDefault that is used for encoding, not decoding, isn't 100% necessary. Should be safe to remove

Copy link
Member Author

Choose a reason for hiding this comment

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

Removed

Copy link
Collaborator

Choose a reason for hiding this comment

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

SGTM. Don't forget to add an entry to the changelog

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants