Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions firebase_functions_genkit/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# https://dart.dev/guides/libraries/private-files
# Created by `dart pub`
.dart_tool/

# Avoid committing pubspec.lock for library packages; see
# https://dart.dev/guides/libraries/private-files#pubspeclock.
pubspec.lock
3 changes: 3 additions & 0 deletions firebase_functions_genkit/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
## 0.1.0

- Initial version.
3 changes: 3 additions & 0 deletions firebase_functions_genkit/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Extension on firebase functions to use genkit.

Not included in firebase functions itself for more flexibility and reduced deps.
10 changes: 10 additions & 0 deletions firebase_functions_genkit/analysis_options.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
include: package:dart_flutter_team_lints/analysis_options.yaml

linter:
rules:
- prefer_final_locals
- unnecessary_parenthesis
- prefer_expression_function_bodies
- document_ignores
- parameter_assignments
- prefer_final_in_for_each
1 change: 1 addition & 0 deletions firebase_functions_genkit/example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Sample of creating a genkit flow and setting it up for an http trigger.
37 changes: 37 additions & 0 deletions firebase_functions_genkit/example/bin/example.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import 'package:firebase_functions/firebase_functions.dart';
import 'package:firebase_functions_genkit/firebase_functions_genkit.dart';
import 'package:genkit/genkit.dart';
import 'package:genkit_google_genai/genkit_google_genai.dart';
import 'package:schemantic/schemantic.dart';

const name = 'jokeTeller';

void main(List<String> args) {
final gemini = googleAI();
final ai = Genkit(plugins: [gemini]);
final flow = ai.defineFlow(
name: name,
inputSchema: stringSchema(),
outputSchema: stringSchema(),
streamSchema: stringSchema(),
fn: (jokeType, context) async {
final prompt = 'Tell me a $jokeType joke.';
/// gemini.model does not have a generic type
// ignore: inference_failure_on_function_invocation
final stream = ai.generateStream(
model: gemini.model('gemini-2.5-flash'),
prompt: prompt,
);
await stream.forEach((chunk) => context.sendChunk(chunk.text));
return stream.result.text;
},
);

fireUp(args, (firebase) {
firebase.https.onCallGenkit(
name: name,
flow: flow,
contextProvider: (context) => {'auth': context.auth?.token?['email']},
Copy link

Choose a reason for hiding this comment

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

Suggested change
contextProvider: (context) => {'auth': context.auth?.token?['email']},
contextProvider: (request) => {'auth': request.auth?.token?['email']},

);
});
}
20 changes: 20 additions & 0 deletions firebase_functions_genkit/example/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: example

environment:
sdk: ^3.11.0

dependencies:
firebase_functions:
path: ../../
firebase_functions_genkit:
path: ../
genkit: ^0.10.0-dev.8
genkit_google_genai: ^0.0.1-dev.8
schemantic: ^0.0.1-dev.9

dependency_overrides:
analyzer: ^10.0.1
dart_firebase_admin: ^0.4.1
genkit: ^0.10.0-dev.2
googleapis_auth: ^1.3.0
protobuf: ^6.0.0
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export 'src/firebase_functions_genkit_base.dart';
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import 'package:firebase_functions/firebase_functions.dart';
import 'package:genkit/genkit.dart';

/// It's experimental as we can't semver package:meta
// ignore: experimental_member_use
import 'package:meta/meta.dart' show mustBeConst;

extension GenkitExt on HttpsNamespace {
void onCallGenkit<Output extends Object, Schema, Init>({
// Must repeat the name
// ignore: experimental_member_use
@mustBeConst required String name,
required Flow<Object?, Output, Schema, Init> flow,

/// It's experimental as we can't semver package:meta
// ignore: experimental_member_use
@mustBeConst CallableOptions? options = const CallableOptions(),
Map<String, dynamic> Function(CallableRequest<Object?>)? contextProvider,
}) {
/// This is why we restate the name in the params above
// ignore: non_const_argument_for_const_parameter
onCall(name: name, options: options, (request, response) async {
if (request.acceptsStreaming) {
final actionStream = flow.stream(
request.data,
context: contextProvider?.call(request),
);
await actionStream.forEach((chunk) => response.sendChunk(chunk));
return CallableResult(actionStream.result);
} else {
return CallableResult(
await flow.run(request.data, context: contextProvider?.call(request)),
);
}
});
}
}
25 changes: 25 additions & 0 deletions firebase_functions_genkit/pubspec.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
name: firebase_functions_genkit
description: A starting point for Dart libraries or applications.
version: 0.1.0
repository: https://github.com/invertase/firebase-functions-dart

publish_to: none

environment:
sdk: ^3.10.0

dependencies:
firebase_functions:
path: ../
genkit:
Copy link

Choose a reason for hiding this comment

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

git:
url: https://github.com/genkit-ai/genkit-dart/
path: packages/genkit
meta: ^1.18.1

dependency_overrides:
analyzer: ^10.0.1
protobuf: ^6.0.0

dev_dependencies:
dart_flutter_team_lints: ^3.5.2
Loading