Remove deprecated APIs and internalize response constructors in firebase-ai - #8563
Remove deprecated APIs and internalize response constructors in firebase-ai#8563VinayGuthal wants to merge 3 commits into
Conversation
📝 PRs merging into main branchOur 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. |
|
Did you forget to add a changelog entry? (Add the 'no-changelog' label to the PR or 'NO_RELEASE_CHANGE' to the description to silence this warning.) |
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 the 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 counterproductive. 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 cleans up the API by removing deprecated classes and methods (such as the vertexAI backend, MediaData, Voices, and GroundingAttribution), making several constructors internal to prevent external instantiation, and renaming internal "Bidi" components to "Live". The review feedback suggests several Kotlin-specific improvements, such as declaring DownloadStatus as a sealed class and converting stateless classes like DownloadCompleted and LiveServerSetupComplete into objects. It also recommends updating outdated variable names and comments that still refer to 'Vertex AI' to reflect the transition to 'Agent Platform'.
| /** An abstract class representing the status of an on-device model download operation. */ | ||
| @PublicPreviewAPI | ||
| public abstract class DownloadStatus { | ||
| public abstract class DownloadStatus internal constructor() { |
There was a problem hiding this comment.
Since DownloadStatus has an internal constructor() and cannot be subclassed outside of this module, it is effectively sealed. Declaring it as a sealed class instead of an abstract class is more idiomatic in Kotlin and enables exhaustive when expressions for Kotlin consumers.
| /** An abstract class representing the status of an on-device model download operation. */ | |
| @PublicPreviewAPI | |
| public abstract class DownloadStatus { | |
| public abstract class DownloadStatus internal constructor() { | |
| /** A sealed class representing the status of an on-device model download operation. */ | |
| @PublicPreviewAPI | |
| public sealed class DownloadStatus internal constructor() { |
| /** Represents when a download has successfully completed. */ | ||
| public class DownloadCompleted : DownloadStatus() { | ||
| public class DownloadCompleted internal constructor() : DownloadStatus() { | ||
| override fun equals(other: Any?): Boolean = other is DownloadCompleted | ||
| override fun hashCode(): Int = javaClass.hashCode() | ||
| } |
There was a problem hiding this comment.
Since DownloadCompleted is stateless and its constructor is now internal, it is more idiomatic and efficient to define it as an object instead of a class. This avoids unnecessary allocations and removes the need for manual equals and hashCode overrides.
/** Represents when a download has successfully completed. */
public object DownloadCompleted : DownloadStatus()| public class LiveServerSetupComplete internal constructor() : LiveServerMessage { | ||
| @Serializable | ||
| internal data class Internal(val setupComplete: JsonObject) : InternalLiveServerMessage { | ||
| override fun toPublic() = LiveServerSetupComplete() |
There was a problem hiding this comment.
Since LiveServerSetupComplete is stateless and its constructor is now internal, it is more idiomatic and efficient to define it as an object instead of a class. This avoids unnecessary allocations.
| public class LiveServerSetupComplete internal constructor() : LiveServerMessage { | |
| @Serializable | |
| internal data class Internal(val setupComplete: JsonObject) : InternalLiveServerMessage { | |
| override fun toPublic() = LiveServerSetupComplete() | |
| public object LiveServerSetupComplete : LiveServerMessage { | |
| @Serializable | |
| internal data class Internal(val setupComplete: JsonObject) : InternalLiveServerMessage { | |
| override fun toPublic() = LiveServerSetupComplete |
|
|
||
| public val vertexAIFlashModel: GenerativeModel by lazy { | ||
| getGenerativeModel(GenerativeBackend.vertexAI("global"), "gemini-3.5-flash") | ||
| getGenerativeModel(GenerativeBackend.agentPlatform("global"), "gemini-3.5-flash") |
There was a problem hiding this comment.
Since the backend has been changed from vertexAI to agentPlatform, consider renaming the variables vertexAIFlashModel, vertexAIFlashLiteModel, and vertexAI3_5FlashModel to use agentPlatform (e.g., agentPlatformFlashModel) to avoid confusion and keep the naming consistent with the actual backend being used.
| } | ||
| public val vertexAITemplateModel: TemplateGenerativeModel by lazy { | ||
| FirebaseAI.getInstance(app(), GenerativeBackend.vertexAI()).templateGenerativeModel() | ||
| FirebaseAI.getInstance(app(), GenerativeBackend.agentPlatform()).templateGenerativeModel() |
| // Initialize the Vertex AI Gemini API backend service. | ||
| TemplateGenerativeModel templateModel = | ||
| FirebaseAI.getInstance(GenerativeBackend.vertexAI("global")).templateGenerativeModel(); | ||
| FirebaseAI.getInstance(GenerativeBackend.agentPlatform("global")).templateGenerativeModel(); |
| // Create a `TemplateGenerativeModel` instance. | ||
| TemplateGenerativeModel model = | ||
| FirebaseAI.getInstance(GenerativeBackend.vertexAI("global")).templateGenerativeModel(); | ||
| FirebaseAI.getInstance(GenerativeBackend.agentPlatform("global")).templateGenerativeModel(); |
Cleans up the firebase-ai public API surface by removing deprecated classes, methods, and properties, and marking constructors of SDK-emitted response/status models as internal.
Removed Deprecated Classes & APIs
Restricted Constructors on Output/Status Types to internal
Tests & API Signatures updated
Removed VERTEX_AI and used AgentPlatform instead.