Gemini Nano deneysel erişimi, uygulamalarını cihaz üzerinde yapay zeka özellikleriyle geliştirmenin yollarını test etmek isteyen geliştiriciler için tasarlanmıştır. Bu kılavuzda, kendi uygulamanızda Google AI Edge SDK'yı kullanarak Gemini Nano ile nasıl deneme yapacağınız hakkında ayrıntılı bilgi verilmektedir.
Örnek uygulamayı edinme
Hazırlanmış bir demoyu takip etmek isterseniz GitHub'daki örnek uygulamamıza göz atın.
Ön koşullar
Gemini Nano'yu denemek için Pixel 9 serisi bir cihazınızın olması gerekir. Devam etmeden önce elinizde bir test hesabı bulunduğundan ve yalnızca test için kullanmayı planladığınız hesapla giriş yaptığınızdan emin olun.
- aicore-experimental Google grubuna katılın.
- Android AICore test programına kaydolun.
Bu adımları tamamladıktan sonra Play Store'daki (uygulamaları ve cihazı yönet bölümünde) uygulama adı "Android AICore"dan "Android AICore (Beta)"ya değişir.
APK'ları güncelleme ve ikili dosyaları indirme
- AICore APK'sını güncelleyin:
- Sağ üst taraftaki profil simgesine dokunun.
- Uygulamaları ve cihazı yönet > Yönet'e dokunun.
- Android AICore'a dokunun.
- Güncelleme varsa Güncelle'ye dokunun.
- Private Compute Service APK'sını güncelleyin:
- Sağ üst taraftaki profil simgesine dokunun.
- Uygulamaları ve cihazı yönet > Yönet'e dokunun.
- Private Compute Services'e dokunun.
- Güncelleme varsa Güncelle'ye dokunun.
- Bu uygulama hakkında sekmesindeki sürümü kontrol edin ve uygulama sürümünün 1.0.release.658389993 veya daha yeni olduğunu doğrulayın.
- Cihazınızı yeniden başlatın ve test kaydının geçerlilik kazanması için birkaç dakika bekleyin.
- Play Store'daki AICore APK sürümünü ("Bu uygulama hakkında" sekmesinde) kontrol ederek 0.thirdpartyeap ile başladığını doğrulayın.
Gradle'ı yapılandırma
build.gradle
yapılandırmanızdaki bağımlılıklar bloğuna aşağıdakileri ekleyin:
implementation("com.google.ai.edge.aicore:aicore:0.0.1-exp01")
build.gradle
yapılandırmanızda minimum SDK hedefini 31 olarak ayarlayın:
defaultConfig {
...
minSdk = 31
...
}
AICore'u edinme ve çıkarım çalıştırma
Modelin çıkarım yapma şekliyle ilgili özellikleri özelleştirmek için parametreleri olan bir GenerationConfig
nesnesi oluşturun.
Parametreler şunları içerir:
- Sıcaklık: Rastgeleliği kontrol eder. Daha yüksek değerler çeşitliliği artırır.
- En yüksek K: En yüksek sıralamaya sahip olanlardan kaç simgenin dikkate alınacağı
- Aday sayısı: Döndürülecek maksimum yanıt sayısı
- Maks. çıkış jetonu sayısı: Yanıtın uzunluğu
- Worker Executor: Arka plan görevlerinin üzerinde çalıştırılması gereken
ExecutorService
- Callback Executor: Geri aramaların çağrılması gereken
Executor
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);
İsteğe bağlı bir downloadCallback
oluşturun. Bu, model indirmek için kullanılan bir geri çağırma işlevidir. Döndürülen iletiler hata ayıklama amaçlıdır.
Daha önce oluşturduğunuz oluşturma ve isteğe bağlı indirme yapılandırmalarıyla GenerativeModel
nesnesini oluşturun.
Kotlin
val downloadConfig = DownloadConfig(downloadCallback) val generativeModel = GenerativeModel( generationConfig = generationConfig, downloadConfig = downloadConfig // optional )
Java
GenerativeModel generativeModel = new GenerativeModel( generationConfig, downloadConfig = DownloadConfig(downloadCallback) // optional );
Modelle çıkarım çalıştırın ve isteminizi iletin. GenerativeModel.generateContent()
bir askıya alma işlevi olduğundan başlatmak için doğru coroutine kapsamında olduğundan emin olmamız gerekir.
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." generativeModelFutures.generateContent(input), new FutureCallback<GenerateContentResponse>() { @Override public void onSuccess(GenerateContentResponse result) { // generation successful } @Override public void onFailure(Throwable t) { // generation failed } }, ContextCompat.getMainExecutor(this));
Google AI Edge SDK ile ilgili geri bildiriminiz veya ekibimiz için başka geri bildirimleriniz varsa destek kaydı gönderin.
İstem ipuçları
İstem tasarımı, dil modellerinden en iyi yanıtı alacak istemler oluşturma sürecidir. İyi yapılandırılmış istemler yazmak, dil modelinden doğru ve yüksek kaliteli yanıtlar almanın önemli bir parçasıdır. Gemini Nano'nun yaygın kullanım alanlarında size yardımcı olacak bazı örnekler ekledik. Daha fazla bilgi için Gemini istem stratejileri başlıklı makaleyi inceleyin.
Yeniden yazma için:
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
Akıllı yanıt kullanım alanları:
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:
Özetleme için:
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.