دسترسی آزمایشی Gemini Nano برای توسعهدهندگانی طراحی شده است که به دنبال آزمایش بهبود برنامههای خود با قابلیتهای پیشرفته هوش مصنوعی روی دستگاه هستند. این راهنما جزئیاتی را در مورد نحوه آزمایش Gemini Nano با استفاده از Google AI Edge SDK در برنامه خود ارائه میدهد.
پیشنیازها
برای آزمایش با Gemini Nano، به یک دستگاه سری Pixel 9 نیاز دارید. قبل از ادامه، مطمئن شوید که یکی از آنها را در دسترس دارید و فقط با حسابی که قصد دارید برای آزمایش از آن استفاده کنید، وارد سیستم شدهاید.
- به گروه گوگل aicore-experimental بپیوندید
- در برنامه تست اندروید AICore شرکت کنید
پس از انجام این مراحل، نام برنامه در فروشگاه Play (در قسمت مدیریت برنامهها و دستگاه) باید از « Android AICore » به « Android AICore (Beta) » تغییر کند.
فایلهای بسته اندروید (APK) را بهروزرسانی کنید و فایلهای باینری را دانلود کنید
- بسته اندروید AICore (APK) را بهروزرسانی کنید:
- در بالا سمت راست، روی نماد نمایه ضربه بزنید
- روی مدیریت برنامهها و دستگاه > مدیریت ضربه بزنید
- روی اندروید AICore ضربه بزنید
- اگر بهروزرسانی موجود است، روی بهروزرسانی ضربه بزنید
- سرویس محاسبات خصوصی APK را بهروزرسانی کنید:
- در بالا سمت راست، روی نماد نمایه ضربه بزنید
- روی مدیریت برنامهها و دستگاه > مدیریت ضربه بزنید
- روی خدمات محاسبات خصوصی ضربه بزنید
- اگر بهروزرسانی موجود است، روی بهروزرسانی ضربه بزنید
- نسخه را در زیر برگه «درباره این برنامه» بررسی کنید و تأیید کنید که نسخه برنامه ۱.۰.release.۶۵۸۳۸۹۹۹۳ یا بالاتر است.
- دستگاه خود را مجدداً راه اندازی کنید و چند دقیقه صبر کنید تا ثبت نام آزمایشی اعمال شود
- نسخه APK برنامه AICore را در فروشگاه Play (در زیر تب « درباره این برنامه ») بررسی کنید تا مطمئن شوید که با 0.thirdpartyeap شروع میشود.
پیکربندی گریدل
موارد زیر را به بلوک dependencies در پیکربندی build.gradle خود اضافه کنید:
implementation("com.google.ai.edge.aicore:aicore:0.0.1-exp01")
در پیکربندی build.gradle خود، حداقل هدف SDK را روی ۳۱ تنظیم کنید:
defaultConfig {
...
minSdk = 31
...
}
دریافت AICore و اجرای استنتاج
یک شیء GenerationConfig ایجاد کنید که دارای پارامترهایی برای سفارشیسازی ویژگیهای نحوهی اجرای استنتاج مدل باشد.
پارامترها شامل موارد زیر هستند:
- دما : تصادفی بودن را کنترل میکند؛ مقادیر بالاتر تنوع را افزایش میدهد
- K برتر : چند توکن از بالاترین رتبهها باید در نظر گرفته شود
- تعداد کاندیدا : حداکثر پاسخهای قابل بازگشت
- حداکثر توکنهای خروجی : طول پاسخ
- مجری کارگر : سرویس
ExecutorServiceکه وظایف پسزمینه باید روی آن اجرا شوند - اجراکنندهی فراخوانی (Callback Executor ):
Executorکه فراخوانیهای بازگشتی باید روی آن فراخوانی شوند.
کاتلین
val generationConfig = generationConfig { context = ApplicationProvider.getApplicationContext() // required temperature = 0.2f topK = 16 maxOutputTokens = 256 }
جاوا
GenerationConfig.Builder configBuilder = GenerationConfig.Companion.builder(); configBuilder.setContext(context); configBuilder.setTemperature(0.2f); configBuilder.setTopK(16); configBuilder.setMaxOutputTokens(256);
یک downloadCallback اختیاری ایجاد کنید. این یک تابع فراخوانی است که برای دانلود مدل استفاده میشود. پیامهای برگردانده شده برای اهداف اشکالزدایی هستند.
شیء GenerativeModel را با پیکربندیهای تولید و دانلود اختیاری که قبلاً ایجاد کردهاید، ایجاد کنید.
کاتلین
val downloadConfig = DownloadConfig(downloadCallback) val generativeModel = GenerativeModel( generationConfig = generationConfig, downloadConfig = downloadConfig // optional )
جاوا
GenerativeModel generativeModel = new GenerativeModel( generationConfig, downloadConfig = DownloadConfig(downloadCallback) // optional );
استنتاج را با مدل اجرا کنید و اعلان خود را ارسال کنید. از آنجایی که GenerativeModel.generateContent() یک تابع suspend است، باید مطمئن شوید که در محدودهی کوروتین صحیح برای اجرا قرار دارد.
کاتلین
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) }
جاوا
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 یا هرگونه بازخورد دیگری برای تیم ما دارید، تیکت ارسال کنید .
نکات سریع
طراحی سریع فرآیند ایجاد دستورالعملهایی است که پاسخ بهینه را از مدلهای زبانی استخراج میکنند. نوشتن دستورالعملهای خوشساختار بخش مهمی از کمک به تضمین پاسخهای دقیق و با کیفیت بالا از یک مدل زبانی است. ما چند مثال برای شروع کار شما در مورد موارد استفاده رایج برای Gemini Nano آوردهایم. برای اطلاعات بیشتر ، استراتژیهای دستورالعمل Gemini را بررسی کنید.
برای بازنویسیها:
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
موارد استفاده برای پاسخ هوشمند:
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:
برای جمع بندی:
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.