튜토리얼: Gemini API 시작하기


이 튜토리얼에서는 Android용 Google AI 클라이언트 SDK를 사용하는 Android 앱 이 클라이언트 SDK를 사용하는 것이 좋습니다. (예: Python)을 사용하여 Android 앱에서 Gemini 모델에 액세스할 수 있습니다.

이 튜토리얼에서는 다음 작업을 수행하는 방법을 알아봅니다.

또한 이 튜토리얼에는 고급 사용 사례 (예: 토큰 계산) 및 콘텐츠 생성을 제어할 수 있습니다.

기기에서 Gemini 사용을 고려해 보세요

이 튜토리얼에서 설명하는 Android용 클라이언트 SDK를 사용하면 Google 서버에서 실행되는 Gemini Pro 모델입니다. 배포와 관련된 사용 사례의 경우 민감한 정보 처리, 오프라인 가용성 또는 비용 절감을 위해 사용자 플로우가 궁금하다면 Gemini Nano에 액세스하는 것이 좋습니다 이는 기기에서 실행됩니다. 자세한 내용은 Android (기기 내) 튜토리얼

기본 요건

이 튜토리얼에서는 Android 스튜디오를 사용하여 문제를 해결하는 데 익숙하다고 가정합니다. 여러분도 아시게 될 겁니다

이 튜토리얼을 완료하려면 개발 환경과 Android 앱은 다음 요구사항을 충족해야 합니다.

  • Android 스튜디오 (최신 버전)
  • Android 앱은 API 수준 21 이상을 타겟팅해야 합니다.

프로젝트 설정

Gemini API를 호출하기 전에 Android 프로젝트를 설정해야 합니다. 여기에는 API 키 설정, Android 라이브러리에 SDK 종속 항목 추가가 포함됩니다. 초기화하고 시작할 수 있습니다.

API 키 설정

Gemini API를 사용하려면 API 키가 필요합니다. 아직 계정이 없는 경우 Google AI Studio에서 키를 만듭니다

API 키 가져오기

API 키 보호

버전에 API 키를 체크인하지 않는 것이 좋습니다. 제어할 수 있습니다 대신 local.properties 파일에 저장해야 합니다. (프로젝트의 루트 디렉터리에 있지만 버전에서 제외된) 컨트롤)에서 Android용 Secrets Gradle 플러그인 API 키를 빌드 구성 변수로 읽습니다.

Kotlin

// Access your API key as a Build Configuration variable
val apiKey = BuildConfig.apiKey

자바

// Access your API key as a Build Configuration variable
String apiKey = BuildConfig.apiKey;

이 튜토리얼의 모든 스니펫은 이 권장사항을 활용합니다. 또한 Secrets Gradle 플러그인의 구현을 확인하려면 샘플 앱 또는 Android 스튜디오 Iguana의 최신 미리보기 버전을 사용하세요. Gemini API Starter 템플릿 (시작하는 데 도움이 되는 local.properties 파일이 포함되어 있음)

프로젝트에 SDK 종속 항목 추가

  1. 모듈 (앱 수준) Gradle 구성 파일 (예: <project>/<app-module>/build.gradle.kts)가 포함된 Android용 Google AI SDK:

    Kotlin

    dependencies {
      // ... other androidx dependencies
    
      // add the dependency for the Google AI client SDK for Android
      implementation("com.google.ai.client.generativeai:generativeai:0.9.0")
    }
    

    자바

    Java의 경우 라이브러리를 두 개 더 추가해야 합니다.

    dependencies {
        // ... other androidx dependencies
    
        // add the dependency for the Google AI client SDK for Android
        implementation("com.google.ai.client.generativeai:generativeai:0.9.0")
    
        // 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")
    }
    
  2. Android 프로젝트를 Gradle 파일과 동기화합니다.

생성 모델 초기화

API 호출을 하려면 먼저 생성 모델을 초기화해야 합니다.

Kotlin

val generativeModel = GenerativeModel(
    // The Gemini 1.5 models are versatile and work with most use cases
    modelName = "gemini-1.5-flash",
    // Access your API key as a Build Configuration variable (see "Set up your API key" above)
    apiKey = BuildConfig.apiKey
)

자바

