Google AI SDK Launch: Empowering Android with Advanced Gemini Pro Models

2023-12-26

Google has launched its new Google AI SDK to simplify the integration of its best-performing model, Gemini Pro, into Android applications. With this SDK, developers no longer need to build and manage their own backend infrastructure. According to Google, Gemini Pro is its top model, with features for various text and image inference tasks. Gemini Pro runs outside the device, in Google's data centers, and can be accessed through the Gemini API. Google states that the easiest way to use Gemini is through Google AI Studio, a web-based tool that allows developers to prototype and run prompts in the browser. Once satisfied with the results, developers can export their models as code and run them on the backend using their preferred language, such as Python. For Android applications, Google provides the Google AI client SDK for Android, which wraps the Gemini REST API into a familiar Kotlin API. With it, developers don't need to directly interact with the REST API or implement server-side services to access Gemini models in their Android applications. The following code snippet demonstrates how to use the Google AI SDK to generate text from a prompt: ```kotlin val generativeModel = GenerativeModel( modelName = "gemini-pro", apiKey = BuildConfig.apiKey ) val prompt = "Write a story about a magic backpack." val response = generativeModel.generateContent(prompt) print(response.text) ``` In addition to the text-only model, Gemini also offers a multimodal model that can generate text from both text and image inputs. It supports streaming for faster interaction. The following code snippet shows how to use the Gemini SDK to generate text using both text and image inputs: ```kotlin var fullResponse = "" generativeModel.generateContentStream(inputContent).collect { chunk -> print(chunk.text) fullResponse += chunk.text } ``` To further simplify the developer workflow, the latest preview version of Android Studio introduces a new project template that guides developers through the necessary steps to use Gemini Pro, starting from generating an API key in Google AI Studio. In addition to Gemini Pro, Google also offers a smaller model called Gemini Nano, which can run on devices. This allows applications to run without the need for data to leave the device, ensuring predictable latency even without a network connection. Gemini Nano is available on selected devices and is powered by AICore, a new system service designed for Android 14 that aims to simplify AI integration in Android applications. AICore handles model management, runtime, security, and more.