Skip to content

[AI] Finish Reasons#15931

Draft
paulb777 wants to merge 4 commits intopb-image-configfrom
pb-finish-reason
Draft

[AI] Finish Reasons#15931
paulb777 wants to merge 4 commits intopb-image-configfrom
pb-finish-reason

Conversation

@paulb777
Copy link
Member

@paulb777 paulb777 commented Mar 11, 2026

PR Review: [AI] Finish Reasons #15931

This PR adds support for new FinishReason values in the Firebase AI SDK, primarily targeting image generation safety and complex tool-calling scenarios.


Summary of Changes

  • GenerateContentResponse.swift:
    • Introduced new enum cases to FinishReason: imageSafety, imageProhibitedContent, imageOther, noImage, imageRecitation, language, unexpectedToolCall, tooManyToolCalls, missingThoughtSignature, and malformedResponse.
    • Added detailed documentation for each new static property.
  • GenerateContentIntegrationTests.swift:
    • Added generateContent_finishReason_imageSafety, an integration test using a "graphic violence" prompt to ensure the SDK correctly identifies safety violations.
    • Ensures the SDK returns a .stop reason or throws a .responseStoppedEarly error with the appropriate context.
  • APITests.swift:
    • Added testFinishReason_decoding to verify that all new reasons are correctly mapped during JSON decoding.
  • CHANGELOG.md:
    • Updated to document these additions for end-users.

@gemini-code-assist
Copy link
Contributor

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 by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description

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 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.

@paulb777
Copy link
Member Author

/gemini review

Copy link
Contributor

@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 adds several new FinishReason cases, primarily related to image generation and tool usage, and includes corresponding integration tests. The changes are generally good, but I've identified a minor grammatical error in a documentation comment and a more significant issue in one of the new integration tests. The test for Imagen safety filtering is incorrectly structured and will fail as it doesn't account for an expected error being thrown. I've provided a corrected implementation for the test.

@paulb777
Copy link
Member Author

/gemini review

Copy link
Contributor

@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 adds several new FinishReason cases to the SDK, along with corresponding unit and integration tests. The changes to the FinishReason enum and the new integration test for Gemini models are well-implemented. However, I've identified a logical issue in the new Imagen integration test and an opportunity to improve maintainability in the new unit test for decoding finish reasons. My detailed feedback is in the comments below.

@paulb777
Copy link
Member Author

/gemini review

Copy link
Contributor

@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 adds several new FinishReason cases to handle more scenarios, particularly around image generation and tool calls. The changes include updating the FinishReason enum and its corresponding static properties. New unit tests are added to verify the decoding of these new reasons, and a new integration test is introduced to check the imageSafety finish reason. The changes are well-implemented and tested. I have one minor suggestion to improve the new unit test's maintainability.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant