Loading...
Loading...
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."
npx skill4agent add android/skills ml-kit-genai-prompt-apiminSdkcom.google.mlkit:genai-promptbuild.gradle1.0.0-beta4com.google.mlkit:genai-schema-compilerFeatureStatusAVAILABLEclose()ActivityFragmentViewModel// Instantiating model in activity, fragment, or ViewModel
val generativeModel = Generation.getClient()
// When activity, fragment, or ViewModel is destroyed
generativeModel.close()isStructuredOutputFeatureAvailable()@GenerableStringfun parseEmail(email: String): String {
...
}fun parseEmail(email: String): ParsedEmail? {
...
}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
}@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
}