AnthropicVertex 프로바이더
AnthropicVertex 프로바이더
nalaso/anthropic-vertex-ai는 Vertex AI를 통해 Anthropic 모델을 사용해 AI SDK에 언어 모델 지원을 제공하는 커뮤니티 프로바이더예요.
출처: 문서
본문
참고: Google Vertex용 Anthropic은 AI SDK Google Vertex 프로바이더에서도 지원돼요.
경고: 이 커뮤니티 프로바이더는 아직 AI SDK 5와 호환되지 않아요. 프로바이더가 업데이트될 때까지 기다리거나 AI SDK 5 호환 프로바이더를 고려해 주세요.
설정 (Setup)
AnthropicVertex 프로바이더는 anthropic-vertex-ai 모듈에서 사용할 수 있어요. 다음과 같이 설치할 수 있어요:
프로바이더 인스턴스 (Provider Instance)
anthropic-vertex-ai에서 기본 프로바이더 인스턴스 anthropicVertex를 임포트할 수 있어요:
import { anthropicVertex } from 'anthropic-vertex-ai';
커스터마이즈가 필요하면 anthropic-vertex-ai에서 createAnthropicVertex를 임포트해 나만의 설정으로 프로바이더 인스턴스를 만들 수 있어요:
import { createAnthropicVertex } from 'anthropic-vertex-ai';
const anthropicVertex = createAnthropicVertex({
region: 'us-central1',
projectId: 'your-project-id',
// other options
});
AnthropicVertex 프로바이더 인스턴스를 커스터마이즈할 때 다음과 같은 옵션 설정을 사용할 수 있어요:
-
region string
Google Vertex 리전이에요. 기본값은
GOOGLE_VERTEX_REGION환경 변수예요. -
projectId string
Google Vertex 프로젝트 ID예요. 기본값은
GOOGLE_VERTEX_PROJECT_ID환경 변수예요. -
googleAuth GoogleAuth
선택 사항. google-auth-library가 제공하는 인증 옵션이에요.
-
baseURL string
프록시 서버를 사용하는 경우처럼 API 호출에 다른 URL 프리픽스를 사용할 수 있어요. 기본 프리픽스는
https://{region}-aiplatform.googleapis.com/v1이에요. -
headers Record<string,string>
요청에 포함할 커스텀 헤더예요.
-
fetch (input: RequestInfo, init?: RequestInit) => Promise<Response>
커스텀 fetch 구현이에요. 요청을 가로채는 미들웨어로 사용하거나, 예를 들어 테스트용 커스텀 fetch 구현을 제공할 수 있어요.
언어 모델 (Language Models)
프로바이더 인스턴스를 사용해 Vertex AI를 거쳐 Anthropic API를 호출하는 모델을 만들 수 있어요. 첫 번째 인자는 모델 ID이며, 예를 들어 claude-3-sonnet@20240229처럼 사용해요:
const model = anthropicVertex('claude-3-sonnet@20240229');
예시: 텍스트 생성 (Generate Text)
AnthropicVertex 언어 모델을 사용해 generateText 함수로 텍스트를 생성할 수 있어요:
import { anthropicVertex } from 'anthropic-vertex-ai';
import { generateText } from 'ai';
const { text } = await generateText({
model: anthropicVertex('claude-3-sonnet@20240229'),
prompt: 'Write a vegetarian lasagna recipe for 4 people.',
});
AnthropicVertex 언어 모델은 streamText 함수에서도 사용할 수 있고, Output을 이용한 구조화된 데이터 생성도 지원해요(AI SDK Core에서 자세한 내용을 확인할 수 있어요).
모델 기능 (Model Capabilities)
| 모델 | 이미지 입력 | 객체 생성 | 도구 사용 | 도구 스트리밍 |
|---|---|---|---|---|
claude-3-5-sonnet@20240620 |
||||
claude-3-opus@20240229 |
||||
claude-3-sonnet@20240229 |
||||
claude-3-haiku@20240307 |
환경 변수 (Environment Variables)
AnthropicVertex 프로바이더를 사용하려면 다음 환경 변수를 설정해야 해요:
GOOGLE_VERTEX_REGION: Google Vertex 리전 (예: 'us-central1')GOOGLE_VERTEX_PROJECT_ID: Google Cloud 프로젝트 ID
이 변수들은 환경이나 프로젝트 루트의 .env 파일에 설정해 주세요.
인증 (Authentication)
AnthropicVertex 프로바이더는 Google Cloud 인증을 사용해요. Google Cloud 자격 증명을 올바르게 설정했는지 확인해 주세요. 서비스 계정 키 파일이나 기본 애플리케이션 자격 증명(application default credentials) 중 하나를 사용할 수 있어요.
인증 설정에 대한 자세한 내용은 Google Cloud 인증 가이드를 참고하세요.