-
Notifications
You must be signed in to change notification settings - Fork 616
Add support for GoogleAI to firebase-vertexai #6772
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
Closed
Closed
Changes from all commits
Commits
Show all changes
17 commits
Select commit
Hold shift + click to select a range
38552da
Add support for GoogleAI to firebase-vertexai
3ca637c
Align with API design
184d6fe
Merge branch 'main' into davidmotson.google_ai
2885e13
add copyright and fix tests
fa68048
add first devapi tests
0ec2945
update to new API
3947b8e
update API for ease of use
19b8f73
initial fixes for comments
10eb66c
add documentation and custom uri for imagen in google-ai
22953ed
update MultiResourceComponent to cache googleAI object
315dd48
update api.txt
48837cf
Merge branch 'main' into davidmotson.google_ai
davidmotson 71d6f0a
update tests
a6d465d
fixes for comments
6fded91
update api.txt
d7665c3
HarmBlockMethod should now throw if the backend is googleAI
36d7741
Merge branch 'main' into davidmotson.google_ai
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
62 changes: 62 additions & 0 deletions
62
firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/FirebaseGenAI.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,62 @@ | ||
/* | ||
* Copyright 2025 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.google.firebase.vertexai | ||
|
||
import com.google.firebase.Firebase | ||
import com.google.firebase.FirebaseApp | ||
import com.google.firebase.app | ||
|
||
/** Entry point for all Firebase Generative AI functionality. */ | ||
public class FirebaseGenAI { | ||
|
||
/** | ||
* Returns the [FirebaseVertexAI] instance for the provided [FirebaseApp] and [location]. | ||
* | ||
* @param location location identifier, defaults to `us-central1`; see available | ||
* [Vertex AI regions](https://firebase.google.com/docs/vertex-ai/locations?platform=android#available-locations) | ||
* . | ||
*/ | ||
@JvmOverloads | ||
public fun vertexAI( | ||
app: FirebaseApp = Firebase.app, | ||
location: String = "us-central1", | ||
): FirebaseVertexAI = FirebaseVertexAI.getInstance(app, location) | ||
|
||
/** Returns the [FirebaseGoogleAI] instance for the provided [FirebaseApp]. */ | ||
@JvmOverloads | ||
public fun googleAI(app: FirebaseApp = Firebase.app): FirebaseGoogleAI = | ||
FirebaseGoogleAI.getInstance(app) | ||
|
||
/** Returns the [FirebaseGoogleAI] instance of the default [FirebaseApp]. */ | ||
public val googleAI: FirebaseGoogleAI | ||
get() = FirebaseGoogleAI.instance | ||
|
||
/** Returns the [FirebaseVertexAI] instance of the default [FirebaseApp]. */ | ||
public val vertexAI: FirebaseVertexAI | ||
get() = FirebaseVertexAI.instance | ||
|
||
internal companion object { | ||
internal val INSTANCE = FirebaseGenAI() | ||
} | ||
} | ||
|
||
/** Returns the [FirebaseGenAI] instance. */ | ||
public val Firebase.genAI: FirebaseGenAI | ||
get() = FirebaseGenAI() | ||
|
||
/** Returns the [FirebaseGenAI] instance. */ | ||
public fun Firebase.genAI(): FirebaseGenAI = FirebaseGenAI.INSTANCE |
99 changes: 99 additions & 0 deletions
99
firebase-vertexai/src/main/kotlin/com/google/firebase/vertexai/FirebaseGoogleAI.kt
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
/* | ||
* Copyright 2025 Google LLC | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
*/ | ||
|
||
package com.google.firebase.vertexai | ||
|
||
import com.google.firebase.Firebase | ||
import com.google.firebase.FirebaseApp | ||
import com.google.firebase.app | ||
import com.google.firebase.vertexai.type.Content | ||
import com.google.firebase.vertexai.type.GenerationConfig | ||
import com.google.firebase.vertexai.type.ImagenGenerationConfig | ||
import com.google.firebase.vertexai.type.ImagenSafetySettings | ||
import com.google.firebase.vertexai.type.PublicPreviewAPI | ||
import com.google.firebase.vertexai.type.RequestOptions | ||
import com.google.firebase.vertexai.type.SafetySetting | ||
import com.google.firebase.vertexai.type.Tool | ||
import com.google.firebase.vertexai.type.ToolConfig | ||
|
||
/** Entry point for all _Google AI_ functionality. */ | ||
public class FirebaseGoogleAI internal constructor(private val proxy: FirebaseVertexAI) { | ||
davidmotson marked this conversation as resolved.
Show resolved
Hide resolved
rlazo marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/** | ||
* Instantiates a new [GenerativeModel] given the provided parameters. | ||
* | ||
* @param modelName The name of the model to use, for example `"gemini-2.0-pro"`. | ||
* @param generationConfig The configuration parameters to use for content generation. | ||
* @param safetySettings The safety bounds the model will abide to during content generation. | ||
* @param tools A list of [Tool]s the model may use to generate content. | ||
* @param toolConfig The [ToolConfig] that defines how the model handles the tools provided. | ||
* @param systemInstruction [Content] instructions that direct the model to behave a certain way. | ||
* Currently only text content is supported. | ||
* @param requestOptions Configuration options for sending requests to the backend. | ||
* @return The initialized [GenerativeModel] instance. | ||
*/ | ||
@JvmOverloads | ||
public fun generativeModel( | ||
modelName: String, | ||
generationConfig: GenerationConfig? = null, | ||
safetySettings: List<SafetySetting>? = null, | ||
tools: List<Tool>? = null, | ||
toolConfig: ToolConfig? = null, | ||
systemInstruction: Content? = null, | ||
requestOptions: RequestOptions = RequestOptions(), | ||
): GenerativeModel = | ||
proxy.generativeModel( | ||
modelName, | ||
generationConfig, | ||
safetySettings, | ||
tools, | ||
toolConfig, | ||
systemInstruction, | ||
requestOptions, | ||
) | ||
|
||
/** | ||
* Instantiates a new [ImagenModel] given the provided parameters. | ||
* | ||
* @param modelName The name of the model to use, for example `"imagen-3.0-generate-001"`. | ||
* @param generationConfig The configuration parameters to use for image generation. | ||
* @param safetySettings The safety bounds the model will abide by during image generation. | ||
* @param requestOptions Configuration options for sending requests to the backend. | ||
* @return The initialized [ImagenModel] instance. | ||
*/ | ||
@JvmOverloads | ||
@PublicPreviewAPI | ||
public fun imagenModel( | ||
modelName: String, | ||
generationConfig: ImagenGenerationConfig? = null, | ||
safetySettings: ImagenSafetySettings? = null, | ||
requestOptions: RequestOptions = RequestOptions(), | ||
): ImagenModel = proxy.imagenModel(modelName, generationConfig, safetySettings, requestOptions) | ||
|
||
public companion object { | ||
/** The [FirebaseGoogleAI] instance for the default [FirebaseApp] */ | ||
@JvmStatic | ||
public val instance: FirebaseGoogleAI | ||
get() = getInstance() | ||
|
||
/** Returns the [FirebaseGoogleAI] instance for the provided [FirebaseApp]. */ | ||
@JvmStatic | ||
public fun getInstance(app: FirebaseApp = Firebase.app): FirebaseGoogleAI { | ||
val multiResourceComponent = app[FirebaseVertexAIMultiResourceComponent::class.java] | ||
return multiResourceComponent.getGoogleAI() | ||
} | ||
davidmotson marked this conversation as resolved.
Show resolved
Hide resolved
|
||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.