Java의 경우 GenerativeModelFutures 객체도 초기화해야 합니다.

// Use a model that's applicable for your use case
// The Gemini 1.5 models are versatile and work with most use cases
GenerativeModel gm = new GenerativeModel(/* modelName */ "gemini-1.5-flash",
// Access your API key as a Build Configuration variable (see "Set up your API key" above)
    /* apiKey */ BuildConfig.apiKey);

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

모델을 지정할 때는 다음 사항에 유의하세요.

  • 사용 사례에 맞는 모델을 사용하세요 (예: gemini-1.5-flash). 멀티모달 입력용). 본 가이드에 나와 있는 각 각 사용 사례의 추천 모델을 나열합니다.

일반적인 사용 사례 구현

이제 프로젝트가 설정되었으므로 Gemini API를 사용하여 다양한 사용 사례 구현:

텍스트 전용 입력에서 텍스트 생성

프롬프트 입력에 텍스트만 포함된 경우에는 Gemini 1.5 모델을 사용하거나 generateContent를 사용하여 텍스트 출력을 생성하는 Gemini 1.0 Pro 모델:

Kotlin

generateContent()는 정지 함수이며 다음과 같아야 합니다. 코루틴 범위에서 호출됩니다. 코루틴에 익숙하지 않다면 다음을 참조하세요. Android의 Kotlin 코루틴

val generativeModel = GenerativeModel(
    // The Gemini 1.5 models are versatile and work with both text-only and multimodal prompts
    modelName = "gemini-1.5-flash",
    // Access your API key as a Build Configuration variable (see "Set up your API key" above)
    apiKey = BuildConfig.apiKey
)

val prompt = "Write a story about a magic backpack."
val response = generativeModel.generateContent(prompt)
print(response.text)

자바

generateContent()ListenableFuture를 반환합니다. 만약 이 API에 익숙하지 않은 경우 자세한 내용은 Android 설명서를 ListenableFuture 사용.

// The Gemini 1.5 models are versatile and work with both text-only and multimodal prompts
GenerativeModel gm = new GenerativeModel(/* modelName */ "gemini-1.5-flash",
// Access your API key as a Build Configuration variable (see "Set up your API key" above)
    /* apiKey */ BuildConfig.apiKey);
GenerativeModelFutures model = GenerativeModelFutures.from(gm);

Content content = new Content.Builder()
    .addText("Write a story about a magic backpack.")
    .build();

Executor executor = // ...

ListenableFuture<GenerateContentResponse> response = model.generateContent(content);
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 1.5 모델)을 지원하여 텍스트와 이미지를 모두 입력할 수 있습니다. 반드시 프롬프트의 이미지 요구사항을 검토하세요.

프롬프트 입력에 텍스트와 이미지가 모두 포함된 경우 generateContent: 텍스트 출력을 생성합니다.

Kotlin

generateContent()는 정지 함수이며 다음과 같아야 합니다. 코루틴 범위에서 호출됩니다. 코루틴에 익숙하지 않다면 다음을 참조하세요. Android의 Kotlin 코루틴

val generativeModel = GenerativeModel(
    // The Gemini 1.5 models are versatile and work with both text-only and multimodal prompts
    modelName = "gemini-1.5-flash",
    // Access your API key as a Build Configuration variable (see "Set up your API key" above)
    apiKey = BuildConfig.apiKey
)

val image1: Bitmap = // ...
val image2: Bitmap = // ...

val inputContent = content {
    image(image1)
    image(image2)
    text("What's different between these pictures?")
}

val response = generativeModel.generateContent(inputContent)
print(response.text)

자바

generateContent()ListenableFuture를 반환합니다. 만약 이 API에 익숙하지 않은 경우 자세한 내용은 Android 설명서를 ListenableFuture 사용.

// The Gemini 1.5 models are versatile and work with both text-only and multimodal prompts
GenerativeModel gm = new GenerativeModel(/* modelName */ "gemini-1.5-flash",
// Access your API key as a Build Configuration variable (see "Set up your API key" above)
    /* apiKey */ BuildConfig.apiKey);
GenerativeModelFutures model = GenerativeModelFutures.from(gm);

Bitmap image1 = // ...
Bitmap image2 = // ...

