-
Notifications
You must be signed in to change notification settings - Fork 2
Add onCallGenkit extension
#26
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
Draft
mosuem
wants to merge
14
commits into
invertase:main
Choose a base branch
from
mosuem:addOnCallGenkit
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
0401c96
initial
mosuem 4263315
sdk
mosuem f510654
add example
mosuem 41f85e3
remove unused deps
mosuem 02c51cb
newline
mosuem c7dc03b
add readme
mosuem 18fa4f4
fix
mosuem 7f743bb
add more readme
mosuem d3c06e3
fixes
mosuem 1986765
add contextprovider
mosuem 0703d9d
add contextprovider
mosuem 0a884bd
add lints
mosuem 8c3e8c7
add ignore
mosuem 519f708
fix cl
mosuem 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
| 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 |
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,3 @@ | ||
| ## 0.1.0 | ||
|
|
||
| - Initial version. |
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,3 @@ | ||
| Extension on firebase functions to use genkit. | ||
|
|
||
| Not included in firebase functions itself for more flexibility and reduced deps. |
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,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 |
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 @@ | ||
| Sample of creating a genkit flow and setting it up for an http trigger. |
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,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']}, | ||
| ); | ||
| }); | ||
| } | ||
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,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 |
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 @@ | ||
| export 'src/firebase_functions_genkit_base.dart'; |
37 changes: 37 additions & 0 deletions
37
firebase_functions_genkit/lib/src/firebase_functions_genkit_base.dart
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,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)), | ||
| ); | ||
| } | ||
| }); | ||
| } | ||
| } |
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,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: | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you can depend directly on https://pub.dev/packages/genkit/versions/0.10.0-dev.11 |
||
| 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 | ||
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.