Firebase Genkit

Genkit는 AI 기반 애플리케이션과 기능의 빌드를 지원하도록 설계된 프레임워크입니다. Node.js 및 Go를 위한 오픈소스 라이브러리와 테스트 및 디버깅을 위한 개발자 도구를 제공합니다.

이 문서에서는 Node.js용 Genkit를 설명합니다. Go 개발자는 Genkit Go 문서를 참고하세요.

Node.js가 지원되는 곳이라면 어디서나 Genkit 라이브러리를 배포하고 실행할 수 있습니다. 모든 생성형 AI 모델 API 또는 벡터 데이터베이스와 함께 작동하도록 설계되었습니다. Firebase와 Google Cloud 통합이 제공되지만 Google 서비스와 관계없이 Genkit를 사용할 수도 있습니다.

시작하기

주요 기능

AI 생성을 위한 통합 API 하나의 API를 사용하여 다양한 AI 모델에서 콘텐츠를 생성하거나 스트리밍할 수 있습니다. 멀티모달 입력/출력 및 커스텀 모델 설정과 함께 작동합니다.
구조화된 생성 내장된 유효성 검사 기능으로 구조화된 객체 (예: JSON)를 생성하거나 스트리밍할 수 있습니다. 앱과의 통합을 간소화하고 구조화되지 않은 데이터를 사용 가능한 형식으로 변환합니다.
도구 호출 AI 모델이 작업을 완료하기 위한 도구로 함수와 API를 호출하도록 하세요. 사용할 도구와 시기는 모델이 결정합니다.
검색 증강 생성 데이터를 통합하여 생성된 출력의 정확성과 관련성을 개선하세요. 간단한 API를 사용하면 다양한 소스에서 정보를 삽입, 색인 생성, 검색할 수 있습니다.
프롬프트 템플릿 서식 있는 텍스트 템플릿, 모델 설정, 멀티모달 지원, 도구 통합을 포함하는 효과적인 프롬프트를 만들고 실행 가능한 소형 프롬프트 파일을 만드세요.

코드에서 이러한 기능을 사용하는 방법에 관한 구체적인 아이디어는 다음 코드 샘플을 참고하세요.

기본 생성

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 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는 명령줄 인터페이스 (CLI)와 로컬 개발자 UI를 제공하여 AI 애플리케이션을 더 쉽게 빌드할 수 있도록 해줍니다. 이 도구는 다음과 같은 작업에 도움이 됩니다.

  • 실험: AI 기능, 프롬프트, 쿼리를 테스트하고 미세 조정합니다.
  • 디버그: 자세한 실행 trace로 문제를 찾아 수정합니다.
  • 평가: 여러 테스트 사례에 걸쳐 생성된 결과를 평가합니다.

Google과 소통하기

  • 커뮤니티 가입: Discord 서버에서 최신 소식을 받고, 질문하고, 작업물을 공유하세요.
  • 의견 제공: GitHub Issue Tracker를 사용하여 문제를 신고하거나 새로운 기능을 제안하세요.

다음 단계

시작하기 가이드에서 Genkit로 첫 AI 애플리케이션을 빌드하는 방법을 알아보세요.