Firebase SDK의 Vertex AI GA 버전에서 Firebase AI 로직 SDK로 마이그레이션


Firebase AI Logic 및 클라이언트 SDK의 이전 명칭은 'Vertex AI in Firebase'였습니다. 확장된 서비스와 기능 (예: 이제 Gemini Developer API를 지원함)을 더 잘 반영하기 위해 서비스의 이름을 바꾸고 Firebase AI Logic로 리패키징했습니다.

모바일 또는 웹 앱에서 Google의 생성형 AI 모델에 안전하게 직접 액세스하려면 이제 'Gemini API' 제공업체(오래된 Vertex AI Gemini API 또는 이제 Gemini Developer API)를 선택할 수 있습니다. 즉, 이제 합리적인 요금 한도와 할당량이 있는 무료 등급을 제공하는 Gemini Developer API를 사용할 수 있습니다.

Firebase AI Logic SDK로 이전하는 단계 개요

  • 1단계: 앱 및 사용 사례에 가장 적합한 'Gemini API' 제공업체를 선택합니다.

  • 2단계: Gemini Developer API를 사용할 수 있도록 Firebase 프로젝트를 설정합니다.
    Vertex AI Gemini API 대신 Gemini Developer API를 사용하도록 전환하는 경우에만 적용됩니다.

  • 3단계: 앱에서 사용되는 라이브러리를 업데이트합니다.

  • 4단계: 앱에서 초기화를 업데이트합니다.

  • 5단계: 사용하는 기능에 따라 코드를 업데이트합니다.

1단계: 앱에 가장 적합한 'Gemini API' 제공업체 선택

이 이전을 통해 'Gemini API' 제공업체를 선택할 수 있습니다.

  • 이전 'Vertex AI in Firebase' SDK는 Vertex AI Gemini API만 사용할 수 있었습니다.

  • Firebase AI Logic SDK를 사용하면 모바일 또는 웹 앱에서 직접 호출할 'Gemini API' 제공자(Gemini Developer API 또는 Vertex AI Gemini API)를 선택할 수 있습니다.

특히 지원되는 기능, 가격, 요금 한도 측면에서 Gemini API 제공업체를 사용하는 것의 차이를 검토하세요. 한 가지 예로 Gemini Developer APICloud Storage URL을 사용하여 파일을 제공하는 것을 지원하지 않지만 무료 등급과 합리적인 할당량을 활용하려는 경우 좋은 선택일 수 있습니다.

2단계: Gemini Developer API를 사용할 수 있도록 Firebase 프로젝트 설정

이 단계는 Firebase AI Logic 클라이언트 SDK에서 Gemini Developer API를 사용하도록 전환하려는 경우에만 필요합니다. 하지만 Vertex AI Gemini API를 계속 사용하려면 다음 단계로 건너뜁니다.

프로젝트에서 두 'Gemini API' 제공자를 동시에 사용 설정해도 됩니다.

  1. Firebase 콘솔에서 Firebase AI Logic 페이지로 이동합니다.

  2. 설정 탭으로 이동하여 Gemini Developer API를 선택합니다.

  3. Gemini Developer API를 사용 설정합니다.

    콘솔에서 필요한 API가 사용 설정되었는지 확인하고 Firebase 프로젝트에 Gemini API 키를 생성합니다.
    Gemini API 키를 앱의 코드베이스에 추가하지 마세요. 자세히 알아보기

  4. 이 이전 가이드를 계속하여 앱의 라이브러리와 초기화를 업데이트합니다.

3단계: 앱에서 사용되는 라이브러리 업데이트

Firebase AI Logic 라이브러리를 사용하도록 앱의 코드베이스를 업데이트합니다.

Swift

  1. 앱 프로젝트를 연 상태로 Xcode에서 다음 옵션 중 하나를 사용하여 Firebase 패키지를 v11.13.0 이상으로 업데이트합니다.

    • 옵션 1: 모든 패키지 업데이트: 파일 > 패키지 > 최신 패키지 버전으로 업데이트로 이동합니다.

    • 옵션 2: Firebase 개별 업데이트: 패키지 종속 항목 섹션에서 Firebase 패키지로 이동합니다. Firebase 패키지를 마우스 오른쪽 버튼으로 클릭한 다음 패키지 업데이트를 선택합니다.

  2. 이제 Firebase 패키지에 v11.13.0 이상이 표시되는지 확인합니다. 그렇지 않으면 지정된 패키지 요구사항이 v11.13.0 이상으로 업데이트할 수 있도록 허용하는지 확인합니다.

  3. Project Editor에서 앱의 타겟을 선택한 다음 프레임워크, 라이브러리, 삽입된 콘텐츠 섹션으로 이동합니다.

  4. 새 라이브러리 추가: + 버튼을 선택한 다음 Firebase 패키지에서 FirebaseAI를 추가합니다.

  5. 앱 이전을 완료한 후 (이 가이드의 나머지 섹션 참고) 이전 라이브러리를 삭제해야 합니다.
    FirebaseVertexAI를 선택한 다음 버튼을 누릅니다.