Content content = new Content.Builder()
    .addText("What's different between these pictures?")
    .addImage(image1)
    .addImage(image2)
    .build();

Executor executor = // ...

ListenableFuture<GenerateContentResponse> response = model.generateContent(content);
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를 사용하면 여러 차례에 걸쳐 자유 형식의 대화를 구축할 수 있습니다. 이 SDK는 대화 상태를 관리하여 프로세스를 간소화하므로 generateContent를 사용하면 대화 기록을 저장할 필요가 없습니다. 확인할 수 있습니다

채팅과 같은 멀티턴 대화를 빌드하려면 Gemini 1.5 모델 또는 Gemini 1.0 Pro 모델을 빌드하고 startChat()를 호출하여 채팅을 초기화합니다. 그런 다음 sendMessage()를 사용하여 새 사용자 메시지를 전송합니다. 이 메시지에는 채팅 기록에 대한 응답을 반환합니다.

role 대화:

  • user: 프롬프트를 제공하는 역할입니다. 이 값은 sendMessage 통화

  • model: 응답을 제공하는 역할입니다. 이 역할은 다음과 같은 경우에 사용할 수 있습니다. 기존 historystartChat()를 호출합니다.

Kotlin

generateContent()는 정지 함수이며 다음과 같아야 합니다. 코루틴 범위에서 호출됩니다. 코루틴에 익숙하지 않다면 다음을 참조하세요. Android의 Kotlin 코루틴

val generativeModel = GenerativeModel(
    // The Gemini 1.5 models are versatile and work with multi-turn conversations (like chat)
    modelName = "gemini-1.5-flash",
    // Access your API key as a Build Configuration variable (see "Set up your API key" above)
    apiKey = BuildConfig.apiKey
)

val chat = generativeModel.startChat(
    history = listOf(
        content(role = "user") { text("Hello, I have 2 dogs in my house.") },
        content(role = "model") { text("Great to meet you. What would you like to know?") }
    )
)

chat.sendMessage("How many paws are in my house?")

자바

generateContent()ListenableFuture를 반환합니다. 만약 이 API에 익숙하지 않은 경우 자세한 내용은 Android 설명서를 ListenableFuture 사용.

// The Gemini 1.5 models are versatile and work with multi-turn conversations (like chat)
GenerativeModel gm = new GenerativeModel(/* modelName */ "gemini-1.5-flash",
// Access your API key as a Build Configuration variable (see "Set up your API key" above)
    /* apiKey */ BuildConfig.apiKey);
GenerativeModelFutures model = GenerativeModelFutures.from(gm);

// (optional) Create previous chat history for context
Content.Builder userContentBuilder = new Content.Builder();
userContentBuilder.setRole("user");
userContentBuilder.addText("Hello, I have 2 dogs in my house.");
Content userContent = userContentBuilder.build();

Content.Builder modelContentBuilder = new Content.Builder();
modelContentBuilder.setRole("model");
modelContentBuilder.addText("Great to meet you. What would you like to know?");
Content modelContent = userContentBuilder.build();

List<Content> history = Arrays.asList(userContent, modelContent);

// Initialize the chat
ChatFutures chat = model.startChat(history);

// Create a new user message
Content.Builder userMessageBuilder = new Content.Builder();
userMessageBuilder.setRole("user");
userMessageBuilder.addText("How many paws are in my house?");
Content userMessage = userMessageBuilder.build();

Executor executor = // ...

// Send the message
ListenableFuture<GenerateContentResponse> response = chat.sendMessage(userMessage);

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);

스트리밍을 사용하여 상호작용 속도 향상

기본적으로 모델은 전체 생성이 완료된 후 응답을 반환합니다. 프로세스입니다 전체 응답을 기다리지 않아도 더 빠르게 상호작용을 할 수 있습니다. 대신 스트리밍을 사용하여 부분 결과를 처리합니다.

다음 예는 다음을 사용하여 스트리밍을 구현하는 방법을 보여줍니다. generateContentStream: 텍스트 및 이미지 입력 프롬프트에서 텍스트를 생성합니다.

Kotlin

generateContentStream()는 정지 함수이며 다음과 같아야 합니다. 코루틴 범위에서 호출됩니다. 코루틴에 익숙하지 않다면 다음을 참조하세요. Android의 Kotlin 코루틴

