Build your First AI application with Firebase Genkit πŸš€(Part 1)

Satyam Gondhale
3 min readNov 20, 2024

--

Image from Google

To start developing a AI app first using Genkit it’s essential to understand what Firebase Genkit is and How it helps to create a AI application.

In simple terms Firebase Genkit is framework from Google to help you build AI powered applications and features. While building the app alongside it provides you all developer tools for testing & debugging the app. It’s designed to work with any generative AI model. The development is supported using open source libraries for node.js and Go language 😊

Let’s develop a basic app πŸ‘·

Before starting a development make sure you have already installed node js Node v20+ and npm installed πŸ—οΈ

As we are totally relying on Genkit we need to install Genkit dependencies.
To develop app basically we need to leverage the core capabilities for Genkit and the AI model which Google already have 🚧

Create a directory as my-genkit-app and Install dependencies using npm

mkdir genkit-app
cd genkit-app
npm install genkit @genkit-ai/googleai
npm install dotenv

It’s already said NOTHING IS FREE πŸ˜„ , but the Good news is
Gemini API provides a generous free tier πŸ₯³ and does not require a credit card to get started.

To access Gemini Api, you’ll need an API key.
Follow this guide to Create a API Key from Google AI Studio
https://aistudio.google.com/app/apikey

After you’ve created an API key, set the GOOGLE_GENAI_API_KEY environment variable to your key.

export GOOGLE_GENAI_API_KEY=<your API key>

Usually it is preferable to set API keys on project scope not a global scope. To do this, create .env file inside the project directory and add
GOOGLE_GENAI_API_KEY = <Your Api Key> and Verify key is added using this command

cat .env

Now create a file πŸ“„ which is responsible to interact with Gemini Api and provide us with results

// import the Genkit and Google AI plugin libraries
import { gemini15Flash, googleAI } from '@genkit-ai/googleai';
import { genkit } from 'genkit';
import dotenv from 'dotenv';

// Load the API key from environment variables
dotenv.config();

// configure a Genkit instance
const ai = genkit({
plugins: [googleAI({ apiKey: process.env.GOOGLE_GENAI_API_KEY })], // Pass the API key
model: gemini15Flash, // Set the model
});


(async () => {
// make a generation request
const { text } = await ai.generate('Hello, Gemini!');
console.log(text);
})();

Fantastic, Now it’s a time to MAKE FIRST REQUEST 🚦,
Open Terminal and run the file using command πŸ‘¨β€πŸš€

node main.js

You should be able to see the output as a reply to your question,
Hello there! How can I help you today?

πŸŽ‰πŸŽ†πŸŽ‡πŸŽ‰πŸŽ†πŸŽ‡πŸŽ‰πŸŽ†πŸŽ‡πŸŽ‰πŸŽ†πŸŽ‡πŸŽ‰πŸŽ†πŸŽ‡πŸŽ‰πŸŽ†πŸŽ‡πŸŽ‰πŸŽ†πŸŽ‡πŸŽ‰πŸŽ†πŸŽ‡πŸŽ‰πŸŽ†

Now you’re set up to make model requests with Genkit, the next step is to learn how to use more Genkit capabilities to build your AI-powered apps and workflows and locally debug and test apps.

Stay Tuned and Keep Watch for Part 2, Happy Learning.
Feel Free to Clap
πŸ‘ and Keep me Motivated πŸ‘ to come up with Next Parts.

--

--

Satyam Gondhale
Satyam Gondhale

Written by Satyam Gondhale

Associate Consultant (Globallogic)

Responses (1)