Firebase Genkit

Firebase Genkit एक ओपन सोर्स फ़्रेमवर्क है, जो प्रोडक्शन के लिए तैयार एआई की मदद से काम करने वाले ऐप्लिकेशन बनाने, डिप्लॉय करने, और मॉनिटर करने में आपकी मदद करता है.

Genkit का लोगो

Genkit को ऐप्लिकेशन डेवलपर के लिए डिज़ाइन किया गया है. इससे आपको अपने ऐप्लिकेशन में, जाने-पहचाने पैटर्न और मॉडल के साथ बेहतर एआई सुविधाओं को आसानी से इंटिग्रेट करने में मदद मिलती है. इसे Firebase की टीम ने ही बनाया है. इसके लिए, दुनिया भर के लाखों डेवलपर इस्तेमाल किए जाने वाले टूल बनाने में हमारे अनुभव का इस्तेमाल करते हैं.

Genkit का इस्तेमाल ऐसे ऐप्लिकेशन बनाने के लिए करें जो पसंद के मुताबिक कॉन्टेंट जनरेट करते हैं, सिमैंटिक सर्च का इस्तेमाल करते हैं, बिना स्ट्रक्चर वाले इनपुट हैंडल करते हैं, अपने कारोबार के डेटा से सवालों के जवाब देते हैं, अपने-आप फ़ैसले लेते हैं, टूल कॉल व्यवस्थित करते हैं, और ऐसे ही कई और काम करते हैं!

फ़िलहाल, Genkit चालू डेवलपमेंट में Go सहायता के साथ JavaScript/TypeScript (Node.js) में सर्वर-साइड डेवलपमेंट की सुविधा देता है.

इसके डेवलपमेंट पर गौर करें या इसके GitHub रिपॉज़िटरी में अपना योगदान दें.

मुख्य सुविधाएं

Genkit आपके लिए एआई के डेवलपमेंट से जुड़े हर कदम पर आपकी मदद करने के लिए तैयार है. प्रॉडक्ट के प्रोटोटाइप बनाने की शुरुआत से लेकर प्रोडक्शन में निगरानी रखने तक, यहां आपको बहुत कुछ करने की ज़रूरत है.

शुरुआत करने में आपकी मदद करने के लिए, यहां Genkit की 10 अहम सुविधाओं के बारे में बताया गया है. हमें लगता है कि आपको ये सुविधाएं पसंद आएंगी:

1. कई मॉडल, एक इंटरफ़ेस

Genkit आपको ऐसे प्लगिन उपलब्ध कराता है जो आपके लिए लोकप्रिय मॉडल को ऐक्सेस करते हैं. साथ ही, आपको आसान और सुविधाजनक मॉडल का ऐक्सेस मिलता है. इसकी मदद से, किसी भी मॉडल एपीआई को इंटिग्रेट करना और कम्यूनिटी की ओर से मैनेज किए जाने वाले मॉडल इस्तेमाल करना आसान हो जाता है. किसी नए मॉडल को आज़माना, किसी एक तर्क को बदलने जितना आसान है. हालांकि, हर मॉडल अपनी पसंद के मुताबिक कॉन्फ़िगरेशन तय कर सकता है.

import { geminiPro } from '@genkit-ai/vertexai';
import { ollama } from 'genkitx-ollama';
import { generate } from '@genkit-ai/ai';

function flipACoin(a, b) {
  return Math.random() > 0.5 ? a : b;
}

const result = await generate({
  model: flipACoin(geminiPro, 'ollama/gemma'),
  config: { temperature: 0.3, maxOutputTokens: 200 },
  prompt: 'What makes you the best LLM out there?',
});

console.log(result.text());

2. स्ट्रक्चर्ड आउटपुट

Zod स्कीमा का इस्तेमाल करके, Genkit के साथ मज़बूत टाइप किया गया डेटा जनरेट करें. इससे आपको बिना स्ट्रक्चर वाले टेक्स्ट का विश्लेषण करने, क्रिएटिव कॉन्टेंट जनरेट करने, टास्क चुनने, और खोज के नतीजों को वापस अपने ऐप्लिकेशन पर ऐसे ऑब्जेक्ट के तौर पर भेजने में मदद मिल सकती है जो स्ट्रक्चर्ड टाइप से सुरक्षित हों.

import { generate } from "@genkit-ai/ai";
import { geminiPro } from "@genkit-ai/vertexai";
import { z } from "zod";