Kotlin

  1. 모듈 (앱 수준) Gradle 파일 (일반적으로 <project>/<app-module>/build.gradle.kts 또는 <project>/<app-module>/build.gradle)에서 이전 종속 항목(해당하는 경우)을 다음으로 바꿉니다.

    이전 종속 항목을 삭제하기 전에 앱의 코드베이스를 이전하는 것이 더 쉬울 수 있습니다 (이 가이드의 나머지 섹션 참고).

    // BEFORE
    dependencies {
      implementation(platform("com.google.firebase:firebase-bom:33.x.y"))
      implementation("com.google.firebase:firebase-vertexai")
      // OR if not using the BoM
      implementation("com.google.firebase:firebase-vertexai:16.x.y")
    }
    
    
    // AFTER
    dependencies {
      // Import the BoM for the Firebase platform
      implementation(platform("com.google.firebase:firebase-bom:33.14.0"))
    
      // Add the dependency for the Firebase AI Logic library
      // When using the BoM, you don't specify versions in Firebase library dependencies
      implementation("com.google.firebase:firebase-ai")
    }
  2. Android 프로젝트를 Gradle 파일과 동기화합니다.

Firebase Android BoM를 사용하지 않으려면 firebase-ai 라이브러리의 종속 항목을 추가하고 Android 스튜디오에서 제안하는 최신 버전을 수락하면 됩니다.

Java

  1. 모듈 (앱 수준) Gradle 파일 (일반적으로 <project>/<app-module>/build.gradle.kts 또는 <project>/<app-module>/build.gradle)에서 이전 종속 항목(해당하는 경우)을 다음으로 바꿉니다.

    이전 종속 항목을 삭제하기 전에 앱의 코드베이스를 이전하는 것이 더 쉬울 수 있습니다 (이 가이드의 나머지 섹션 참고).

    // BEFORE
    dependencies {
      implementation(platform("com.google.firebase:firebase-bom:33.x.y"))
      implementation("com.google.firebase:firebase-vertexai")
      // OR if not using the BoM
      implementation("com.google.firebase:firebase-vertexai:16.x.y")
    }
    
    
    // AFTER
    dependencies {
      // Import the BoM for the Firebase platform
      implementation(platform("com.google.firebase:firebase-bom:33.14.0"))
    
      // Add the dependency for the Firebase AI Logic library
      // When using the BoM, you don't specify versions in Firebase library dependencies
      implementation("com.google.firebase:firebase-ai")
    }
  2. Android 프로젝트를 Gradle 파일과 동기화합니다.

Firebase Android BoM를 사용하지 않으려면 firebase-ai 라이브러리의 종속 항목을 추가하고 Android 스튜디오에서 제안하는 최신 버전을 수락하면 됩니다.

Web

  1. npm을 사용하여 웹용 Firebase JS SDK의 최신 버전을 가져옵니다.

    npm i firebase@latest

    또는

    yarn add firebase@latest
  2. 라이브러리를 가져온 위치에서 가져오기 문을 업데이트하여 대신 firebase/ai를 사용합니다.

    이전 가져오기를 삭제하기 전에 앱의 코드베이스를 이전하는 것이 더 쉬울 수 있습니다 (이 가이드의 나머지 섹션 참고).

    // BEFORE
    import { initializeApp } from "firebase/app";
    import { getVertexAI, getGenerativeModel } from "firebase/vertexai";
    
    
    // AFTER
    import { initializeApp } from "firebase/app";
    import { getAI, getGenerativeModel } from "firebase/ai";

Dart

  1. Flutter 프로젝트 디렉터리에서 다음 명령어를 실행하여 pubspec.yaml 파일에서 firebase_ai 패키지를 사용하도록 업데이트합니다.

    flutter pub add firebase_ai
  2. Flutter 프로젝트를 다시 빌드합니다.

    flutter run
  3. 앱 이전을 완료한 후 (이 가이드의 나머지 섹션 참고) 이전 패키지를 삭제해야 합니다.

    flutter pub remove firebase_vertexai

Unity

'Vertex AI in Firebase'에서 Unity 지원을 사용할 수 없었습니다.

