본문으로 건너뛰기
Skillpedia
모바일 앱10k · #11913

ml-kit-genai-prompt-api

하는 일

이 스킬은 ML Kit GenAI Prompt API를 Android 앱에 추가하는 방법을 안내합니다. 이 API는 기기 안의 모델에 텍스트 요청을 보냅니다. 기기 내 생성 모델을 쓰려는 Android 개발자를 위한 스킬입니다.

사용하는 경우

  • ✓Android 앱이 기기 안의 Gemini Nano로 텍스트 요청에 답하게 하고 싶을 때.
  • ✓기기 내 Prompt API에서 구조화된 출력이 필요할 때.
  • ✓프롬프트가 길어서 접두사 캐싱으로 속도를 높이고 싶을 때.

스킬 링크

https://github.com/android/skills/blob/main/device-ai/ml-kit-genai-prompt-api/SKILL.md

복사해서 AI(Claude, ChatGPT, Cursor)에 붙여넣고 지침을 따르도록 요청하세요.

사용 방법

가장 쉬운 방법입니다. 메시지를 복사해 AI에 붙여넣으세요. AI가 스킬을 읽고 지침을 따릅니다.

바로 붙여넣을 수 있는 메시지

Use this skill to help me: https://github.com/android/skills/blob/main/device-ai/ml-kit-genai-prompt-api/SKILL.md Read the SKILL.md file at that link and follow its instructions for my task.
AI가 이런 스킬을 알아서 찾아 쓰길 원하시나요?무료 Skillpedia MCP를 설치하세요. 한 줄이면 작업마다 스킬 15,000+개 중에서 검색합니다.1분 만에 설치 →

AI에게 요청하는 예시

“ML Kit Prompt API로 내 Android 앱에 기기 내 텍스트 요약 기능을 추가해 주세요.”

매주 새 스킬 5개. 읽는 데 1분.

작동 방식

이 스킬은 필요한 의존성과 최소 Android 버전을 설정한 뒤, 첫 요청 전에 모델을 사용할 수 있는지 확인합니다. 프롬프트 조정, 접두사 캐싱, 리소스 해제도 다룹니다.

기술 내용 (원본 SKILL.md)

작성자의 영어 원문을 GitHub에서 그대로 가져왔습니다.

This skill provides step-by-step guidance for integrating and optimizing the ML Kit GenAI Prompt API in Android apps.

Prerequisites

  • Android API level must be 26 or higher. If minSdk is below 26, update it to 26.
  • Add the ML Kit GenAI Prompt API dependency (com.google.mlkit:genai-prompt) to the app-level build.gradle file, with version at least 1.0.0-beta4.
  • If com.google.mlkit:genai-schema-compiler dependency is used and KSP plugin version is below 2.3.6, update it to 2.3.6.

Detailed steps

1. Prompt optimization

To optimize prompts for use with the ML Kit Prompt API, follow the prompt optimization guide.

2. Prefix caching optimization

If the prompt is more than 200 words, implement the prefix caching API.

3. Lifecycle and best practices

  • The model must be fully downloaded and available before calling the first inference. Follow the guide on implementing a generative model to check that the FeatureStatus of a model is AVAILABLE before making an inference.

  • Release ML Kit instances by calling close() when an Activity, Fragment, or ViewModel is destroyed. Example:

    // Instantiating model in activity, fragment, or ViewModel
        val generativeModel = Generation.getClient()
    
    // When activity, fragment, or ViewModel is destroyed
        generativeModel.close()
    
    <br />

4. Structured output

When implementing or refactoring a prompt to use structured output, follow these rules:

  1. Check for API availability: Verify Structured Output feature is available on the device with isStructuredOutputFeatureAvailable() before using it. Refer to the Structured Output API guide for full instructions.

  2. Return type: Return the @Generable typed object from the function signature instead of a String or JSON string.

    For example:

    fun parseEmail(email: String): String {
        ... 
    }
    

    should be refactored to:

    fun parseEmail(email: String): ParsedEmail? {
        ...
    }
    
  3. Example:

    This is the example code before refactoring:

    suspend fun parseEmail(email: String): String {
        val parseEmailPrompt = "Parse this email and return the sender, title, and short summary of the email less than 10 words: "
    
        val parsedEmail = generativeModel.generateContent(parseEmailPrompt + email)
    
        return parsedEmail.candidates[0].text
    }
    
    <br />

    This is the example code after using Structured Output API:

    @Generable
    data class ParsedEmail(
        @Guide(description = "Sender of the email")
        var sender: String = "",
    
        @Guide(description = "Title of the email")
        var title: String = "",
    
        @Guide(description = "Summary of the email less than 10 words")
        var summary: String = ""
    )
    
    suspend fun parseEmail(email: String): ParsedEmail? {
        val parseEmailPrompt =
            "Parse this email: $email"
    
        val baseRequest = GenerateContentRequest.Builder(TextPart(parseEmailPrompt)).build()
        val typedRequest = generateTypedContentRequest(baseRequest, ParsedEmail::class)
        val typedResponse = generativeModel.generateContent(typedRequest)
        return typedResponse.candidates[0].response
    }
    
    <br />
자주 묻는 질문

최소 Android 버전은 무엇이 필요한가요?

앱의 minSdk는 26 이상이어야 하며, 필요하면 스킬이 이를 올립니다.

모델 상태를 먼저 확인하는 이유는 무엇인가요?

첫 요청 전에 모델이 완전히 다운로드되어 사용 가능해야 하므로, 스킬이 먼저 상태를 확인합니다.

접두사 캐싱은 무엇인가요?

200단어보다 긴 프롬프트에 권장되는 최적화 방법입니다.

상세 정보

작성자의 원본 설명

Analyzes Android codebases to implement ML Kit GenAI Prompt API. Use this skill to send natural language requests on-device to Gemini Nano, use structured output with Prompt API, implement prefix caching, optimize the current prompt, or apply best practices."

repo: android/skills

인기도

GitHub 스타
10k
순위
#11913
라이선스
Apache-2.0
업데이트
2026. 10. 29.

이 스킬이 유용한가요?

0

로그인 투표하려면 로그인하세요.

댓글

  • …

이 저장소의 다른 스킬

비슷한 스킬