Skip to content

Commit fa9fd59

Browse files
committed
add snippets
1 parent ab4a920 commit fa9fd59

File tree

1 file changed

+19
-3
lines changed
  • Node/quickstarts/genkit-helloworld/functions

1 file changed

+19
-3
lines changed

Node/quickstarts/genkit-helloworld/functions/index.js

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/**
2-
* Copyright 2022 Google LLC
2+
* Copyright 2025 Google LLC
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -14,19 +14,27 @@
1414
* limitations under the License.
1515
*/
1616

17+
// [START complete-example]
1718
// [START imports]
1819
// Dependencies for callable functions.
1920
const {onCallGenkit} = require("firebase-functions/v2/https");
21+
// [START import-params]
2022
const {defineSecret} = require("firebase-functions/params");
23+
// [END import-params]
2124

25+
// [START import-genkit]
2226
// Dependencies for Genkit
2327
const {gemini15Flash, googleAI} = require("@genkit-ai/googleai");
2428
const {genkit, z} = require("genkit");
29+
// [END import-genkit]
2530
// [END imports]
2631

32+
// [START define-secret]
2733
// Store the Gemini API key in Cloud Secret Manager
2834
const apiKey = defineSecret("GOOGLE_GENAI_API_KEY");
35+
// [END define-secret]
2936

37+
// [START flow]
3038
const ai = genkit({
3139
plugins: [googleAI()],
3240
model: gemini15Flash,
@@ -52,13 +60,21 @@ const jokeTeller = ai.defineFlow({
5260
return (await aiResponse).text;
5361
},
5462
);
63+
// [END flow]
5564

65+
// [START trigger]
5666
exports.tellJoke = onCallGenkit({
67+
// [START bind-secrets]
5768
// bind the Gemini API key secret parameter to the function
5869
secrets: [apiKey],
70+
// [END bind-secrets]
71+
// [START auth-policy]
72+
// protect your endpoint with authPolicy
73+
authPolicy: (auth) => !!auth && auth.token.email_verified,
74+
// [END auth-policy]
5975
},
6076
// pass in the genkit flow
6177
jokeTeller,
6278
);
63-
64-
79+
// [END trigger]
80+
// [END complete-example]

0 commit comments

Comments
 (0)