Google 생성형 AI 플러그인은 Gemini API를 통해 Google의 Gemini 모델에 대한 인터페이스를 제공합니다.
설치
npm i --save @genkit-ai/googleai
구성
이 플러그인을 사용하려면 configureGenkit()
를 호출할 때 지정합니다.
import { googleAI } from '@genkit-ai/googleai';
export default configureGenkit({
plugins: [googleAI()],
// ...
});
플러그인에는 Gemini API용 API 키가 필요하며 Google AI Studio에서 가져올 수 있습니다.
다음 중 하나를 수행하여 API 키를 사용하도록 플러그인을 구성합니다.
GOOGLE_GENAI_API_KEY
환경 변수를 API 키로 설정합니다.플러그인을 초기화할 때 API 키를 지정합니다.
googleAI({ apiKey: yourKey });
하지만 API 키를 코드에 직접 삽입하지 마세요. Cloud Secret Manager 또는 이와 유사한 서비스에서만 함께 사용할 수 있습니다
일부 모델 (예: Gemini 1.5 Pro)은 프리뷰 버전이며
v1beta
API를 사용합니다. apiVersion
를 지정하여 이러한 모델에 액세스할 수 있습니다.
configureGenkit({
plugins: [googleAI({ apiVersion: 'v1beta' })],
});
또는 다른 버전의 광고를 사용하고 싶은 경우 여러 버전을 지정할 수 있습니다. 동시에 사용할 수 있습니다.
configureGenkit({
plugins: [googleAI({ apiVersion: ['v1', 'v1beta'] })],
});
용도
이 플러그인은 지원되는 모델에 대한 참조를 정적으로 내보냅니다.
import {
gemini15Flash,
gemini15Pro,
textEmbeddingGecko001,
} from '@genkit-ai/googleai';
이러한 참조를 사용하여 generate()
에서 사용할 모델을 지정할 수 있습니다.
const llmResponse = await generate({
model: gemini15Flash,
prompt: 'Tell me a joke.',
});
또는 임베딩을 사용합니다 (예: textEmbeddingGecko001
)를 embed
또는 검색기와 함께 사용합니다.
const embedding = await embed({
embedder: textEmbeddingGecko001,
content: input,
});
Gemini 파일 API
Genkit를 통해 Gemini Files API에 업로드된 파일을 사용할 수 있습니다.
import { GoogleAIFileManager } from '@google/generative-ai/server';
const fileManager = new GoogleAIFileManager(process.env.GOOGLE_GENAI_API_KEY);
const uploadResult = await fileManager.uploadFile(
'path/to/file.jpg',
{
mimeType: 'image/jpeg',
displayName: 'Your Image',
}
);
const response = await generate({
model: gemini15Flash,
prompt: [
{text: 'Describe this image:'},
{media: {contentType: uploadResult.file.mimeType, url: uploadResult.file.uri}}
]
});