const CreatureSchema = z.object({
  name: z.string().describe('the name of the creature'),
  hitPoints: z.number().describe('hit points, between 5 and 100'),
  attacks: z.array(z.object({
    name: z.string(),
    damage: z.number().describe('amount of damage, between 2 and 25'),
  })).describe('3 attacks the creature can use')
});

const createCreature = defineFlow({
    name: "createCreature",
    inputSchema: z.string(),
    outputSchema: CreatureSchema,
  },
  (habitat) => {
    const result = await generate({
      model: geminiPro,
      prompt: `You are a brilliant RPG designer. Generate a creature that lives in ${habitat}.`,
      output: {schema: CreatureSchema}
    });
    // strongly typed and ready to go
    return result.output();
  }
)

console.log(await createCreature("a developer conference"));

3. मल्टीमोडल, मल्टीमीडिया

Genkit ऐसे कॉन्टेंट के लिए एक सामान्य फ़ॉर्मैट उपलब्ध कराता है जिसमें टेक्स्ट, डेटा, और आर्बिट्रेरी मीडिया को मिक्स किया जा सकता है. यह आपको Genkit का इस्तेमाल उन मॉडल के लिए करने देता है जो सिर्फ़ एलएलएम ही नहीं, बल्कि जनरेटिव टास्क (जैसे, इमेज जनरेट करना) को भी करते हैं.

import { imagen2, geminiProVision } from '@genkit-ai/vertexai';
import { generate } from '@genkit-ai/ai';

const imageResult = await generate({
  model: imagen2,
  prompt: 'Generate an image of a very specific historical time and place.',
});
const generatedImage = imageResult.media();

const descriptionResult = await generate({
  model: geminiProVision,
  prompt: [
    {
      text: 'What is the historical time and place represented in this picture?',
    },
    { media: generatedImage },
  ],
});
console.log(descriptionResult.text());

4. एलएलएम के टूल इस्तेमाल करें

Genkit की मदद से, टूल की मदद से एलएलएम का इस्तेमाल करके, फ़ंक्शन कॉल करना आसान हो जाता है. टूल की मदद से एआई, डेटा फ़ेच कर सकता है, यूआई दिखा सकता है, डेटाबेस में लिख सकता है. इसके अलावा, ऐसी कोई भी अन्य कार्रवाई कर सकता है जिसे कोड अप किया जा सके.

import { generate, defineTool } from '@genkit-ai/ai';
import { geminiPro } from '@genkit-ai/vertexai';
import { z } from 'zod';

const createReminder = defineTool(
  {
    name: 'createReminder',
    description: 'Use this to create reminders for things in the future',
    inputSchema: z.object({
      time: z
        .string()
        .describe('ISO timestamp string, e.g. 2024-04-03T12:23:00Z'),
      reminder: z.string().describe('the content of the reminder'),
    }),
    outputSchema: z.number().describe('the ID of the created reminder'),
  },
  (reminder) => db.reminders.create(reminder)
);

const searchNotes = defineTool(
  {
    name: 'searchNotes',
    description: "Use this to search the user's notes for people or phrases",
    inputSchema: z.string().describe('the search query'),
    outputSchema: z.object({ notes: z.array(NoteSchema) }),
  },
  (query) => db.notes.search(query)
);

const result = await generate({
  model: geminiPro,
  tools: [createReminder, searchNotes],
  prompt: `
  You are a note-taking assistant. Using the tools available, try to answer the provided query.
  If you create a reminder, describe in text the reminder you created as a response.

  Query: I took a note about a meeting with Anna - can you set a reminder for the time?
  `,
});
console.log(result.text());

5. Dotprompt की मदद से, प्रॉम्प्ट को कम समय में मैनेज करने की सुविधा

प्रॉम्प्ट इंजीनियरिंग सिर्फ़ टेक्स्ट में बदलाव करने से कहीं ज़्यादा है. आपके इस्तेमाल किए जाने वाले मॉडल, आपके दिए गए पैरामीटर, और आपके अनुरोध किए गए फ़ॉर्मैट का असर आपके आउटपुट की क्वालिटी पर पड़ता है. Genkit, Dotprompt की सुविधा देता है, जो एक प्रॉम्प्ट फ़ाइल फ़ॉर्मैट है. यह आपको सभी फ़ाइलों को एक ही फ़ाइल में रखने की सुविधा देता है, ताकि टेस्ट करना और उन्हें व्यवस्थित करना आसान हो जाए.

