Firebase Genkit

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

Genkit का लोगो

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

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

फ़िलहाल, Genkit JavaScript/TypeScript में सर्वर साइड डेवलपमेंट के साथ काम करता है (Node.js) को ऐक्टिव डेवलपमेंट में Go सहायता के साथ जोड़ना होगा.

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

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

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

8. खोलें और एक्सटेंसिबल

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

क्या आपको अपने मनचाहे इंटिग्रेशन के लिए प्लगिन नहीं मिल रहा है? कोई बात नहीं. जेनकिट्स ऐब्स्ट्रैक्ट आसानी से बनाए जा सकते हैं और इसकी मदद से, ऐसे कस्टम कॉम्पोनेंट आसानी से बनाए जा सकते हैं जो फ़्रेमवर्क में इंटिग्रेट किया जा सकता है, जैसे कि यह कस्टम 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 के साथ इंटिग्रेट करें Firebase के लिए Cloud Functions, Firebase से पुष्टि करने, ऐप्लिकेशन की जांच, और Firestore.

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
एम्बेड करने के मॉडल: गेको टेक्स्ट एम्बेड करना
vertexai जनरेटिव मॉडल: Gemini Pro, Gemini Pro Vision, Gemini 1.5 Flash, Gemini 1.5 Pro, Imagen2, Anthropic Claude 3
एम्बेड करने के मॉडल: गेको टेक्स्ट एम्बेड करना
एवैलुएटर: 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 इंस्टॉल करने का तरीका जानने के लिए, शुरू करने का तरीका बताने वाली गाइड पढ़ें अपना पहला एआई फ़्लो चलाएं.