Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Generative AI to you Android with Gemini API by...

GDG Montreal
November 14, 2024
7

Generative AI to you Android with Gemini API by Eric Ampire

DevFest Montreal talk 2024 :
https://youtu.be/CCm97du5ido

GDG Montreal

November 14, 2024
Tweet

More Decks by GDG Montreal

Transcript

  1. Potential Applications • Education : Personalized learning experiences, interactive tutoring

    knowledge. • Healthcare: Assisting doctors, analyzing medical data, and enhancing coms.
  2. Potential Applications • Education : Personalized learning experiences, interactive tutoring

    knowledge. • Healthcare: Assisting doctors, analyzing medical data, and enhancing coms. • Customer service : Personalized interactions, resolving complex queries, and improving customer satisfaction.
  3. AI Core • Android AICore, a new system service for

    on-device foundation models starting from Android 14
  4. AI Core • Android AICore, a new system service for

    on-device foundation models starting from Android 14 • AICore enables Low Rank Adaptation (LoRA) fine tuning with Gemini Nano.
  5. AI Core • Android AICore, a new system service for

    on-device foundation models starting from Android 14 • AICore enables Low Rank Adaptation (LoRA) fine tuning with Gemini Nano. • AICore takes advantage of new ML hardware like the latest Google Tensor TPU and NPUs in flagship Qualcomm Technologies, Samsung S.LSI and MediaTek silicon
  6. Privacy: your data is not sent to a remote server

    Fast, everything is process On-Device Advantage
  7. Privacy: your data is not sent to a remote server

    Fast, everything is process On-Device Indirect Internet Access Advantage
  8. Privacy: your data is not sent to a remote server

    Fast, everything is process On-Device Indirect Internet Access Advantage AICore does not have direct internet access. All internet requests, including model downloads, are routed through the open-source Private Compute Services
  9. What is Private Compute Core • Android’s Private Compute Core

    is an open source, secure environment that is isolated from the rest of the operating system and apps
  10. What is Private Compute Core • Android’s Private Compute Core

    is an open source, secure environment that is isolated from the rest of the operating system and apps • Introduced with Android 12, It is a secure environment that isolates sensitive data to perform private computations while ensuring that this data never leaves the device
  11. Private Compute Core - Limited data access • The Private

    Compute Core is completely isolated from the rest of the system and from third-party applications, which means that not even Google has access to the data. Only local machine learning APIs, which are strictly controlled, can interact with private data.
  12. Private Compute Core - Indirect Internet Access • AICore does

    not have direct internet access. All internet requests, including model downloads, are routed through the open-source Private Compute Services companion APK
  13. Private Compute Core - Indirect Internet Access • AICore does

    not have direct internet access. All internet requests, including model downloads, are routed through the open-source Private Compute Services companion APK • Learn more : bit.ly/private-compute
  14. Text Rephrasing: Modify the tone and style of text Smart

    Reply: Generate relevant responses within a chat Use cases
  15. Text Rephrasing: Modify the tone and style of text Smart

    Reply: Generate relevant responses within a chat Proofreading: Correct spelling and grammatical errors. Use cases
  16. Text Rephrasing: Modify the tone and style of text Smart

    Reply: Generate relevant responses within a chat Proofreading: Correct spelling and grammatical errors. Condense lengthy documents into concise summaries Use cases
  17. Gemini Nano is currently in Private Preview • Supported Devices:

    AICore is currently available on Pixel 9 series devices, Google Pixel 8 Series devices, Samsung S24 Series devices, Realme GT 6, Motorola Edge 50 Ultra, Motorola Razr 50 Ultra, Xiaomi 14T/Pro, and Xiaomi MIX Flip
  18. Gemini Nano is currently in Private Preview • Supported Devices:

    AICore is currently available on Pixel 9 series devices, Google Pixel 8 Series devices, Samsung S24 Series devices, Realme GT 6, Motorola Edge 50 Ultra, Motorola Razr 50 Ultra, Xiaomi 14T/Pro, and Xiaomi MIX Flip • Supported Modalities: AICore currently supports text modality for Gemini Nano
  19. Add the SDK dependency to your project dependencies { //

    add the dependency for the Google AI client SDK for Android implementation("com.google.ai.client.generativeai:generativeai:0.7.0") }
  20. Initialized the Generative Model val model = GenerativeModel( // Specify

    a Gemini model appropriate for your use case modelName = "gemini-1.5-flash", // Access your API key as a Build Configuration variable apiKey = "gemini-key" )
  21. Initialized the Generative Model with More settings val generationConfig =

    generationConfig { temperature = 0.15f topK = 32 topP = 1f maxOutputTokens = 4096 }
  22. Initialized the Generative Model with More settings val safetySettings =

    listOf( SafetySetting( HarmCategory.HARASSMENT, BlockThreshold.MEDIUM_AND_ABOVE ), SafetySetting( HarmCategory.HATE_SPEECH, BlockThreshold.MEDIUM_AND_ABOVE ) )
  23. Initialized the Generative Model with More settings val model =

    GenerativeModel( model = "gemini-1.5-flash-001", apiKey = "gemini-key", generationConfig = generationConfig, safetySettings = safetySettings )
  24. Initialized the Generative Model val model = GenerativeModel( model =

    "gemini-1.5-flash-001", apiKey = "gemini-key", generationConfig = generationConfig, safetySettings = safetySettings )
  25. Write your first prompt val prompt = "Write a story

    about a magic backpack." coroutineScope.launch { val response = model.generateContent(prompt) }
  26. Generate text from images and other media coroutineScope.launch { val

    response = model.generateContent( content { image(bitmap) text("What is the object in this picture?") } ) }
  27. Multi-turn chat You can also support multi-turn conversations. Initialize a

    chat with the startChat() function. You can optionally provide a message history. Then call the sendMessage() function to send chat messages.
  28. Multi-turn chat val chat = model.startChat( history = listOf( content(role

    = "user") { text("Hello, I have 2 dogs in my house.") }, content(role = "model") { text("What would you like to know?") } ) ) coroutineScope.launch { val response = chat.sendMessage("How many paws are in my house?") }
  29. Stream the response You can achieve faster interactions by not

    waiting for the entire result from the model generation, and instead use streaming to handle partial results. Use generateContentStream() to stream a response.
  30. Summary Gemini is a family of multimodal large language models

    developed by Google DeepMind and Google Research