val generativeModel = GenerativeModel(
    // The Gemini 1.5 models are versatile and work with both text-only and multimodal prompts
    modelName = "gemini-1.5-flash",
    // Access your API key as a Build Configuration variable (see "Set up your API key" above)
    apiKey = BuildConfig.apiKey
)

val image1: Bitmap = // ...
val image2: Bitmap = // ...

val inputContent = content {
    image(image1)
    image(image2)
    text("What's the difference between these pictures?")
}

var fullResponse = ""
generativeModel.generateContentStream(inputContent).collect { chunk ->
    print(chunk.text)
    fullResponse += chunk.text
}

자바

이 SDK의 Java 스트리밍 메서드는 Publisher 유형을 반환합니다. Reactive Streams 있습니다.

// The Gemini 1.5 models are versatile and work with both text-only and multimodal prompts
GenerativeModel gm = new GenerativeModel(/* modelName */ "gemini-1.5-flash",
// Access your API key as a Build Configuration variable (see "Set up your API key" above)
    /* apiKey */ BuildConfig.apiKey);
GenerativeModelFutures model = GenerativeModelFutures.from(gm);

Bitmap image1 = // ...
Bitmap image2 = // ...

Content content = new Content.Builder()
    .addText("What's different between these pictures?")
    .addImage(image1)
    .addImage(image2)
    .build();

Publisher<GenerateContentResponse> streamingResponse =
    model.generateContentStream(content);

StringBuilder outputContent = new StringBuilder();

streamingResponse.subscribe(new Subscriber<GenerateContentResponse>() {
    @Override
    public void onNext(GenerateContentResponse generateContentResponse) {
        String chunk = generateContentResponse.getText();
        outputContent.append(chunk);
    }

    @Override
    public void onComplete() {
        System.out.println(outputContent);
    }

    @Override
    public void onError(Throwable t) {
        t.printStackTrace();
    }

    @Override
    public void onSubscribe(Subscription s) {
      s.request(Long.MAX_VALUE);
    }
});

텍스트 전용 입력 및 채팅 사용 사례에도 비슷한 접근 방식을 사용할 수 있습니다.

Kotlin

generateContentStream()는 정지 함수이며 다음과 같아야 합니다. 코루틴 범위에서 호출됩니다. 코루틴에 익숙하지 않다면 다음을 참조하세요. Android의 Kotlin 코루틴

// Use streaming with text-only input
generativeModel.generateContentStream(inputContent).collect { chunk ->
    print(chunk.text)
}
// Use streaming with multi-turn conversations (like chat)
val chat = generativeModel.startChat()
chat.sendMessageStream(inputContent).collect { chunk ->
    print(chunk.text)
}

자바

이 SDK의 Java 스트리밍 메서드는 Publisher 유형을 반환합니다. Reactive Streams 있습니다.

// Use streaming with text-only input
Publisher<GenerateContentResponse> streamingResponse =
    model.generateContentStream(inputContent);

StringBuilder outputContent = new StringBuilder();

streamingResponse.subscribe(new Subscriber<GenerateContentResponse>() {
    @Override
    public void onNext(GenerateContentResponse generateContentResponse) {
        String chunk = generateContentResponse.getText();
        outputContent.append(chunk);
    }

    @Override
    public void onComplete() {
        System.out.println(outputContent);
    }

    @Override
    public void onSubscribe(Subscription s) {
      s.request(Long.MAX_VALUE);
    }

    // ... other methods omitted for brevity
});
// Use streaming with multi-turn conversations (like chat)
ChatFutures chat = model.startChat(history);

Publisher<GenerateContentResponse> streamingResponse =
    chat.sendMessageStream(inputContent);

StringBuilder outputContent = new StringBuilder();

streamingResponse.subscribe(new Subscriber<GenerateContentResponse>() {
    @Override
    public void onNext(GenerateContentResponse generateContentResponse) {
        String chunk = generateContentResponse.getText();
        outputContent.append(chunk);
    }

    @Override
    public void onComplete() {
        System.out.println(outputContent);
    }

    @Override
    public void onSubscribe(Subscription s) {
      s.request(Long.MAX_VALUE);
    }

    // ... other methods omitted for brevity
});

고급 사용 사례 구현

