Gemini Enterprise Agent Platform 통합

Gemini Enterprise Agent Platform 통합

LangChain JavaScript로 Gemini Enterprise Agent Platform LLM과 통합하는 방법을 알아봅니다.

Gemini Enterprise Agent Platform은 Google Cloud에서 제공하는 모든 파운데이션 모델(예: gemini-2.5-pro, gemini-2.5-flash 등)을 노출하는 서비스예요. LangChain으로 Gemini Enterprise Agent Platform 완성 모델(LLM)을 시작하는 데 도움을 주는 가이드입니다. VertexAI 기능과 구성 옵션에 대한 자세한 문서는 API reference를 참조하세요.

출처: 문서

본문

현재 이 페이지는 Gemini Enterprise Agent Platform 모델을 텍스트 완성 모델로 사용하는 방법을 다루는 문서예요. Gemini Enterprise Agent Platform에서 제공하는 많은 인기 모델은 챗 완성 모델입니다.

아마 이 페이지를 찾고 계실 수도 있어요.

개요

통합 세부 정보

클래스(Class) 패키지(Package) 로컬(Local) 직렬화(Serializable) PY 지원 다운로드(Downloads) 버전(Version)
VertexAI @langchain/google-vertexai NPM - Downloads NPM - Version

설정

LangChain.js는 Node.js 환경에서 실행하는지 웹 환경에서 실행하는지에 따라 두 가지 서로 다른 인증 방법을 지원합니다.

Gemini Enterprise Agent Platform 모델에 접근하려면 Google Cloud Platform(GCP) 계정을 만들고 API 키를 발급받은 뒤 @langchain/google-vertexai 통합 패키지를 설치해야 합니다. Node.js에서는 이 패키지가 인증을 위해 @langchain/google-gauth를 사용합니다(별도로 설치할 필요는 없습니다).

자격 증명(Credentials)

Node.js

해당 프로젝트에 Gemini Enterprise Agent Platform API가 활성화되어 있고, 다음 방법 중 하나로 Google Cloud에 인증했는지 확인하세요:

  • 프로젝트에 대한 권한이 있는 계정(gcloud auth application-default login 사용)으로 로그인한 경우.
  • 프로젝트에 대한 권한이 있는 서비스 계정을 사용하는 머신에서 실행 중인 경우.
  • 프로젝트에 대한 권한이 있는 서비스 계정의 자격 증명을 다운로드하고 GOOGLE_APPLICATION_CREDENTIALS 환경 변수를 이 파일의 경로로 설정한 경우. 또는
  • 프로젝트의 API 키로 GOOGLE_API_KEY 환경 변수를 설정한 경우.

Web

웹 환경(예: Edge 함수)에서 Gemini Enterprise Agent Platform 모델을 호출하려면 @langchain/google-vertexai-web 패키지를 설치해야 합니다.

그런 다음 서비스 계정 자격 증명을 GOOGLE_WEB_CREDENTIALS(또는 더 이상 사용되지 않는 GOOGLE_VERTEX_AI_WEB_CREDENTIALS)에 설정하세요:

export GOOGLE_WEB_CREDENTIALS='{"type":"service_account","project_id":"YOUR_PROJECT-12345",...}'

코드에서 직접 자격 증명을 전달할 수도 있습니다:

import { VertexAI } from "@langchain/google-vertexai";
// Or uncomment this line if you're using the web version:
// import { VertexAI } from "@langchain/google-vertexai-web";

const model = new VertexAI({
  authOptions: {
    credentials: {"type":"service_account","project_id":"YOUR_PROJECT-12345",...},
  },
});

모델 호출에 대한 자동 추적을 받으려면 아래 주석을 해제해 LangSmith API 키를 설정할 수도 있습니다:

# export LANGSMITH_TRACING="true"
# export LANGSMITH_API_KEY="your-api-key"

설치

LangChain Gemini Enterprise Agent Platform 통합은 @langchain/google-vertexai 패키지에 있습니다:

npm install @langchain/google-vertexai @langchain/core
yarn add @langchain/google-vertexai @langchain/core
pnpm add @langchain/google-vertexai @langchain/core

또는 웹 환경의 경우:

npm install @langchain/google-vertexai-web @langchain/core
yarn add @langchain/google-vertexai-web @langchain/core
pnpm add @langchain/google-vertexai-web @langchain/core

인스턴스화(Instantiation)

이제 모델 객체를 인스턴스화하고 채팅 완성을 생성할 수 있습니다:

import { VertexAI } from "@langchain/google-vertexai-web"

const llm = new VertexAI({
  model: "gemini-pro",
  temperature: 0,
  maxRetries: 2,
  // other params...
})

호출(Invocation)

const inputText = "Gemini is an AI model family that "

const completion = await llm.invoke(inputText)
completion
offers a wide range of cloud computing services and artificial intelligence solutions to businesses and developers worldwide.

API reference

모든 VertexAI 기능과 구성에 대한 자세한 문서는 API reference를 참조하세요.

더 알아보기 (Learn more)