Vertex AI 플러그인

Vertex AI 플러그인은 여러 Google 생성형 AI 모델에 대한 인터페이스를 제공합니다. Vertex AI API를 통해 사용할 수 있습니다.

  • Gemini 1.0 Pro 및 Gemini 1.0 Pro Vision 텍스트 생성
  • Imagen2 이미지 생성
  • Gecko 텍스트 임베딩 생성

또한 Vertex AI Rapid Evaluation API를 통해 평가 측정항목의 하위 집합에 대한 액세스도 제공합니다.

설치

npm i --save @genkit-ai/vertexai

이 플러그인을 사용하는 흐름을 로컬에서 실행하려면 Google Cloud CLI 도구 설치

구성

이 플러그인을 사용하려면 configureGenkit()를 호출할 때 지정합니다.

import { vertexAI } from '@genkit-ai/vertexai';

export default configureGenkit({
  plugins: [
    vertexAI({ projectId: 'your-cloud-project', location: 'us-central1' }),
  ],
  // ...
});

플러그인을 사용하려면 Google Cloud 프로젝트 ID, Vertex API 요청을 수행할 리전, Google Cloud 프로젝트 사용자 인증 정보를 지정해야 합니다.

  • 다음에서 projectId를 설정하여 Google Cloud 프로젝트 ID를 지정할 수 있습니다. vertexAI() 구성 또는 GCLOUD_PROJECT 환경 설정 변수의 값을 반환합니다. Google Cloud 환경 (Cloud Monitoring)에서 Functions, Cloud Run 등)에서 GCLOUD_PROJECT가 자동으로 환경의 프로젝트 ID입니다.

  • 다음 중 하나에서 location를 설정하여 API 위치를 지정할 수 있습니다. vertexAI() 구성 또는 GCLOUD_LOCATION 환경 설정 변수의 값을 반환합니다.

  • API 사용자 인증 정보를 제공하려면 Google Cloud 애플리케이션 기본 사용자 인증 정보를 설정해야 합니다.

    1. 사용자 인증 정보를 지정하려면 다음 안내를 따르세요.

      • Google Cloud 환경(Cloud Functions, Cloud Run 등)에서 흐름을 실행하는 경우 이는 자동으로 설정됩니다

      • 로컬 개발 환경에서 다음을 실행하여 이 작업을 수행합니다.

      gcloud auth application-default login
      
    2. 또한 계정에 Vertex AI 사용자 IAM 역할(roles/aiplatform.user)이 부여되었는지 확인합니다. Vertex AI 액세스 제어 문서를 참조하세요.

용도

생성형 AI 모델

이 플러그인은 지원되는 생성형 AI 모델에 대한 참조를 정적으로 내보냅니다.

import { gemini15Flash, gemini15Pro, imagen2 } from '@genkit-ai/vertexai';

이러한 참조를 사용하여 generate()에서 사용할 모델을 지정할 수 있습니다.

const llmResponse = await generate({
  model: gemini15Flash,
  prompt: 'What should I do when I visit Melbourne?',
});

또한 이 플러그인은 Gecko 텍스트 임베딩 참조를 정적으로 내보냅니다. 모델:

import { textEmbeddingGecko } from '@genkit-ai/vertexai';

이 참조를 사용하여 색인 생성기 또는 검색기로 사용할 임베딩을 지정할 수 있습니다. 사용합니다 예를 들어 Chroma DB를 사용하는 경우:

configureGenkit({
  plugins: [
    chroma([
      {
        embedder: textEmbeddingGecko,
        collectionName: 'my-collection',
      },
    ]),
  ],
});

또는 임베딩을 직접 생성할 수도 있습니다.

// import { embed, EmbedderArgument } from '@genkit-ai/ai/embedder';
const embedding = await embed({
  embedder: textEmbeddingGecko,
  content: 'How many widgets do you have in stock?',
});

Vertex AI 모델 가든의 Anthropic Claude 3

Vertex AI Model Garden에서 Claude 3 모델 (haiku, sonnet, opus)에 액세스할 수 있는 경우 Genkit와 함께 사용할 수 있습니다.

다음은 Vertex AI Model Garden 모델을 사용 설정하기 위한 샘플 구성입니다.

import {
  vertexAI,
  claude3Haiku,
  claude3Sonnet,
  claude3Opus,
} from '@genkit-ai/vertexai';

export default configureGenkit({
  plugins: [
    vertexAI({
      location: 'us-central1',
      modelGarden: {
        models: [claude3Haiku, claude3Sonnet, claude3Opus],
      },
    }),
  ],
});

그런 다음 일반 모델로 사용합니다.

const llmResponse = await generate({
  model: claude3Sonnet,
  prompt: 'What should I do when I visit Melbourne?',
});

Vertex AI 모델 가든의 Llama 3.1 405b

먼저 Vertex AI 모델 가든에서 Llama 3.1 API 서비스를 사용 설정해야 합니다.

다음은 Vertex AI 플러그인의 Llama 3.1 405b의 샘플 구성입니다.

import { vertexAI, llama3 } from '@genkit-ai/vertexai';

export default configureGenkit({
  plugins: [
    vertexAI({
      location: 'us-central1',
      modelGarden: {
        models: [llama3],
      },
    }),
  ],
});

그런 다음 일반 모델로 사용합니다.

const llmResponse = await generate({
  model: llama3,
  prompt: 'Write a function that adds two numbers together',
});

평가자

Vertex AI Rapid Evaluation에서 평가자를 사용하려면 vertexAI 플러그인 구성에 evaluation 블록을 추가하세요.

import { vertexAI, VertexAIEvaluationMetricType } from '@genkit-ai/vertexai';

export default configureGenkit({
  plugins: [
    vertexAI({
      projectId: 'your-cloud-project',
      location: 'us-central1',
      evaluation: {
        metrics: [
          VertexAIEvaluationMetricType.SAFETY,
          {
            type: VertexAIEvaluationMetricType.ROUGE,
            metricSpec: {
              rougeType: 'rougeLsum',
            },
          },
        ],
      },
    }),
  ],
  // ...
});

위 구성은 SafetyROUGE 측정항목의 평가자를 추가합니다. 이 예에서는 두 가지 접근 방식을 보여줍니다. Safety 측정항목은 기본 사양을 사용하는 반면, ROUGE 측정항목은 루즈 유형을 rougeLsum로 설정하는 맞춤설정된 사양을 제공합니다.

두 평가자는 호환되는 데이터 세트(즉, outputreference 필드가 있는 데이터 세트)와 함께 genkit eval:run 명령어를 사용하여 실행할 수 있습니다. Safety 평가자는 output만 필요하므로 genkit eval:flow -e vertexai/safety 명령어를 사용하여 실행할 수도 있습니다.