Skip to content

[Vertex AI] Parameterize integration tests for Vertex and Dev API #14540

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Merged
merged 1 commit into from
Mar 7, 2025

Conversation

andrewheard
Copy link
Contributor

@andrewheard andrewheard commented Mar 7, 2025

  • Added a new GenerateContentIntegrationTests test suite, which runs a generateContent test against the Vertex AI (v1 and v1beta) API, as well as the Developer API (v1beta).
  • Refactored the VertexAI component to use one static method vertexAI(app:location:), where app is optional, to reduce code and documentation duplication.
  • Removed the internal VertexAI.developer(...) API in favour of calling VertexAI.vertexAI(app:location:apiConfig:) (also internal -- I think we should consider renaming to differentiate it from the public API) directly in the integration tests.
    • I removed this for now since it didn't reduce it didn't reduce the boilerplate in the integration test. This can be revisited when we have a public API surface.

#no-changelog

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.

Hello @andrewheard, 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 a new integration test suite, GenerateContentIntegrationTests, to verify the generateContent functionality against Vertex AI (v1 and v1beta) and the Developer API (v1beta). It also refactors the VertexAI component to consolidate the initialization logic into a single static method, vertexAI(app:location:), reducing code duplication. The internal VertexAI.developer(...) API has been removed in favor of directly calling VertexAI.vertexAI(app:location:apiConfig:) in the integration tests.

Highlights

  • Integration Tests: Added a new GenerateContentIntegrationTests suite to test generateContent against Vertex AI and Developer APIs.
  • Refactoring: Refactored the VertexAI component to use a single static method vertexAI(app:location:) for initialization.
  • API Simplification: Removed the internal VertexAI.developer(...) API, using VertexAI.vertexAI(app:location:apiConfig:) directly in tests.

Changelog

Click here to see the changelog
  • FirebaseVertexAI/Sources/VertexAI.swift
    • Consolidated the vertexAI initialization logic into a single static method vertexAI(app:location:).
    • Removed the separate developerAPI methods.
    • Modified the vertexAI method to accept an optional FirebaseApp instance.
  • FirebaseVertexAI/Tests/TestApp/Tests/Integration/GenerateContentIntegrationTests.swift
    • Introduced a new test suite GenerateContentIntegrationTests.
    • Added a generateContent test case that runs against Vertex AI and Developer APIs.
    • Included helper methods for creating GenerativeModel instances with specific configurations.
  • FirebaseVertexAI/Tests/TestApp/Tests/Integration/IntegrationTests.swift
    • Removed the testGenerateContent method, as its functionality is now covered by the new integration test suite.
  • FirebaseVertexAI/Tests/TestApp/VertexAITestApp.xcodeproj/project.pbxproj
    • Added the GenerateContentIntegrationTests.swift file to the project.
    • Updated the project file to include the new test file in the build process.
  • FirebaseVertexAI/Tests/Unit/VertexComponentTests.swift
    • Updated testVertexInstanceCreation_defaultApp to assert default values.
    • Added testVertexInstanceCreation_defaultApp_customLocation to test custom locations.
    • Modified testSameAppAndDifferentAPI_newInstanceCreated to use vertexAI with different APIConfig values.
    • Updated testModelResourceName_developerAPI_generativeLanguage and testGenerativeModel_developerAPI to use the new vertexAI method with APIConfig.
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.


Did you know?

The first version of Swift was released in 2014.

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

The pull request introduces a new integration test suite for the generateContent method, covering Vertex AI and Developer APIs. It also refactors the VertexAI component to reduce code duplication. The changes seem well-structured and aim to improve test coverage and code maintainability.

Summary of Findings

  • Fatal error in VertexAI initialization: The vertexAI method in VertexAI.swift uses fatalError if no default Firebase app is found. This could crash the app in unexpected scenarios. Consider using a more graceful error handling mechanism, especially in a public API.
  • TODO comments in integration tests: The integration tests contain TODO comments indicating potential areas for improvement, such as moving helper functions to a utilities folder. Addressing these would improve code organization and reusability.
  • Token count accuracy in integration tests: The integration tests use a tokenCountAccuracy variable to account for slight variations in token counts. While this addresses potential flakiness, it might mask underlying issues with tokenization. Consider investigating the source of these variations and addressing them directly.

Merge Readiness

The pull request introduces valuable integration tests and refactors existing code. However, the potential for app crashes due to fatalError in VertexAI.swift should be addressed before merging. Additionally, addressing the TODO comments and investigating token count variations would further improve the quality of the code. I am unable to approve this pull request, and other reviewers should approve this code before merging.

@andrewheard andrewheard marked this pull request as ready for review March 7, 2025 01:35
@andrewheard andrewheard requested a review from paulb777 March 7, 2025 01:35
@andrewheard andrewheard merged commit 0fcadb9 into main Mar 7, 2025
40 checks passed
@andrewheard andrewheard deleted the ah/vertex-dev-integration branch March 7, 2025 15:46
@firebase firebase locked and limited conversation to collaborators Apr 7, 2025
# for free to subscribe to this conversation on GitHub. Already have an account? #.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants