Skip to content

Commit 2b23cb1

Browse files
committed
refine comments
1 parent 5d6ad35 commit 2b23cb1

File tree

1 file changed

+13
-10
lines changed
  • Node/quickstarts/genkit-helloworld/functions

1 file changed

+13
-10
lines changed

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

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -24,14 +24,14 @@ const {defineSecret} = require("firebase-functions/params");
2424
// [END import-params]
2525

2626
// [START import-genkit]
27-
// Dependencies for Genkit
27+
// Dependencies for Genkit.
2828
const {gemini15Flash, googleAI} = require("@genkit-ai/googleai");
2929
const {genkit, z} = require("genkit");
3030
// [END import-genkit]
3131
// [END imports]
3232

3333
// [START define-secret]
34-
// Store the Gemini API key in Cloud Secret Manager
34+
// Store the Gemini API key in Cloud Secret Manager.
3535
const apiKey = defineSecret("GOOGLE_GENAI_API_KEY");
3636
// [END define-secret]
3737

@@ -48,16 +48,19 @@ const jokeTeller = ai.defineFlow({
4848
streamSchema: z.string(),
4949
}, async (jokeType = "knock-knock", response) => {
5050
const prompt = `Tell me a ${jokeType} joke.`;
51+
52+
// Call the `generateStream()` method to
53+
// receive the `stream` async iterable.
5154
const {stream, response: aiResponse} = ai.generateStream(prompt);
5255

53-
// Loop over the `stream` async iterable to
54-
// send new words of the AI response
55-
// to the client as they're generated
56+
// Send new words of the generative AI response
57+
// to the client as they're generated.
5658
for await (const chunk of stream) {
5759
response.sendChunk(chunk.text);
5860
}
5961

60-
// Return the full response
62+
// Return the full generative AI response
63+
// to clients that may not support streaming.
6164
return (await aiResponse).text;
6265
},
6366
);
@@ -66,15 +69,15 @@ const jokeTeller = ai.defineFlow({
6669
// [START trigger]
6770
exports.tellJoke = onCallGenkit({
6871
// [START bind-secrets]
69-
// bind the Gemini API key secret parameter to the function
72+
// Bind the Gemini API key secret parameter to the function.
7073
secrets: [apiKey],
7174
// [END bind-secrets]
7275
// [START auth-policy]
73-
// protect your endpoint with authPolicy
74-
authPolicy: (auth) => !!auth?.token.email_verified,
76+
// Protect your endpoint with authPolicy.
77+
// authPolicy: (auth) => !!auth?.token.email_verified,
7578
// [END auth-policy]
7679
},
77-
// pass in the genkit flow
80+
// Pass in the genkit flow.
7881
jokeTeller,
7982
);
8083
// [END trigger]

0 commit comments

Comments
 (0)