Unity용 Firebase AI Logic SDK를 시작하는 방법을 알아보세요.

4단계: 앱에서 초기화 업데이트

Gemini API 제공업체를 클릭하여 이 페이지에서 제공업체별 콘텐츠와 코드를 확인합니다.

선택한 API 제공업체의 서비스를 초기화하는 방법을 업데이트하고 GenerativeModel 인스턴스를 만듭니다.

Swift


import FirebaseAI

// Initialize the Gemini Developer API backend service
let ai = FirebaseAI.firebaseAI(backend: .googleAI())

// Create a `GenerativeModel` instance with a model that supports your use case
let model = ai.generativeModel(modelName: "gemini-2.0-flash")

Kotlin


// Initialize the Gemini Developer API backend service
// Create a `GenerativeModel` instance with a model that supports your use case
val model = Firebase.ai(backend = GenerativeBackend.googleAI())
                        .generativeModel("gemini-2.0-flash")

Java


// Initialize the Gemini Developer API backend service
// Create a `GenerativeModel` instance with a model that supports your use case
GenerativeModel ai = FirebaseAI.getInstance(GenerativeBackend.googleAI())
        .generativeModel("gemini-2.0-flash");

// Use the GenerativeModelFutures Java compatibility layer which offers
// support for ListenableFuture and Publisher APIs
GenerativeModelFutures model = GenerativeModelFutures.from(ai);

Web


import { initializeApp } from "firebase/app";
import { getAI, getGenerativeModel, GoogleAIBackend } from "firebase/ai";

// TODO(developer) Replace the following with your app's Firebase configuration
// See: https://firebase.google.com/docs/web/learn-more#config-object
const firebaseConfig = {
  // ...
};

// Initialize FirebaseApp
const firebaseApp = initializeApp(firebaseConfig);

// Initialize the Gemini Developer API backend service
const ai = getAI(firebaseApp, { backend: new GoogleAIBackend() });

// Create a `GenerativeModel` instance with a model that supports your use case
const model = getGenerativeModel(ai, { model: "gemini-2.0-flash" });

Dart


import 'package:firebase_ai/firebase_ai.dart';
import 'package:firebase_core/firebase_core.dart';
import 'firebase_options.dart';

// Initialize FirebaseApp
await Firebase.initializeApp(
  options: DefaultFirebaseOptions.currentPlatform,
);

// Initialize the Gemini Developer API backend service
// Create a `GenerativeModel` instance with a model that supports your use case
final model =
      FirebaseAI.googleAI().generativeModel(model: 'gemini-2.0-flash');

Unity

'Vertex AI in Firebase'에서 Unity 지원을 사용할 수 없었습니다.

Unity용 Firebase AI Logic SDK를 시작하는 방법을 알아보세요.

사용 중인 기능에 따라 GenerativeModel 인스턴스가 항상 생성되지 않을 수 있습니다.

5단계: 사용하는 기능에 따라 코드 업데이트

이 단계에서는 사용하는 기능에 따라 필요할 수 있는 변경사항을 설명합니다.

  • Cloud Storage URL을 사용하고 이번 이전에서 Gemini Developer API를 사용하도록 전환한 경우 파일을 인라인 데이터로 포함하도록(또는 동영상에 YouTube URL을 사용하도록) 멀티모달 요청을 업데이트해야 합니다.

  • Firebase AI Logic SDK를 사용하기 위해 코드에서 변경해야 할 사항이 있는지 다음 목록을 검토합니다.

Swift

추가 변경사항이 없습니다.

Kotlin

  • Live API

    • enum 클래스 ResponseModalityUNSPECIFIED 값을 삭제했습니다. 대신 null를 사용하세요.

Java

  • Live API

    • enum 클래스 ResponseModalityUNSPECIFIED 값을 삭제했습니다. 대신 null를 사용하세요.
  • 이제 void 대신 클래스의 인스턴스를 올바르게 반환하도록 다양한 Java 빌더 메서드를 변경했습니다.

Web

Vertex AI Gemini API 대신 Gemini Developer API를 사용하기 시작하는 경우에만 변경이 필요합니다.

  • 안전 설정

    • 지원되지 않는 SafetySetting.method의 사용을 삭제했습니다.
  • 인라인 데이터

    • 지원되지 않는 InlineDataPart.videoMetadata의 사용을 삭제했습니다.

Dart

추가 변경사항이 없습니다.

Unity

'Vertex AI in Firebase'에서 Unity 지원을 받을 수 없습니다.

Unity용 Firebase AI Logic SDK를 시작하는 방법을 알아보세요.


Firebase AI Logic 사용 경험에 관한 의견 보내기