forked from firebase/firebase-functions-dart
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathexample.dart
More file actions
37 lines (34 loc) · 1.15 KB
/
example.dart
File metadata and controls
37 lines (34 loc) · 1.15 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
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']},
);
});
}