이 튜토리얼의 이전 섹션에 설명된 일반적인 사용 사례는 Gemini API 사용에 익숙해지세요 이 섹션에서는 고급 사용 사례를 살펴보겠습니다

함수 호출

함수 호출을 통해 구조화된 데이터 출력을 더 쉽게 가져올 수 있음 살펴보겠습니다 그런 다음 이러한 출력을 사용하여 다른 API를 호출하고 모델에 전달합니다. 즉, 함수 호출은 생성 모델을 외부 시스템에 연결하여 생성된 콘텐츠가 가장 정확한 최신 정보가 포함됩니다. 자세히 알아보기: 함수 호출 튜토리얼을 참조하세요.

토큰 수 계산

긴 프롬프트를 사용할 때는 모델에 추가할 수 있습니다. 다음 예는 countTokens() 사용 방법을 보여줍니다. 다음과 같이 다양한 사용 사례에 활용할 수 있습니다.

Kotlin

countTokens()는 정지 함수이며 다음과 같아야 합니다. 코루틴 범위에서 호출됩니다. 코루틴에 익숙하지 않다면 다음을 참조하세요. Android의 Kotlin 코루틴

// For text-only input
val (totalTokens) = generativeModel.countTokens("Write a story about a magic backpack.")

// For text-and-image input (multi-modal)
val multiModalContent = content {
    image(image1)
    image(image2)
    text("What's the difference between these pictures?")
}

val (totalTokens) = generativeModel.countTokens(multiModalContent)

// For multi-turn conversations (like chat)
val history = chat.history
val messageContent = content { text("This is the message I intend to send")}
val (totalTokens) = generativeModel.countTokens(*history.toTypedArray(), messageContent)

자바

countTokens()ListenableFuture를 반환합니다. 만약 이 API에 익숙하지 않은 경우 자세한 내용은 Android 설명서를 ListenableFuture 사용.

Content text = new Content.Builder()
    .addText("Write a story about a magic backpack.")
    .build();

Executor executor = // ...

// For text-only input
ListenableFuture<CountTokensResponse> countTokensResponse = model.countTokens(text);

Futures.addCallback(countTokensResponse, new FutureCallback<CountTokensResponse>() {
    @Override
    public void onSuccess(CountTokensResponse result) {
        int totalTokens = result.getTotalTokens();
        System.out.println("TotalTokens = " + totalTokens);
    }

    @Override
    public void onFailure(Throwable t) {
        t.printStackTrace();
    }
}, executor);

// For text-and-image input
Bitmap image1 = // ...
Bitmap image2 = // ...

Content multiModalContent = new Content.Builder()
    .addImage(image1)
    .addImage(image2)
    .addText("What's different between these pictures?")
    .build();

ListenableFuture<CountTokensResponse> countTokensResponse = model.countTokens(multiModalContent);

// For multi-turn conversations (like chat)
List<Content> history = chat.getChat().getHistory();

Content messageContent = new Content.Builder()
    .addText("This is the message I intend to send")
    .build();

Collections.addAll(history, messageContent);

ListenableFuture<CountTokensResponse> countTokensResponse = model.countTokens(history.toArray(new Content[0]));

콘텐츠 생성을 제어하는 옵션

모델 매개변수를 구성하고 모델 매개변수를 사용하여 콘텐츠 생성을 제어할 수 있습니다. 안전 설정을 변경할 수 있습니다.

모델 매개변수 구성

모델로 보내는 모든 프롬프트에는 모델이 응답을 생성합니다. 모델은 서로 다른 매개변수 값에 대해 서로 다른 결과를 생성할 수 있습니다. 다음에 대해 자세히 알아보기 모델 매개변수.

Kotlin

val config = generationConfig {
    temperature = 0.9f
    topK = 16
    topP = 0.1f
    maxOutputTokens = 200
    stopSequences = listOf("red")
}

val generativeModel = GenerativeModel(
    // The Gemini 1.5 models are versatile and work with most use cases
    modelName = "gemini-1.5-flash",
    apiKey = BuildConfig.apiKey,
    generationConfig = config
)

자바

