genkit_firebase_ai 0.3.0
genkit_firebase_ai: ^0.3.0 copied to clipboard
Firebase AI plugin for Genkit Dart.
// Copyright 2026 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.
/// Calls Gemini from a Flutter app through Firebase AI Logic.
///
/// Firebase must be initialized first (normally with the `firebase_options.dart`
/// generated by `flutterfire configure`); see the package README and
/// `testapps/firebase_ai` for a complete app.
library;
import 'package:firebase_core/firebase_core.dart';
import 'package:flutter/widgets.dart';
import 'package:genkit/genkit.dart';
import 'package:genkit_firebase_ai/genkit_firebase_ai.dart';
Future<void> main() async {
// Firebase talks to the platform through the Flutter binding.
WidgetsFlutterBinding.ensureInitialized();
await Firebase.initializeApp();
final ai = Genkit(plugins: [firebaseAI()]);
final response = await ai.generate(
model: firebaseAI.gemini('gemini-flash-latest'),
prompt: 'Tell me a joke about a developer.',
);
print(response.text);
// Structured output: the response is parsed into the schema's type.
final structured = await ai.generate(
model: firebaseAI.gemini('gemini-flash-latest'),
prompt: 'List three primary colors.',
outputSchema: .list(.string()),
);
print(structured.output);
}