---
model: vertexai/gemini-1.0-pro
config:
  temperature: 0.9
input:
  schema:
    properties:
      location: {type: string}
      style: {type: string}
      name: {type: string}
    required: [location]
  default:
    location: a restaurant
---

You are the world's most welcoming AI assistant and are currently working at {{location}}.

Greet a guest{{#if name}} named {{name}}{{/if}}{{#if style}} in the style of {{style}}{{/if}}.

6. स्थानीय तौर पर फ़्लो चलाएं

जनरेटिव एआई के नतीजे कई तरह के होते हैं. इसलिए, इन्हें आज़माना बहुत ज़रूरी है. लोकल Genkit डेवलपर यूज़र इंटरफ़ेस (यूआई) की मदद से, मॉडल और रिट्रीवर जैसे ज़रूरी एआई कॉम्पोनेंट के साथ इंटरैक्ट किया जा सकता है. साथ ही, इसमें एंड-टू-एंड फ़्लो की मैन्युअल तौर पर जांच की जा सकती है. इसमें आपके लिखे गए सभी कस्टम कोड भी शामिल होते हैं.

7. ट्रेस की जांच करें

कई चरणों वाले, मुश्किल वर्कफ़्लो को एआई की मदद से डीबग करना मुश्किल हो सकता है. ऐसा, प्रोसेस को किसी भी क्रम में करने और छिपी हुई प्रोसेस की वजह से होता है. Genkit, डेवलपर के यूज़र इंटरफ़ेस (यूआई) में ट्रेस इंस्पेक्टर उपलब्ध कराता है. इसकी मदद से, हर मॉडल कॉल और फ़्लो के चरण के लिए ट्रेस की जांच की जा सकती है. यह प्रोडक्शन के ट्रेस देख सकता है और इमेज को रेंडर भी कर सकता है!

8. खुला है और एक्सटेंशन की सुविधा उपलब्ध है

एआई ईकोसिस्टम, किसी भी एक टीम के साथ तेज़ी से आगे बढ़ रहा है. Genkit का एक ओपन प्लगिन मॉडल है. यह नए मॉडल, रिवर्सिटी वगैरह के साथ पहले से बने इंटिग्रेशन की सुविधा देता है. Genkit टीम के पास आधिकारिक प्लगिन का एक छोटा सेट होता है. हालांकि, कोई भी व्यक्ति बेझिझक अपने Genkit प्लगिन को NPM पर पब्लिश कर सकता है.

क्या आपको अपने मनचाहे इंटिग्रेशन के लिए प्लगिन नहीं मिल रहा है? कोई बात नहीं. Genkit के ऐब्स्ट्रैक्ट आसानी से इस्तेमाल किए जा सकते हैं और इनकी मदद से ऐसे कस्टम कॉम्पोनेंट बनाना आसान हो जाता है जो फ़्रेमवर्क में इंटिग्रेट हो जाते हैं, जैसे कि यह कस्टम Firestore रिट्रीवर:

import { embed } from '@genkit-ai/ai/embedder';
import { Document, defineRetriever } from '@genkit-ai/ai/retriever';
import { textEmbeddingGecko } from '@genkit-ai/vertexai';
import {
  FieldValue,
  VectorQuery,
  VectorQuerySnapshot,
} from '@google-cloud/firestore';
import { Firestore } from 'firebase-admin/firestore';
import * as z from 'zod';
import { augmentedPrompt } from './prompt';

const QueryOptions = z.object({
  k: z.number().optional(),
});

const firestoreArtifactsRetriever = defineRetriever(
  {
    name: 'firestore/artifacts',
    configSchema: QueryOptions,
  },
  async (input, options) => {
    const embedding = await embed({
      embedder: textEmbeddingGecko,
      content: input,
    });

    const db = new Firestore();
    const coll = db.collection('vectors' /* your collection name */);

    const vectorQuery: VectorQuery = coll.findNearest(
      'embedding' /* the name of the field that contains the vector */,
      FieldValue.vector(embedding),
      {
        limit: options.k ?? 3,
        distanceMeasure: 'COSINE',
      }
    );

    const vectorQuerySnapshot: VectorQuerySnapshot = await vectorQuery.get();
    return {
      documents: vectorQuerySnapshot.docs.map((doc) =>
        // doc.data() represents the Firestore document. You may process
        // it as needed to generate a Genkit document object, depending on your
        // storage format.
        Document.fromText(doc.data().content.text)
      ),
    };
  }
);

9. प्रोडक्शन के लिए बनाया गया

अपने फ़्लो को ऐसे किसी भी प्लैटफ़ॉर्म पर आसानी से डिप्लॉय करें जो Express.js ऐप्लिकेशन के साथ काम कर सकता है. Genkit को पूरी तरह से OpenTelemetry और एंटरप्राइज़-ग्रेड के प्रोडक्शन की निगरानी के लिए कस्टम मेटाडेटा से बनाया गया है.

Google Cloud और Firebase के लिए भी आधिकारिक प्लगिन उपलब्ध हैं. इनकी मदद से, डेटा को Google Cloud के ऑपरेशंस सुइट में एक्सपोर्ट किया जा सकता है. साथ ही, Firebase के लिए Cloud Functions, Firebase से पुष्टि करने, ऐप्लिकेशन की जांच, और Firestore जैसी Firebase सेवाओं को इंटिग्रेट किया जा सकता है.

Cloud Trace का स्क्रीनशॉट

10. अनुमति देना और सुरक्षा मैनेज करना

सार्वजनिक तौर पर उपलब्ध कोई भी ऐप्लिकेशन बनाते समय, अपने सिस्टम में सेव किए गए डेटा की सुरक्षा करना अहम होता है. एलएलएम के मामले में, ज़्यादा सावधानी बरतने की ज़रूरत होती है, ताकि मॉडल सिर्फ़ डेटा को ऐक्सेस कर सके. टूल कॉल का दायरा, एलएलएम का इस्तेमाल करने वाले उपयोगकर्ता तक सही तरीके से हो. साथ ही, इस फ़्लो को सिर्फ़ पुष्टि किए गए क्लाइंट ऐप्लिकेशन से ही शुरू किया जा रहा हो.

Genkit, अनुमति देने की नीतियों और कॉन्टेक्स्ट को मैनेज करने के लिए मैकेनिज़्म उपलब्ध कराता है.

import { defineFlow, runFlow } from '@genkit-ai/flow';

export const selfSummaryFlow = defineFlow(
  {
    name: 'selfSummaryFlow',
    inputSchema: z.object({uid: z.string()}),
    outputSchema: z.string(),
    authPolicy: (auth, input) => {
      if (!auth) {
        throw new Error('Authorization required.');
      }
      if (input.uid !== auth.uid) {
        throw new Error('You may only summarize your own profile data.');
      }
    }
  },
  async (input) => { ... });

इंटिग्रेशन

Genkit अपने प्लगिन सिस्टम की मदद से, एआई मॉडल, वेक्टर डेटाबेस, टेलीमेट्री प्लैटफ़ॉर्म वगैरह के साथ इंटिग्रेशन करता है. Genkit टीम इन प्लगिन का रखरखाव करती है:

आधिकारिक प्लगिन
googleai जनरेटिव मॉडल: Gemini Pro, Gemini 1.5 Pro, Gemini Pro Vision
एम्बेड करने के मॉडल: Gecko में टेक्स्ट एम्बेड करना
vertexai जनरेटिव मॉडल: Gemini Pro, Gemini Pro Vision, Gemini 1.5 Flash, Gemini 1.5 Pro, Imagen2, एंथ्रोपिक क्लाउड 3
एम्बेड करने की सुविधा वाले मॉडल: Gecko में टेक्स्ट एम्बेड करना
आकलनकर्ता: Vertex AI का आकलन
ollama जनरेटिव मॉडल: कई लोकल मॉडल. इनमें Gemma, Llama 3, Mistral वगैरह शामिल हैं
chroma वेक्टर डेटाबेस: ChromaDB
pinecone वेक्टर डेटाबेस: पाइनकोन
google-cloud निगरानी करने वाले टूल: Google Cloud Trace, Google Cloud Logging
firebase Cloud डिप्लॉयमेंट: Cloud Functions, Firebase से पुष्टि करना, ऐप्लिकेशन की जांच
वेक्टर डेटाबेस: Cloud Firestore वेक्टर स्टोर
langchain Genkit के फ़्लो में, LangChain चेन और काम के टूल इस्तेमाल करें

शुरू करना

Genkit इंस्टॉल करने और अपना पहला एआई फ़्लो इस्तेमाल करने का तरीका जानने के लिए, इस्तेमाल शुरू करने का तरीका बताने वाली गाइड पढ़ें.