GenerationConfig.Builder configBuilder = new GenerationConfig.Builder();
configBuilder.temperature = 0.9f;
configBuilder.topK = 16;
configBuilder.topP = 0.1f;
configBuilder.maxOutputTokens = 200;
configBuilder.stopSequences = Arrays.asList("red");

GenerationConfig generationConfig = configBuilder.build();

// The Gemini 1.5 models are versatile and work with most use cases
GenerativeModel gm = new GenerativeModel(
    "gemini-1.5-flash",
    BuildConfig.apiKey,
    generationConfig
);

GenerativeModelFutures model = GenerativeModelFutures.from(gm);

안전 설정 사용

안전 설정을 사용하여 유해할 수 있습니다. 기본적으로 안전 설정은 매체가 포함된 콘텐츠를 차단합니다. 또는 모든 측정기준에서 안전하지 않은 콘텐츠일 가능성이 높음 알아보기 안전 설정에 관해 자세히 알아보세요.

하나의 안전 설정을 지정하는 방법은 다음과 같습니다.

Kotlin

val generativeModel = GenerativeModel(
    // The Gemini 1.5 models are versatile and work with most use cases
    modelName = "gemini-1.5-flash",
    apiKey = BuildConfig.apiKey,
    safetySettings = listOf(
        SafetySetting(HarmCategory.HARASSMENT, BlockThreshold.ONLY_HIGH)
    )
)

자바

SafetySetting harassmentSafety = new SafetySetting(HarmCategory.HARASSMENT,
    BlockThreshold.ONLY_HIGH);

// The Gemini 1.5 models are versatile and work with most use cases
GenerativeModel gm = new GenerativeModel(
    "gemini-1.5-flash",
    BuildConfig.apiKey,
    null, // generation config is optional
    Collections.singletonList(harassmentSafety)
);

GenerativeModelFutures model = GenerativeModelFutures.from(gm);

둘 이상의 안전 설정을 지정할 수도 있습니다.

Kotlin

val harassmentSafety = SafetySetting(HarmCategory.HARASSMENT, BlockThreshold.ONLY_HIGH)

val hateSpeechSafety = SafetySetting(HarmCategory.HATE_SPEECH, BlockThreshold.MEDIUM_AND_ABOVE)

val generativeModel = GenerativeModel(
    // The Gemini 1.5 models are versatile and work with most use cases
    modelName = "gemini-1.5-flash",
    apiKey = BuildConfig.apiKey,
    safetySettings = listOf(harassmentSafety, hateSpeechSafety)
)

Java

SafetySetting harassmentSafety = new SafetySetting(HarmCategory.HARASSMENT,
    BlockThreshold.ONLY_HIGH);

SafetySetting hateSpeechSafety = new SafetySetting(HarmCategory.HATE_SPEECH,
    BlockThreshold.MEDIUM_AND_ABOVE);

// The Gemini 1.5 models are versatile and work with most use cases
GenerativeModel gm = new GenerativeModel(
    "gemini-1.5-flash",
    BuildConfig.apiKey,
    null, // generation config is optional
    Arrays.asList(harassmentSafety, hateSpeechSafety)
);

GenerativeModelFutures model = GenerativeModelFutures.from(gm);

다음 단계

  • 프롬프트 설계는 언어 모델에서 원하는 응답을 유도하는 프롬프트를 만드는 프로세스입니다. 체계적인 메시지 작성은 언어 모델의 정확하고 고품질 응답을 보장하는 필수 부분입니다. 프롬프트 작성 권장사항에 대해 알아보세요.

  • Gemini는 다양한 용도의 니즈에 맞는 여러 가지 모델 변형을 제공합니다. 입력 유형 및 복잡성, 채팅 또는 기타 대화상자 언어 작업, 크기 제약 조건을 고려해야 합니다. 사용 가능한 Gemini 모델에 대해 알아보세요.

  • 이 튜토리얼에서 설명하는 Android용 클라이언트 SDK를 사용하면 Google 서버에서 실행되는 Gemini Pro 모델입니다. 배포와 관련된 사용 사례의 경우 민감한 정보 처리, 오프라인 가용성 또는 비용 절감을 위해 사용자 플로우가 궁금하다면 Gemini Nano에 액세스하는 것이 좋습니다 이는 기기에서 실행됩니다. 자세한 내용은 Android (기기 내) 튜토리얼