Skip to content

Add Firebase AI SDK implementation #14774

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 4 commits into from
Apr 25, 2025
Merged

Add Firebase AI SDK implementation #14774

merged 4 commits into from
Apr 25, 2025

Conversation

andrewheard
Copy link
Contributor

@andrewheard andrewheard commented Apr 25, 2025

Added the new Firebase AI SDK, which provides support for the Gemini API using both Google AI (Developer API) and Vertex AI.

#no-changelog

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

@google-oss-bot

This comment was marked as outdated.

Copy link
Contributor

Summary of Changes

This pull request introduces the Firebase AI SDK implementation, providing access to Gemini models directly from apps. It includes a new FirebaseAI.podspec file, the core FirebaseAI.swift file, and a Backend.swift file to represent available backend APIs. The changes also involve updating several test files to use the new FirebaseAI SDK instead of the previous FirebaseVertexAI SDK. Additionally, snippet tests and utilities are added to verify code snippet compilation.

Highlights

  • Firebase AI SDK Implementation: Adds the core implementation of the Firebase AI SDK, enabling access to Gemini models.
  • Podspec Creation: Creates a FirebaseAI.podspec file to define the pod for the Firebase AI SDK.
  • Backend API Configuration: Introduces Backend.swift to configure backend APIs for the Firebase AI SDK, including Vertex AI and Google Developer API.
  • Test File Updates: Updates integration and unit test files to utilize the new FirebaseAI SDK.
  • Snippet Tests and Utilities: Adds snippet tests and utilities to ensure the compilation of code snippets in documentation.

Changelog

