Get started with Gemini Nano experimental access

Gemini Nano experimental access is designed for developers seeking to test enhancement of their apps with cutting-edge on-device AI capabilities. This guide provides details for how to experiment with Gemini Nano using the Google AI Edge SDK in your own app.

Get the sample app

If you'd like to follow along with a prepared demo, check out our sample app on GitHub.

Prerequisites

To experiment with Gemini Nano, you'll need a Pixel 9 series device. Make sure you have one on hand before proceeding, and that you are logged in with only the account that you intend to use for testing.

  1. Join the aicore-experimental Google group
  2. Opt in to the Android AICore testing program

After you complete these steps, the app name on the Play store (under manage apps and device) should change from "Android AICore" to "Android AICore (Beta)".

Update APKs and download binaries

  1. Update the AICore APK:
    1. At the top right, tap the profile icon
    2. Tap Manage apps & device > Manage
    3. Tap Android AICore
    4. Tap Update if an update is available
  2. Update the Private Compute Service APK:
    1. At the top right, tap the profile icon
    2. Tap Manage apps & device > Manage
    3. Tap Private Compute Services
    4. Tap Update if an update is available
    5. Check the version under the About this app tab and confirm the app version is 1.0.release.658389993 or higher
  3. Restart your device and wait a few minutes for testing enrollment to take effect
  4. Check out the AICore APK version in the Play store (under "about this app" tab) to confirm it starts with 0.thirdpartyeap

Configure gradle

Add the following to the dependencies block in your build.gradle configuration:


implementation("com.google.ai.edge.aicore:aicore:0.0.1-exp01")

In your build.gradle configuration, set the minimum SDK target to 31:

defaultConfig {
    ...
    minSdk = 31
    ...
}

Get AICore and run inference

Create a GenerationConfig object, which has parameters to customize properties for how the model should run inference.

Parameters include:

  • Temperature: Controls randomness; higher values increase diversity
  • Top K: How many tokens from the highest ranking ones are to be considered
  • Candidate Count: Max responses to return
  • Max output tokens: Length of the response
  • Worker Executor: The ExecutorService on which background tasks should be run
  • Callback Executor: The Executor on which callbacks should be invoked

Kotlin


val generationConfig = generationConfig {
  context = ApplicationProvider.getApplicationContext() // required
  temperature = 0.2f
  topK = 16
  maxOutputTokens = 256
}

Java


GenerationConfig.Builder configBuilder = GenerationConfig.Companion.builder();
    configBuilder.setContext(context);
    configBuilder.setTemperature(0.2f);
    configBuilder.setTopK(16);
    configBuilder.setMaxOutputTokens(256);

Create an optional downloadCallback. This is a callback function that is used for model downloading. The messages returned are for debugging purposes.

Create the GenerativeModel object with the generation and optional download configs that you created earlier.

Kotlin


val downloadConfig = DownloadConfig(downloadCallback)
val model = GenerativeModel(
   generationConfig = generationConfig,
   downloadConfig = downloadConfig // optional
)

Java


GenerativeModel model = new GenerativeModel(
   generationConfig,
   downloadConfig = DownloadConfig(downloadCallback) // optional
);

Run the inference with the model and pass in your prompt. Since GenerativeModel.generateContent() is a suspend function, we need to make sure it's in the correct coroutine scope to launch.

Kotlin


scope.launch {
  // Single string input prompt
  val input = "I want you to act as an English proofreader. I will provide you
    texts, and I would like you to review them for any spelling, grammar, or
    punctuation errors. Once you have finished reviewing the text, provide me
    with any necessary corrections or suggestions for improving the text: These
    arent the droids your looking for."
  val response = generativeModel.generateContent(input)
  print(response.text)

  // Or multiple strings as input
  val response = generativeModel.generateContent(
  content {
    text("I want you to act as an English proofreader. I will provide you texts
      and I would like you to review them for any spelling, grammar, or
      punctuation errors.")
    text("Once you have finished reviewing the text, provide me with any
      necessary corrections or suggestions for improving the text:")
    text("These arent the droids your looking for.")
    }
  )
  print(response.text)
}

Java


Futures.addCallback(
    String input = "I want you to act as an English proofreader. I will
    provide you texts, and I would like you to review them for any
    spelling, grammar, or punctuation errors. Once you have finished
    reviewing the text, provide me with any necessary corrections or
    suggestions for improving the text:
    These aren't the droids you're looking for."
    modelFutures.generateContent(input),
    new FutureCallback<GenerateContentResponse>() {
      @Override
      public void onSuccess(GenerateContentResponse result) {
        // generation successful
      }

      @Override
      public void onFailure(Throwable t) {
        // generation failed
      }
    },
    ContextCompat.getMainExecutor(this));

If you have any feedback about the Google AI Edge SDK or any other feedback for our team, submit a ticket.

Prompt tips

Prompt design is the process of creating prompts that elicit an optimal response from language models. Writing well structured prompts is an essential part of ensuring accurate, high quality responses from a language model. We've included some examples to get you started on common use-cases for Gemini Nano. Check out the Gemini prompting strategies for more info.

For rewrites:

I want you to act as an English proofreader. I will provide you texts, and I
would like you to review them for any spelling, grammar, or punctuation errors.
Once you have finished reviewing the text, provide me with any necessary
corrections or suggestions for improving the text: These arent the droids your
looking for

For smart reply use-cases:

Prompt: Predict up to 5 emojis as a response to a text chat message. The output
should only include emojis.

input: The new visual design is blowing my mind 🤯
output: ➕,💘, ❤‍🔥

input: Well that looks great regardless
output: 💗,🪄

input: Unfortunately this won't work
output: 💔,😔

input: sounds good, I'll look into that
output: 🙏,👍

input: 10hr cut of jeff goldblum laughing URL
output: 😂,💀,⚰️

input: Woo! Launch time!
Output:

For summarization:

Summarize this text as bullet points of key information.
Text: A quantum computer exploits quantum mechanical phenomena to perform
  calculations exponentially faster than any modern traditional computer. At
  very tiny scales, physical matter acts as both particles and as waves, and
  quantum computing uses specialized hardware to leverage this behavior. The
  operating principles of quantum devices are beyond the scope of classical
  physics. When deployed at scale, quantum computers could be used in a wide
  variety of applications such as: in cybersecurity to break existing encryption
  methods while helping researchers create new ones, in meteorology to develop
  better weather forecasting etc. However, the current state-of-the-art quantum
  computers are still largely experimental and impractical.