بدء استخدام الإصدار التجريبي من Gemini Nano

تم تصميم إمكانية الوصول التجريبي إلى Gemini Nano للمطوّرين الذين يريدون اختبار تحسين تطبيقاتهم باستخدام إمكانات الذكاء الاصطناعي المتطوّرة التي تعمل على الجهاز فقط. يقدّم هذا الدليل تفاصيل حول كيفية تجربة Gemini Nano باستخدام حزمة تطوير البرامج (SDK)‏ Google AI Edge في تطبيقك.

الحصول على نموذج التطبيق

إذا أردت متابعة عرض توضيحي مُعدّ مسبقًا، يمكنك الاطّلاع على تطبيقنا النموذجي على GitHub.

المتطلّبات الأساسية

لتجربة Gemini Nano، ستحتاج إلى جهاز من سلسلة Pixel 9. تأكَّد من توفّر بطاقة ائتمان قبل المتابعة، ومن تسجيل الدخول باستخدام الحساب الذي تنوي استخدامه للاختبار فقط.

  1. الانضمام إلى مجموعة Google التجريبية الخاصة بـ aicore
  2. الموافقة على الانضمام إلى برنامج اختبار Android AICore

بعد إكمال هذه الخطوات، من المفترض أن يتغيّر اسم التطبيق في "متجر Play" (ضمن "إدارة التطبيقات والأجهزة") من "Android AICore" إلى "Android AICore (إصدار تجريبي)".

تعديل حِزم APK وتنزيل الملفات الثنائية

  1. تحديث حزمة APK لتطبيق AICore:
    1. في أعلى يسار الشاشة، انقر على رمز الملف الشخصي.
    2. انقر على إدارة التطبيقات والأجهزة > إدارة
    3. انقر على Android AICore.
    4. انقر على تحديث إذا كان هناك تحديث متوفّر
  2. تعديل حزمة APK لـ "خدمة الحوسبة الخاصة":
    1. في أعلى يسار الشاشة، انقر على رمز الملف الشخصي.
    2. انقر على إدارة التطبيقات والأجهزة > إدارة
    3. انقر على خدمات الحوسبة الخاصة.
    4. انقر على تحديث إذا كان هناك تحديث متوفّر
    5. تحقَّق من الإصدار ضمن علامة التبويب لمحة عن هذا التطبيق وتأكَّد من أنّ إصدار التطبيق هو 1.0.release.658389993 أو إصدار أحدث.
  3. أعِد تشغيل جهازك وانتظر بضع دقائق حتى يصبح التسجيل في الاختبار ساريًا
  4. تحقَّق من إصدار حزمة APK الخاصة بـ AICore في "متجر Play" (ضمن علامة التبويب "حول هذا التطبيق") للتأكّد من أنّها تبدأ بـ 0.thirdpartyeap.

ضبط Gradle

أضِف ما يلي إلى قسم التبعيات في إعدادات build.gradle:


implementation("com.google.ai.edge.aicore:aicore:0.0.1-exp01")

في إعدادات build.gradle، اضبط الحد الأدنى لإصدار حزمة تطوير البرامج (SDK) على 31:

defaultConfig {
    ...
    minSdk = 31
    ...
}

الحصول على AICore وتشغيل الاستدلال

أنشئ عنصر GenerationConfig يحتوي على مَعلمات لتخصيص الخصائص المتعلقة بطريقة تنفيذ النموذج للاستدلال.

تشمل المَعلمات ما يلي:

  • مستوى الإبداع: يتحكّم في العشوائية، وتؤدي القيم الأعلى إلى زيادة التنوّع
  • أعلى K: عدد الرموز المميزة من الرموز الأعلى ترتيبًا التي يجب أخذها في الاعتبار
  • عدد المرشحين: الحد الأقصى لعدد الردود المطلوب عرضها
  • الحدّ الأقصى لعدد الرموز المميزة في الإخراج: طول الردّ
  • Worker Executor: ExecutorService الذي يجب تشغيل المهام في الخلفية عليه
  • Callback Executor: 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);

إنشاء downloadCallback اختياري هذه دالة ردّ اتصال تُستخدَم لتنزيل النماذج. يتم عرض الرسائل لأغراض تصحيح الأخطاء.

أنشئ الكائن GenerativeModel باستخدام إعدادات الإنشاء والتنزيل الاختيارية التي أنشأتها سابقًا.

Kotlin

val downloadConfig = DownloadConfig(downloadCallback)
val generativeModel = GenerativeModel(
   generationConfig = generationConfig,
   downloadConfig = downloadConfig // optional
)

Java

GenerativeModel generativeModel = new GenerativeModel(
   generationConfig,
   downloadConfig = DownloadConfig(downloadCallback) // optional
);

نفِّذ الاستنتاج باستخدام النموذج وأدخِل طلبك. بما أنّ GenerativeModel.generateContent() هي دالة تعليق، علينا التأكّد من أنّها في نطاق الروتين المشترك الصحيح لتشغيلها.

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 أو أي ملاحظات أخرى لفريقنا، يُرجى إرسال طلب.

نصائح حول الطلبات

تصميم الطلبات هو عملية إنشاء طلبات تؤدي إلى الحصول على ردود مثالية من النماذج اللغوية. تُعد كتابة طلبات منظَّمة بشكل جيد جزءًا أساسيًا من ضمان الحصول على ردود دقيقة وعالية الجودة من نموذج لغوي. لقد أدرجنا بعض الأمثلة لمساعدتك في البدء باستخدام 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.