이 가이드에서는 선택한 플랫폼의 Vertex AI in Firebase SDK를 사용하여 앱에서 직접 Vertex AI Gemini API를 호출하는 방법을 설명합니다.
Gemini API를 사용하는 기타 옵션
원하는 경우 Gemini API
의 대체 'Google AI' 버전을 실험해 보세요. Google AI Studio 및 Google AI 클라이언트 SDK를 사용하여 무료 액세스 권한을 얻을 수 있습니다(한도 내에서, 사용 가능한 경우). 이러한 SDK는 모바일 및 웹 앱에서 프로토타입 제작 전용으로 사용해야 합니다.Gemini API의 작동 방식을 숙지한 후 Vertex AI in Firebase SDK로 이전하세요(이 문서). Firebase App Check를 사용하여 API 악용으로부터 보호하고 요청의 대용량 미디어 파일을 지원하는 등 모바일 및 웹 앱에 중요한 여러 추가 기능이 있습니다.
Vertex AI Gemini API 서버 측을 호출할 수도 있습니다(예: Python, Node.js 또는 Go).
Gemini API에 서버 측 Vertex AI SDK, Firebase Genkit 또는 Firebase Extensions를 사용합니다.
기본 요건
이 가이드에서는 Android 스튜디오를 사용하여 Android용 앱을 개발하는 데 익숙하다고 가정합니다.
개발 환경과 Android 앱이 다음 요구사항을 충족하는지 확인합니다.
- Android 스튜디오 (최신 버전)
- Android 앱이 API 수준 21 이상을 타겟팅해야 합니다.
(선택사항) 샘플 앱을 확인합니다.
SDK를 빠르게 사용해 보거나 다양한 사용 사례의 전체 구현을 확인하거나 자체 Android 앱이 없는 경우 샘플 앱을 사용할 수 있습니다. 샘플 앱을 사용하려면 Firebase 프로젝트에 연결해야 합니다.
1단계: Firebase 프로젝트 설정 및 앱을 Firebase에 연결
Firebase 프로젝트와 Firebase에 연결된 앱이 이미 있는 경우
Firebase 콘솔에서 Gemini로 빌드 페이지로 이동합니다.
Vertex AI in Firebase 카드를 클릭하여 다음 작업을 완료하는 데 도움이 되는 워크플로를 실행합니다.
사용한 만큼만 지불하는 Blaze 요금제를 사용하도록 프로젝트를 업그레이드합니다.
프로젝트에서 필요한 API (Vertex AI API 및 Vertex AI in Firebase API)를 사용 설정합니다.
이 가이드의 다음 단계로 진행하여 앱에 SDK를 추가합니다.
아직 Firebase 프로젝트와 Firebase에 연결된 앱이 없는 경우
Firebase 프로젝트 설정
Firebase Console에 로그인합니다.
프로젝트 만들기를 클릭하고 다음 옵션 중 하나를 사용합니다.
옵션 1: '프로젝트 만들기' 워크플로의 첫 번째 단계에서 새 프로젝트 이름을 입력하여 완전히 새로운 Firebase 프로젝트 (및 기본 Google Cloud 프로젝트 자동 생성)를 만듭니다.
옵션 2: '프로젝트 만들기' 워크플로의 첫 번째 단계에서 드롭다운 메뉴에서 Google Cloud 프로젝트 이름을 선택하여 기존 Google Cloud 프로젝트에 'Firebase를 추가'합니다.
메시지가 표시되면 Vertex AI in Firebase SDK를 사용하기 위해 Google Analytics를 설정하지 않아도 됩니다.
Firebase 콘솔에서 Gemini로 빌드 페이지로 이동합니다.
Vertex AI in Firebase 카드를 클릭하여 다음 작업을 완료하는 데 도움이 되는 워크플로를 실행합니다.
사용한 만큼만 지불하는 Blaze 요금제를 사용하도록 프로젝트를 업그레이드합니다.
프로젝트에서 필요한 API (Vertex AI API 및 Vertex AI in Firebase API)를 사용 설정합니다.
Firebase에 앱 연결
Console의 생성형 AI 워크플로를 계속 진행하여 앱을 Firebase에 연결합니다. 여기에는 다음 작업이 포함됩니다.
Firebase 프로젝트에 앱 등록
Firebase 구성 파일(
) 및google-services.json
Gradle 플러그인을 앱에 추가합니다.google-services
이 가이드의 다음 단계에서는 앱에 Vertex AI in Firebase SDK를 추가하고 SDK 및 Gemini API 사용과 관련된 필수 초기화를 완료합니다.
2단계: SDK 추가
Firebase 프로젝트가 설정되고 앱이 Firebase에 연결되면(이전 단계 참고) 이제 앱에 Vertex AI in Firebase SDK를 추가할 수 있습니다.
Android용 Vertex AI in Firebase SDK (firebase-vertexai
)는 Vertex AI Gemini API에 대한 액세스를 제공합니다.
모듈 (앱 수준) Gradle 파일(예: <project>/<app-module>/build.gradle.kts
)에서 Android용 Vertex AI in Firebase 라이브러리의 종속 항목을 추가합니다.
라이브러리 버전 관리 제어에는 Firebase Android BoM을 사용하는 것이 좋습니다.
dependencies { // ... other androidx dependencies // Import the BoM for the Firebase platform implementation(platform("com.google.firebase:firebase-bom:33.9.0")) // Add the dependency for the Vertex AI in Firebase library // When using the BoM, you don't specify versions in Firebase library dependencies implementation("com.google.firebase:firebase-vertexai") }
Java의 경우 라이브러리를 두 개 더 추가해야 합니다.
dependencies { // ... other androidx dependencies // Import the BoM for the Firebase platform implementation(platform("com.google.firebase:firebase-bom:33.9.0")) // Add the dependency for the Vertex AI in Firebase library // When using the BoM, you don't specify versions in Firebase library dependencies implementation("com.google.firebase:firebase-vertexai") // Required for one-shot operations (to use `ListenableFuture` from Guava Android) implementation("com.google.guava:guava:31.0.1-android") // Required for streaming operations (to use `Publisher` from Reactive Streams) implementation("org.reactivestreams:reactive-streams:1.0.4") }
Firebase Android BoM을 사용하면 앱에서 항상 호환되는 Firebase Android 라이브러리 버전을 사용합니다.
(대안) BoM을 사용하지 않고 Firebase 라이브러리 종속 항목을 추가합니다.
Firebase BoM을 사용하지 않도록 선택한 경우에는 종속 항목 줄에 각 Firebase 라이브러리 버전을 지정해야 합니다.
앱에서 여러 Firebase 라이브러리를 사용하는 경우 모든 버전이 호환되도록 BoM을 사용하여 라이브러리 버전을 관리하는 것이 좋습니다.
dependencies { // Add the dependency for the Vertex AI in Firebase library // When NOT using the BoM, you must specify versions in Firebase library dependencies implementation("com.google.firebase:firebase-vertexai:16.1.0") }
3단계: Vertex AI 서비스 및 생성형 모델 초기화
API를 호출하려면 먼저 Vertex AI 서비스와 생성 모델을 초기화해야 합니다.
// Initialize the Vertex AI service and the generative model
// Specify a model that supports your use case
val generativeModel = Firebase.vertexAI.generativeModel("gemini-2.0-flash")
Publisher
유형을 반환합니다.
// Initialize the Vertex AI service and the generative model
// Specify a model that supports your use case
GenerativeModel gm = FirebaseVertexAI.getInstance()
.generativeModel("gemini-2.0-flash");
// Use the GenerativeModelFutures Java compatibility layer which offers
// support for ListenableFuture and Publisher APIs
GenerativeModelFutures model = GenerativeModelFutures.from(gm);
시작 가이드를 완료한 후 사용 사례 및 앱에 적합한 Gemini 모델과 (선택사항) 위치를 선택하는 방법을 알아봅니다.
4단계: Vertex AI Gemini API 호출
이제 앱을 Firebase에 연결하고, SDK를 추가하고, Vertex AI 서비스와 생성형 모델을 초기화했으므로 Vertex AI Gemini API를 호출할 수 있습니다.
generateContent()
를 사용하여 텍스트 전용 프롬프트 요청에서 텍스트를 생성할 수 있습니다.
// Initialize the Vertex AI service and the generative model
// Specify a model that supports your use case
val generativeModel = Firebase.vertexAI.generativeModel("gemini-2.0-flash")
// Provide a prompt that contains text
val prompt = "Write a story about a magic backpack."
// To generate text output, call generateContent with the text input
val response = generativeModel.generateContent(prompt)
print(response.text)
ListenableFuture
를 반환합니다.
// Initialize the Vertex AI service and the generative model
// Specify a model that supports your use case
GenerativeModel gm = FirebaseVertexAI.getInstance()
.generativeModel("gemini-2.0-flash");
GenerativeModelFutures model = GenerativeModelFutures.from(gm);
// Provide a prompt that contains text
Content prompt = new Content.Builder()
.addText("Write a story about a magic backpack.")
.build();
// To generate text output, call generateContent with the text input
ListenableFuture<GenerateContentResponse> response = model.generateContent(prompt);
Futures.addCallback(response, new FutureCallback<GenerateContentResponse>() {
@Override
public void onSuccess(GenerateContentResponse result) {
String resultText = result.getText();
System.out.println(resultText);
}
@Override
public void onFailure(Throwable t) {
t.printStackTrace();
}
}, executor);
또 뭘 할 수 있니?
Gemini 모델 자세히 알아보기
다양한 사용 사례에 사용할 수 있는 모델과 할당량 및 가격에 대해 알아보세요.
Gemini API의 다른 기능 사용해 보기
- 응답을 스트리밍하는 방법을 비롯하여 텍스트 전용 프롬프트에서 텍스트를 생성하는 방법을 자세히 알아보세요.
- 멀티모달 프롬프트(텍스트, 이미지, PDF, 동영상, 오디오 포함)에서 텍스트를 생성합니다.
- 멀티턴 대화 (채팅)를 빌드합니다.
- 텍스트 및 멀티모달 프롬프트에서 구조화된 출력 (예: JSON)을 생성합니다.
- 함수 호출을 사용하여 생성형 모델을 외부 시스템 및 정보에 연결합니다.
콘텐츠 생성을 제어하는 방법 알아보기
- 권장사항, 전략, 프롬프트 예시를 포함하여 프롬프트 설계 이해하기
- 온도 및 최대 출력 토큰과 같은 모델 매개변수를 구성합니다.
- 안전 설정을 사용하여 유해하다고 간주될 수 있는 대답이 표시될 가능성을 조정합니다.
Vertex AI in Firebase 사용 경험에 관한 의견 보내기