Firebase Genkit

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

इस दस्तावेज़ में Node.js के लिए Genkit के बारे में बताया गया है. अगर आप Go डेवलपर हैं, तो Genkit Go का दस्तावेज़ देखें.

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

शुरू करें

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

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

कोड में इन क्षमताओं का इस्तेमाल करने का तरीका जानने के लिए, यहां दिए गए कोड के सैंपल देखें:

सामान्य जनरेशन

import { generate } from `@genkit-ai/ai`;
import { gemini15Flash, claude3Sonnet, llama31 } from '@genkit-ai/vertexai';
import { gpt4o } from 'genkitx-openai';

// Use the same API to generate content from many models
const result = await generate({
    model: gemini15Flash, // Or use claude3Sonnet, llama31, gpt4o
    prompt: 'What makes you the best LLM out there?',
});

स्ट्रक्चर्ड जनरेशन

import { generate } from `@genkit-ai/ai`;
import { gemini15Flash } from `@genkit-ai/googleai`;
import { z } from `zod`;

const result = await generate({
    model: gemini15Flash,
    prompt: 'Create a brief profile for a character in a fantasy video game.',
    // Specify output structure using Zod schema
    output: {
        schema: z.object({
            name: z.string(),
            role: z.enum(['knight', 'mage', 'archer']),
            backstory: z.string(),
            attacks: z.array(z.object({
              name: z.string(),
              damage: z.number().describe('amount of damage, between 2 and 25'),
            })).describe('3 attacks the character can use')
        })
    }
});

टूल कॉलिंग

import { generate, defineTool } from `@genkit-ai/ai`;
import { gemini15Flash } from `@genkit-ai/googleai`;
import { z } from `zod`;

// Define tool to get weather data for a given location
const lookupWeather = defineTool({
    name: 'lookupWeather',
    description: 'Get the current weather in a location.',
    // Define input and output schema so the model knows how to use the tool
    inputSchema: z.object({
        location: z.string().describe('The location to get the weather for.'),
    }),
    outputSchema: z.object({
        temperature: z.number().describe('The current temperature in Fahrenheit.'),
        condition: z.string().describe('A brief description of the weather conditions.'),
    }),
    async (input) => {
        // Insert weather lookup API code
    }
});

const result = await generate({
    model: gemini15Flash,
    tools: [lookupWeather], // Give the model a list of tools it can call
    prompt: 'What is the weather like in New York? ',
});

वापस पाना

import { generate, retrieve } from `@genkit-ai/ai`;
import { devLocalRetrieverRef } from '@genkit-ai/dev-local-vectorstore';
import { gemini15Flash } from `@genkit-ai/googleai`;

// Sample assumes Genkit documentation has been chunked, stored, and indexed in 
// local vectorstore in previous step.

// Reference to a local vector database storing Genkit documentation
const retriever = devLocalRetrieverRef('genkitQA');

const query = 'How do I retrieve relevant documents in Genkit?'

// Consistent API to retrieve most relevant documents based on semantic similarity to query
const docs = await retrieve({
    retriever: retriever,
    query: query,
    options: { limit: 5 },
});

const result = await generate({
    model: gemini15Flash
    prompt: 'Use the provided context from the Genkit documentation to answer this query: ${query}',
    context: docs // Pass retrieved documents to the model
});

प्रॉम्प्ट टेंप्लेट

---
model: vertexai/gemini-1.5-flash
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}}.

डेवलपमेंट टूल

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

  • एक्सपेरिमेंट: अपने एआई फ़ंक्शन, प्रॉम्प्ट, और क्वेरी की जांच करें और उन्हें बेहतर बनाएं.
  • डीबग: लागू करने के ट्रेस की पूरी जानकारी की मदद से समस्याओं को ढूंढें और उन्हें ठीक करें.
  • आकलन करें: एक से ज़्यादा टेस्ट केस में जनरेट किए गए नतीजों का आकलन करें.

हमसे जुड़ें

  • कम्यूनिटी में शामिल हों: हमारे Discord सर्वर पर अपडेट रहें, सवाल पूछें, और अपना काम शेयर करें.
  • सुझाव या राय दें: GitHub पर काम करने वाले समस्या को ट्रैक करने वाले टूल की मदद से, समस्याओं की शिकायत करें या नई सुविधाओं का सुझाव दें.

अगले चरण

शुरू करें गाइड में, Genkit की मदद से अपना पहला एआई ऐप्लिकेशन बनाने का तरीका जानें.