Click here to see the changelog
  • FirebaseAI.podspec
    • Created a new podspec file for the Firebase AI SDK.
    • Defined the pod's name, version, summary, description, homepage, license, authors, source, social media URL, deployment targets, cocoapods version, source files, swift version, frameworks, dependencies, and test specifications.
  • FirebaseAI/Sources/FirebaseAI.swift
    • Implemented the core FirebaseAI class with methods to initialize generative and imagen models.
    • Added logic to handle different backend APIs (Vertex AI and Google Developer API).
    • Included internal component for Firebase user agent registration.
    • Implemented instance management to avoid race conditions.
    • Added fatal error checks for missing project ID and API key.
    • Added methods to construct model resource names for Vertex AI and Developer API services.
  • FirebaseAI/Sources/Types/Public/Backend.swift
    • Created Backend struct to represent available backend APIs.
    • Added static methods to initialize Backend for Vertex AI and Google AI.
    • Included properties for apiConfig and location.
  • FirebaseAI/Tests/TestApp/Tests/Integration/CountTokensIntegrationTests.swift
    • Updated import statements to use FirebaseAI instead of FirebaseVertexAI.
    • Modified code to use FirebaseAI.componentInstance instead of VertexAI.componentInstance.
  • FirebaseAI/Tests/TestApp/Tests/Integration/GenerateContentIntegrationTests.swift
    • Updated import statements to use FirebaseAI instead of FirebaseVertexAI.
    • Modified code to use FirebaseAI.componentInstance instead of VertexAI.componentInstance.
  • FirebaseAI/Tests/TestApp/Tests/Integration/ImagenIntegrationTests.swift
    • Updated import statements to use FirebaseAI instead of FirebaseVertexAI.
    • Modified code to use FirebaseAI.firebaseAI(backend: .vertexAI()) instead of VertexAI.vertexAI().
  • FirebaseAI/Tests/TestApp/Tests/Integration/IntegrationTests.swift
    • Updated import statements to use FirebaseAI instead of FirebaseVertexAI.
    • Modified code to use FirebaseAI.firebaseAI(backend: .vertexAI()) instead of VertexAI.vertexAI().
  • FirebaseAI/Tests/TestApp/Tests/SchemaTests.swift
    • Updated import statements to use FirebaseAI instead of FirebaseVertexAI.
    • Modified code to use FirebaseAI.componentInstance instead of VertexAI.componentInstance.
  • FirebaseAI/Tests/TestApp/Tests/Utilities/InstanceConfig.swift
    • Updated import statements to use FirebaseAI instead of FirebaseVertexAI.
    • Modified code to use FirebaseAI.createInstance instead of VertexAI.vertexAI.
  • FirebaseAI/Tests/Unit/APITests.swift
    • Created new unit test file APITests.swift to test public APIs of FirebaseAI.
  • FirebaseAI/Tests/Unit/ChatTests.swift
    • Updated import statements to use FirebaseAI instead of FirebaseVertexAI.
    • Modified code to use FirebaseAI.defaultVertexAIAPIConfig instead of VertexAI.defaultVertexAIAPIConfig.
  • FirebaseAI/Tests/Unit/GenerationConfigTests.swift
    • Updated import statements to use FirebaseAI instead of FirebaseVertexAI.
  • FirebaseAI/Tests/Unit/GenerativeModelTests.swift
    • Updated import statements to use FirebaseAI instead of FirebaseVertexAI.
    • Modified code to use FirebaseAI.defaultVertexAIAPIConfig instead of VertexAI.defaultVertexAIAPIConfig.
  • FirebaseAI/Tests/Unit/JSONValueTests.swift
    • Updated import statements to use FirebaseAI instead of FirebaseVertexAI.
  • FirebaseAI/Tests/Unit/PartTests.swift
    • Updated import statements to use FirebaseAI instead of FirebaseVertexAI.
  • FirebaseAI/Tests/Unit/PartsRepresentableTests.swift
    • Updated import statements to use FirebaseAI instead of FirebaseVertexAI.
  • FirebaseAI/Tests/Unit/RequestOptionsTest.swift
    • Updated import statements to use FirebaseAI instead of FirebaseVertexAI.
  • FirebaseAI/Tests/Unit/Snippets/ChatSnippets.swift
    • Created new snippet test file ChatSnippets.swift to test chat functionalities.
  • FirebaseAI/Tests/Unit/Snippets/CloudStorageSnippets.swift
    • Created new snippet test file CloudStorageSnippets.swift to test cloud storage functionalities.
  • FirebaseAI/Tests/Unit/Snippets/FirebaseAppSnippetsUtil.swift
    • Created new utility file FirebaseAppSnippetsUtil.swift to configure and delete Firebase apps for snippet tests.
  • FirebaseAI/Tests/Unit/Snippets/FunctionCallingSnippets.swift
    • Created new snippet test file FunctionCallingSnippets.swift to test function calling functionalities.
  • FirebaseAI/Tests/Unit/Snippets/MultimodalSnippets.swift
    • Created new snippet test file MultimodalSnippets.swift to test multimodal functionalities.
  • FirebaseAI/Tests/Unit/Snippets/README.md
    • Created new README file for snippet tests.
  • FirebaseAI/Tests/Unit/Snippets/StructuredOutputSnippets.swift
    • Created new snippet test file StructuredOutputSnippets.swift to test structured output functionalities.
  • FirebaseAI/Tests/Unit/Snippets/TextSnippets.swift
    • Created new snippet test file TextSnippets.swift to test text functionalities.
  • FirebaseAI/Tests/Unit/TestUtilities/BundleTestUtil.swift
    • Created new utility file BundleTestUtil.swift to handle bundle differences between SPM and CocoaPods tests.
  • FirebaseAI/Tests/Unit/Types/BackendTests.swift
    • Created new unit test file BackendTests.swift to test backend API configurations.
  • FirebaseAI/Tests/Unit/Types/Imagen/ImageGenerationInstanceTests.swift
    • Created new unit test file ImageGenerationInstanceTests.swift to test image generation instance.
  • FirebaseAI/Tests/Unit/Types/Imagen/ImageGenerationOutputOptionsTests.swift
    • Created new unit test file ImageGenerationOutputOptionsTests.swift to test image generation output options.
  • FirebaseAI/Tests/Unit/Types/Imagen/ImageGenerationParametersTests.swift
    • Created new unit test file ImageGenerationParametersTests.swift to test image generation parameters.
  • FirebaseAI/Tests/Unit/Types/Imagen/ImagenGCSImageTests.swift
    • Created new unit test file ImagenGCSImageTests.swift to test Google Cloud Storage image handling.
  • FirebaseAI/Tests/Unit/Types/Imagen/ImagenGenerationRequestTests.swift
    • Created new unit test file ImagenGenerationRequestTests.swift to test image generation requests.
  • FirebaseAI/Tests/Unit/Types/Imagen/ImagenGenerationResponseTests.swift
    • Created new unit test file ImagenGenerationResponseTests.swift to test image generation responses.
  • FirebaseAI/Tests/Unit/Types/Imagen/ImagenInlineImageTests.swift
    • Created new unit test file ImagenInlineImageTests.swift to test inline image handling.
  • FirebaseAI/Tests/Unit/Types/Imagen/RAIFilteredReasonTests.swift
    • Created new unit test file RAIFilteredReasonTests.swift to test responsible AI filtered reasons.
  • FirebaseAI/Tests/Unit/Types/Internal/APIConfigTests.swift
    • Created new unit test file APIConfigTests.swift to test internal API configurations.
  • FirebaseAI/Tests/Unit/Types/Internal/Requests/CountTokensRequestTests.swift
    • Updated import statements to use FirebaseAI instead of FirebaseVertexAI.
    • Modified code to use FirebaseAI.defaultVertexAIAPIConfig instead of VertexAI.defaultVertexAIAPIConfig.
  • FirebaseAI/Tests/Unit/Types/ModalityTokenCountTests.swift
    • Updated import statements to use FirebaseAI instead of FirebaseVertexAI.
  • FirebaseAI/Tests/Unit/Types/ProtoDateTests.swift
    • Updated import statements to use FirebaseAI instead of FirebaseVertexAI.
  • FirebaseAI/Tests/Unit/Types/SchemaTests.swift
    • Updated import statements to use FirebaseAI instead of FirebaseVertexAI.
  • FirebaseAI/Tests/Unit/VertexComponentTests.swift
    • Updated import statements to use FirebaseAI instead of FirebaseVertexAI.
    • Modified code to use FirebaseAI.firebaseAI instead of VertexAI.vertexAI.
    • Modified code to use FirebaseAI.createInstance instead of VertexAI.vertexAI.
  • FirebaseVertexAI.podspec
    • Changed dependency from FirebaseAppCheckInterop, FirebaseAuthInterop, FirebaseCore, and FirebaseCoreExtension to FirebaseAI.
    • Removed resources from unit test spec.
  • FirebaseVertexAI/Sources/VertexAI.swift
    • Added @_exported import FirebaseAI to make FirebaseAI public.
    • Modified vertexAI method to use FirebaseAI.firebaseAI instead of creating a VertexAI instance directly.
    • Modified generativeModel and imagenModel methods to use the corresponding methods from firebaseAI.
    • Removed private properties and methods related to instance management and model resource name construction.
    • Added internal API to hold FirebaseAI instance.
  • Package.swift
    • Added FirebaseAI library and FirebaseVertexAI library.
    • Updated FirebaseVertexAI target dependencies to include FirebaseAI.
    • Updated FirebaseVertexAIUnit target dependencies to include FirebaseVertexAI.
    • Moved FirebaseVertexAI target and testTarget after FirebaseAI target and testTarget.
    • Updated FirebaseAIUnit target dependencies to include FirebaseStorage.
    • Updated FirebaseAIUnit target resources to copy vertexai mock responses and process resources.
    • Removed FirebaseVertexAI target and testTarget dependencies.
    • Added FirebaseAI target dependencies.
  • scripts/build.sh
    • Updated project path in RunXcodebuild command to 'FirebaseAI/Tests/TestApp/VertexAITestApp.xcodeproj'.
  • scripts/update_vertexai_responses.sh
    • Updated path to FirebaseAI tests unit directory.

Activity

  • The pull request was created by andrewheard.
  • gemini-code-assist[bot] provided a summary of the pull request.

@andrewheard andrewheard added this to the 11.13.0 - M164 milestone Apr 25, 2025
@andrewheard andrewheard marked this pull request as ready for review April 25, 2025 15:50
@andrewheard andrewheard requested a review from paulb777 April 25, 2025 15:50
Copy link
Member

@paulb777 paulb777 left a comment

Choose a reason for hiding this comment

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

LGTM - fine to address or not address my comment in a separate PR

OK to merge from command line if you want to keep individual commits in the history

@andrewheard andrewheard merged commit 15e6b03 into main Apr 25, 2025
92 of 104 checks passed
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.

3 participants