Vertex AI for Firebase: Bringing Serverless AI to Your Mobile and Web Apps

Google's Vertex AI, renowned for building scalable generative AI applications, now integrates with Firebase, offering a suite of client SDKs for Swift, Kotlin, Java, Dart, and JavaScript. This integration allows developers to harness the power of AI without the need for backend infrastructure.

Vertex AI for Firebase: A New Era of AI Development

Effortless Onboarding

Getting started with the Vertex AI Gemini API through Firebase is seamless. The Firebase console's new “Build with the Gemini API” page guides you through enrollment in the pay-as-you-go plan, activates necessary services, and generates a Firebase configuration file for your app. With these steps, you're just a few lines of code away from using Gemini models in your app.

Access to the Vertex AI Gemini API from Your Client

Firebase provides a gateway to the Vertex AI Gemini API, enabling direct use of Gemini models via Kotlin/Java, Swift, Dart, and JavaScript SDKs. These SDKs allow granular control over the model’s behavior with parameters and safety settings for response generation and prompting.

Example using Swift:

let vertex = VertexAI.vertexAI()
let model = vertex.generativeModel(modelName: "gemini-1.5-pro-preview-0409", systemInstruction: "You write inspirational quotes.")
let image = UIImage(...)
let response = try await model.generateContent(image, "What quote should I put on this poster?")
if let text = response.text {
    print(text)
}

Example using Kotlin:

val generativeModel = Firebase.vertexAI.generativeModel("gemini-1.5-pro-preview-0409")
val prompt = "Write a story about a magic backpack."
var response = ""
generativeModel.generateContentStream(prompt).collect { chunk ->
    print(chunk.text)
    response += chunk.text
}

Use Firebase App Check to Protect the Gemini API

To prevent unauthorized access, Vertex AI for Firebase SDKs are integrated with Firebase App Check. This ensures that only legitimate requests from genuine apps and devices are processed, safeguarding your app from potential abuse.

Streamline File Uploads via Cloud Storage for Firebase

Cloud Storage for Firebase allows direct file uploads for multimodal AI prompts, ensuring efficient handling even with unreliable network conditions. Firebase Security Rules provide granular control over file access, ensuring security.

Example using JavaScript:

const firebaseConfig = { /* Firebase configuration */ };
const firebaseApp = initializeApp(firebaseConfig);
const vertexAI = getVertexAI(firebaseApp);
const model = getGenerativeModel(vertexAI, { model: "gemini-1.5-pro-preview-0409" });
const prompt = "What's in this picture?";
const imagePart = { fileData: { mimeType: 'image/jpeg', fileUri: "gs://bucket-name/path/image.jpg" }};
const result = await model.generateContent([prompt, imagePart]);
console.log(result.response.text());

Seamless Model and Prompt Updates with Firebase Remote Config

Firebase Remote Config allows you to adjust your app’s behavior on the fly, without requiring users to download updates. Manage your model and prompts through default values, and use the Firebase console to change these defaults for all users or target specific groups.

Example using Dart:

await Firebase.initializeApp();
final remoteConfig = FirebaseRemoteConfig.instance;
final prompt = remoteConfig.getString('promptText');
final geminiModel = remoteConfig.getString('geminiModel');
final model = FirebaseVertexAI.instance.generativeModel(model: geminiModel);
const imagePart = { fileData: { mimeType: 'image/jpeg', fileUri: 'gs://bucket-name/path/image.jpg' }};
const result = await model.generateContent([prompt, imagePart]);
print(result.response.text());

Get Started Now

  • Begin building your vision with our public preview
  • Prepare for the general availability release in Fall this year.
  • Explore our quick starts and detailed documentation

Your feedback is invaluable. Report bugs, request features, or contribute code directly to our Firebase SDKs’ repositories. Participate in Firebase’s UserVoice to share your ideas and vote on existing ones.

We can't wait to see what you build with Vertex AI for Firebase!

Next Post Previous Post
No Comment
Add Comment
comment url