google-gemini/generative-ai-android
Fork: 165 Star: 741 (更新于 2024-12-12 04:26:28)
license: Apache-2.0
Language: Kotlin .
The official Android library for the Google Gemini API
最后发布版本: v0.9.0 ( 2024-07-03 06:54:37)
Google AI SDK for Android
The Google AI Android SDK is the easiest way for Android developers to build with the Gemini API. The Gemini API gives you access to Gemini models created by Google DeepMind. Gemini models are built from the ground up to be multimodal, so you can reason seamlessly across text, images, and code.
[!CAUTION] The Google AI SDK for Android is recommended for prototyping only. If you plan to enable billing, we strongly recommend that you use a backend SDK to access the Google AI Gemini API. You risk potentially exposing your API key to malicious actors if you embed your API key directly in your Android app or fetch it remotely at runtime.
[!NOTE] If you want to access Gemini on-device (Gemini Nano), check out the Google AI Edge SDK for Android, which is enabled via Android AICore.
Get started with the Gemini API
This repository contains a sample app demonstrating how the SDK can access and utilize the Gemini model for various use cases.
To try out the sample app you can directly import the project from Android Studio via File > New > Import Sample and searching for Generative AI Sample or follow these steps below:
- Go to Google AI Studio.
- Login with your Google account.
- Create an API key. Note that in Europe the free tier is not available.
- Check out this repository.
git clone https://github.com/google/generative-ai-android
- Open and build the sample app in the
generativeai-android-sample
folder of this repo. - Paste your API key into the
apiKey
property in thelocal.properties
file. - Run the app
- For detailed instructions, try the Android SDK tutorial on ai.google.dev.
Usage example
-
Add the dependency
implementation("com.google.ai.client.generativeai:generativeai:<version>"
) to your Android project. -
Initialize the model
val generativeModel = GenerativeModel(
modelName = "gemini-1.5-pro-latest",
apiKey = BuildConfig.apiKey
)
- Run a prompt.
val cookieImage: Bitmap = // ...
val inputContent = content() {
image(cookieImage)
text("Does this look store-bought or homemade?")
}
val response = generativeModel.generateContent(inputContent)
print(response.text)
For detailed instructions, you can find a quickstart for the Google AI client SDK for Android in the Google documentation.
This quickstart describes how to add your API key and the SDK's dependency to your app, initialize the model, and then call the API to access the model. It also describes some additional use cases and features, like streaming, counting tokens, and controlling responses.
Documentation
See the Gemini API Cookbook or ai.google.dev for complete documentation.
Contributing
See Contributing for more information on contributing to the Google AI client SDK for Android.
License
The contents of this repository are licensed under the Apache License, version 2.0.
最近版本更新:(数据更新于 2024-10-12 05:22:02)
2024-07-03 06:54:37 v0.9.0
2024-06-12 04:11:51 v0.8.0
2024-05-30 22:20:13 v0.7.0
2024-05-13 22:28:55 v0.6.0
2024-05-04 00:32:34 v0.5.0
2024-04-20 02:34:22 v0.4.0
2024-04-10 23:06:14 v0.3.0
2024-03-15 03:06:00 v0.2.2
2024-02-29 05:32:03 v0.2.1
2024-02-14 04:49:51 v0.2.0
主题(topics):
gemini, gemini-api, generative-ai
google-gemini/generative-ai-android同语言 Kotlin最近更新仓库
2024-12-20 11:28:10 Mygod/VPNHotspot
2024-12-17 22:50:27 mudkipme/MoeMemosAndroid
2024-12-17 15:04:09 gotson/komga
2024-12-15 18:02:25 MatsuriDayo/NekoBoxForAndroid
2024-12-14 17:50:54 avluis/Hentoid
2024-12-13 19:06:45 EhViewer-NekoInverter/EhViewer