
Before you begin
- Labs create a Google Cloud project and resources for a fixed time
- Labs have a time limit and no pause feature. If you end the lab, you'll have to restart from the beginning.
- On the top left of your screen, click Start lab to begin
Setup your Genkit Project
/ 30
Add additional flows
/ 30
Define strongly typed prompts
/ 40
Firebase Genkit is an open source framework that helps you build, deploy, and monitor production-ready AI-powered apps.
Genkit is designed for app developers. It helps you to easily integrate powerful AI capabilities into your apps with familiar patterns and paradigms. The team behind Firebase builds it, and leverages their experience in building tools used by millions of developers worldwide. Genkit doesn't require a Firebase project and can be used in all Node.js environments, but it has integrations with Firebase and Google Cloud services through their own plugins.
Use Genkit to create apps that generate custom content, use semantic search, handle unstructured inputs, answer questions with your business data, autonomously make decisions, orchestrate tool calls, and much more.
This lab provides an introductory, hands-on experience with Firebase Genkit and the Gemini Flash foundation model. You create a simple application with two flows resolving two different prompts that accept input from the user.
You learn how to:
This Qwiklabs hands-on lab lets you do the lab activities yourself in a real cloud environment, not in a simulation or demo environment. It does so by giving you new, temporary credentials that you use to sign in and access Google Cloud for the duration of the lab.
To complete this lab, you need:
Click the Start Lab button. If you need to pay for the lab, a pop-up opens for you to select your payment method. On the left is a panel populated with the temporary credentials that you must use for this lab.
Copy the username, and then click Open Google Console. The lab spins up resources, and then opens another tab that shows the Choose an account page.
On the Choose an account page, click Use Another Account. The Sign in page opens.
Paste the username that you copied from the Connection Details panel. Then copy and paste the password.
After a few moments, the Cloud console opens in this tab.
Google Cloud Shell is a virtual machine that is loaded with development tools. It offers a persistent 5GB home directory and runs on the Google Cloud.
Google Cloud Shell provides command-line access to your Google Cloud resources.
In Cloud console, on the top right toolbar, click the Open Cloud Shell button.
Click Continue.
It takes a few moments to provision and connect to the environment. When you are connected, you are already authenticated, and the project is set to your PROJECT_ID. For example:
gcloud is the command-line tool for Google Cloud. It comes pre-installed on Cloud Shell and supports tab-completion.
Output:
Example output:
Output:
Example output:
In this task, you set up a node application to use Firebase Genkit, and configure it to access the Gemini model in Google Cloud's Vertex AI.
To initialize your environment for Google Cloud, run the following commands:
To authenticate to Google Cloud and set up credentials for your project and user, run the following command:
When prompted, type Y, and press ENTER.
To launch the Google Cloud sign-in flow, press Control (for Windows and Linux) or Command (for MacOS), and click the link in the terminal.
Click the student email address.
When you're prompted to continue, click Continue.
To let the Google Cloud SDK access your Google Account and agree to the terms, click Allow.
Your verification code is displayed in the browser tab.
Click Copy.
Back in the terminal, where it says Enter authorization code, paste the code and press ENTER.
You are now authenticated to Google Cloud.
Create a directory for your project, and initialize a new Node project:
This command creates a package.json
file in the genkit-intro
directory.
To install the Genkit CLI, run the following command:
To install the core Genkit packages and dependencies for your app, run the following command:
Create the application source folder and main file:
From the Cloud Shell menu, click Open Editor.
Open the genkit-intro/package.json
file, and review all the dependencies that were added with Genkit.
The dependency list should look similar to this:
Go to the src
folder, and open the src/index.ts
file. Add the following import library references to the index.ts
file:
After the import statements, add code to initialize and configure the genkit instance with the required plugin:
The Vertex AI plugin provides access to the Gemini models. The initialization code also sets the log level to debug for troubleshooting, and enables tracing and metrics for monitoring.
Define a flow for your application:
A flow to suggest menu items is created. The subject of the menu is passed in as a parameter and inserted into the prompt to the model. The model used is gemini20Flash001
with a temperature configuration setting of 1.
Add the following code to start the flow server, which exposes your flow as an HTTP endpoint:
To return to the command line, click Open Terminal.
To copy the package.json
and index.ts
files to a Cloud Storage Bucket, run the following commands:
Click Check my progress to verify the objectives.
The Genkit developer UI is a local web app that you can use to interact with models, retrievers, flows, and other actions in your Genkit project.
In this task, you use the Genkit developer UI to explore AI workflows, models, and parameters, and analyze traces for your app.
To launch the Genkit developer UI from your Cloud Shell terminal, run:
Press ENTER to continue.
Wait for the command to return the Genkit Developer UI URL in the output, and indicate the flow server is running, before continuing to the next step.
In the Web Preview menu (), click Change port.
For the Port Number, type 4000, and click Change and Preview.
This opens the Genkit developer UI in a separate tab in your browser.
To explore your predefined workflows, in the left panel click Flows, and then click menuSuggestionsFlow.
For Input JSON, type "Spanish" (include the quotation marks), and click Run.
The flow executes, and the model response is displayed in the UI.
To analyze the execution time and metadata associated with the flow, scroll to the bottom, and click View trace.
The trace shows the overall time taken by menuSuggestionFlow, and the subset of that time taken by the vertex/gemini-2.0-flash-001 model.
Click menuSuggestionFlow, and click Open in Flow Runner.
The flow can be run with another input. Experiment with a different string value in the input JSON field, for example, "Indian".
In the left panel, click Models. In the Config tab on the right, select vertexai/gemini-2.0-flash-001.
Several models available in Vertex AI are listed, including the Flash model used by your application. The Gemini 2.0 Flash 001 model is selected.
In the Config pane, modify the Temperature.
For Enter a message, set the input to:
Click Run.
The new prompt is submitted to the Gemini 2.0 Flash 001 model. A Greek menu item is returned.
Click View Trace.
In this case, the trace shows the input to and output from the Flash model.
To review traces of all the executed flows and models, in the left panel, click Traces.
You can click on any trace to review the input, output, and steps for that run.
To exit the Genkit UI, close your browser tab. Then, in Cloud Shell, type CTRL+C to stop the application.
In this task, you add additional flows to your project, explore them in the UI, and leverage the Genkit CLI to execute the flows and stream the responses.
Open the Cloud Shell editor, and locate and open the src/index.ts
file.
Insert the new flow jokeFlow
above the line that starts the flow server.
This flow generates a joke based on a user-suggested topic using the generate function and the gemini20Flash001
model.
Update the list of flows to be started:
After your changes are saved, open the Cloud Shell terminal, and start the Genkit Developer UI:
Wait for the UI and flow server to start before proceeding to the next step.
To access the Genkit Developer UI in your browser, use the Web Preview option, and set the port to 4000.
In the UI, click Flows, and then click jokeFlow.
Provide a topic for the joke. For Input JSON, between the quotes, type cats, and click Run.
A joke on the topic of cats is generated by the model and returned in the response.
You can use the Genkit CLI to execute flows directly. In Cloud Shell, open a new Cloud Shell terminal, and run the menuSuggestionFlow:
View the response from the model.
Exit the UI. In the original Cloud Shell terminal type CTRL+C to stop the Genkit application.
Finally, copy the output.txt
and src/index.ts
files to a Cloud Storage bucket:
Click Check my progress to verify the objectives.
In this task, you create a flow that receives structured input that contains a customer name, the current time, and data from a previous order. The flow returns a recommendation based on the input.
You learn to structure the input as an object, and define the prompt using Dotprompt
. This structure is more composable and will help you organize more complex applications.
Open the src/index.ts
file in the Cloud Shell editor.
Below the last flow jokeFlow
, and above the startFlowServer()
function call, define the input schema that contains the customer name, current time, and previous order.
Below the CustomerTimeAndHistorySchema
schema definition, define the prompt object that the flow will use. The prompt contains the input schema, the model to use, and the text prompt.
Below the greetingWithHistoryPrompt
prompt definition, define the flow that uses the input schema and the defined prompt.
Update the startFlowServer
call with the list of flows to be started:
After your changes are saved, open the Cloud Shell terminal, and start the Genkit Developer UI:
Wait for the Genkit Developer UI and the flow server to start before proceeding to the next step.
To access the Genkit Developer UI in your browser, use the Web Preview option, and set the port to 4000.
In the UI, click Prompts, and click the greetingWithHistory prompt.
Provide the Input (JSON) below:
The user and model prompts are updated in the UI.
To execute the prompt and view the response, click Run.
In the left panel, click Flows, and then click the greetingFlow flow.
Provide the same Input (JSON) below:
To execute the flow and view the response, click Run.
To analyze the flow's execution details, timing and metadata, after the flow executes, click View Trace.
Exit the UI, and type CTRL+C in your Cloud Shell terminal to stop the Genkit application.
Copy the src/index.ts
file to the Cloud Storage bucket.
Click Check my progress to verify the objective.
Congratulations! You have successfully created your first Genkit project. In this lab, you defined several flows, interacted with structured input, and managed prompts using Dotprompt. Additionally, you tested the application through both the Genkit development UI and the CLI interface.
For more information about the topics discussed in this lab, view these links:
Manual Last Updated March 24, 2025
Lab Last Tested February 20, 2025
Copyright 2024 Google LLC All rights reserved. Google and the Google logo are trademarks of Google LLC. All other company and product names may be trademarks of the respective companies with which they are associated.
This content is not currently available
We will notify you via email when it becomes available
Great!
We will contact you via email if it becomes available
One lab at a time
Confirm to end all existing labs and start this one