با مجموعهها، منظم بمانید
ذخیره و طبقهبندی محتوا براساس اولویتهای شما.
میتوانید از ML Kit برای تولید پاسخ پیامها با استفاده از مدل روی دستگاه استفاده کنید.
برای ایجاد پاسخهای هوشمند، فهرستی از پیامهای اخیر را در یک مکالمه به ML Kit ارسال میکنید. اگر ML Kit تشخیص دهد که مکالمه به زبان انگلیسی است و مکالمه دارای موضوع بالقوه حساس نیست، ML Kit حداکثر سه پاسخ ایجاد می کند که می توانید آنها را به کاربر خود پیشنهاد دهید.
برای ایجاد پاسخهای هوشمند، List از اشیاء FirebaseTextMessage را با ترتیب زمانی به ML Kit ارسال میکنید که ابتدا اولین مُهر زمانی را در اختیار شما قرار میدهد.
هر زمان که کاربر پیامی ارسال کرد، پیام و مهر زمانی آن را به تاریخچه مکالمه اضافه کنید:
جاوا
conversation.add(FirebaseTextMessage.createForLocalUser("heading out now",System.currentTimeMillis()));
کاتلین
conversation.add(FirebaseTextMessage.createForLocalUser("heading out now",System.currentTimeMillis()))
هر زمان که کاربر پیامی دریافت کرد، پیام، مهر زمانی و شناسه کاربری فرستنده را به تاریخچه مکالمه اضافه کنید. شناسه کاربر میتواند هر رشتهای باشد که به طور منحصربهفرد فرستنده را در مکالمه شناسایی میکند. شناسه کاربر نیازی به مطابقت با دادههای کاربر ندارد و شناسه کاربر نیازی ندارد بین مکالمه یا فراخوانهای تولیدکننده پاسخ هوشمند سازگار باشد.
جاوا
conversation.add(FirebaseTextMessage.createForRemoteUser("Are you coming back soon?",System.currentTimeMillis(),userId));
کاتلین
conversation.add(FirebaseTextMessage.createForRemoteUser("Are you coming back soon?",System.currentTimeMillis(),userId))
یک شی تاریخچه مکالمه مانند مثال زیر است:
مهر زمان
شناسه کاربری
کاربر محلی؟
پیام
پنجشنبه 21 فوریه 13:13:39 PST 2019
درست است
در راه هستی؟
پنجشنبه 21 فوریه 13:15:03 PST 2019
FRIEND0
نادرست
دیر آمدم، ببخشید!
توجه داشته باشید که جدیدترین پیام در مثال بالا از یک کاربر غیر محلی است. این مهم است زیرا ML Kit پاسخ هایی را پیشنهاد می کند که قرار است توسط کاربر برنامه شما ارسال شود: کاربر محلی. باید مطمئن شوید که گزارش مکالمهای را به ML Kit ارسال میکنید که با پیامی به پایان میرسد که ممکن است کاربر شما بخواهد به آن پاسخ دهد.
2. پاسخ پیام را دریافت کنید
برای ایجاد پاسخ های هوشمند به یک پیام، نمونه ای از FirebaseSmartReply را دریافت کنید و تاریخچه مکالمه را به متد suggestReplies() آن ارسال کنید:
جاوا
FirebaseSmartReplysmartReply=FirebaseNaturalLanguage.getInstance().getSmartReply();smartReply.suggestReplies(conversation).addOnSuccessListener(newOnSuccessListener<SmartReplySuggestionResult>(){@OverridepublicvoidonSuccess(SmartReplySuggestionResultresult){if(result.getStatus()==SmartReplySuggestionResult.STATUS_NOT_SUPPORTED_LANGUAGE){// The conversation's language isn't supported, so the// the result doesn't contain any suggestions.}elseif(result.getStatus()==SmartReplySuggestionResult.STATUS_SUCCESS){// Task completed successfully// ...}}}).addOnFailureListener(newOnFailureListener(){@OverridepublicvoidonFailure(@NonNullExceptione){// Task failed with an exception// ...}});
کاتلین
valsmartReply=FirebaseNaturalLanguage.getInstance().smartReplysmartReply.suggestReplies(conversation).addOnSuccessListener{result->
if(result.getStatus()==SmartReplySuggestionResult.STATUS_NOT_SUPPORTED_LANGUAGE){// The conversation's language isn't supported, so the// the result doesn't contain any suggestions.}elseif(result.getStatus()==SmartReplySuggestionResult.STATUS_SUCCESS){// Task completed successfully// ...}}.addOnFailureListener{// Task failed with an exception// ...}
اگر عملیات با موفقیت انجام شود، یک شی SmartReplySuggestionResult به کنترل کننده موفقیت ارسال می شود. این شی حاوی لیستی از حداکثر 3 پاسخ پیشنهادی است که می توانید به کاربر خود ارائه دهید:
توجه داشته باشید که اگر مدل از مرتبط بودن پاسخهای پیشنهادی مطمئن نباشد، مکالمه ورودی به زبان انگلیسی نباشد، یا اگر مدل موضوع حساس را تشخیص دهد، ممکن است ML Kit به نتایجی برنگردد.
تاریخ آخرین بهروزرسانی 2025-09-06 بهوقت ساعت هماهنگ جهانی.
[[["درک آسان","easyToUnderstand","thumb-up"],["مشکلم را برطرف کرد","solvedMyProblem","thumb-up"],["غیره","otherUp","thumb-up"]],[["اطلاعاتی که نیاز دارم وجود ندارد","missingTheInformationINeed","thumb-down"],["بیشازحد پیچیده/ مراحل بسیار زیاد","tooComplicatedTooManySteps","thumb-down"],["قدیمی","outOfDate","thumb-down"],["مشکل ترجمه","translationIssue","thumb-down"],["مشکل کد / نمونهها","samplesCodeIssue","thumb-down"],["غیره","otherDown","thumb-down"]],["تاریخ آخرین بهروزرسانی 2025-09-06 بهوقت ساعت هماهنگ جهانی."],[],[],null,["You can use ML Kit to generate message replies using an on-device\nmodel.\n\nTo generate smart replies, you pass ML Kit a log of recent messages in a\nconversation. If ML Kit determines the conversation is in English, and that\nthe conversation doesn't have potentially sensitive subject matter, ML Kit\ngenerates up to three replies, which you can suggest to your user.\n\n\u003cbr /\u003e\n\nBefore you begin\n\n1. If you haven't already, [add Firebase to your Android project](/docs/android/setup).\n2. Add the dependencies for the ML Kit Android libraries to your module (app-level) Gradle file (usually `app/build.gradle`): \n\n ```carbon\n apply plugin: 'com.android.application'\n apply plugin: 'com.google.gms.google-services'\n\n dependencies {\n // ...\n implementation 'com.google.firebase:firebase-ml-natural-language:22.0.0'\n implementation 'com.google.firebase:firebase-ml-natural-language-smart-reply-model:20.0.7'\n }\n ```\n3. Also in your app-level `build.gradle` file, disable compression of `tflite` files: \n\n ```text\n android {\n // ...\n aaptOptions {\n noCompress \"tflite\"\n }\n }\n ```\n\n1. Create a conversation history object\n\nTo generate smart replies, you pass ML Kit a chronologically-ordered `List`\nof `FirebaseTextMessage` objects, with the earliest timestamp first.\n\nWhenever the user sends a message, add the message and its timestamp to the\nconversation history: \n\nJava \n\n conversation.add(FirebaseTextMessage.createForLocalUser(\n \"heading out now\", System.currentTimeMillis()));\n\nKotlin \n\n conversation.add(FirebaseTextMessage.createForLocalUser(\n \"heading out now\", System.currentTimeMillis()))\n\nWhenever the user receives a message, add the message, its timestamp, and the\nsender's user ID to the conversation history. The user ID can be any string that\nuniquely identifies the sender within the conversation. The user ID doesn't need\nto correspond to any user data, and the user ID doesn't need to be consistent\nbetween conversation or invocations of the smart reply generator. \n\nJava \n\n conversation.add(FirebaseTextMessage.createForRemoteUser(\n \"Are you coming back soon?\", System.currentTimeMillis(), userId));\n\nKotlin \n\n conversation.add(FirebaseTextMessage.createForRemoteUser(\n \"Are you coming back soon?\", System.currentTimeMillis(), userId))\n\nA conversation history object looks like the following example:\n\n| Timestamp | User ID | Local User? | Message |\n|------------------------------|---------|-------------|----------------------|\n| Thu Feb 21 13:13:39 PST 2019 | | true | are you on your way? |\n| Thu Feb 21 13:15:03 PST 2019 | FRIEND0 | false | Running late, sorry! |\n\nNote that the most recent message in the example above is from a non-local\nuser. This is important because ML Kit suggests replies intended to be sent\nby the user of your app: the local user. You should be sure you're passing\nML Kit a conversation log that ends with a message to which your user might\nwant to reply.\n\n2. Get message replies\n\nTo generate smart replies to a message, get an instance of `FirebaseSmartReply`\nand pass the conversation history to its `suggestReplies()` method: \n\nJava \n\n FirebaseSmartReply smartReply = FirebaseNaturalLanguage.getInstance().getSmartReply();\n smartReply.suggestReplies(conversation)\n .addOnSuccessListener(new OnSuccessListener\u003cSmartReplySuggestionResult\u003e() {\n @Override\n public void onSuccess(SmartReplySuggestionResult result) {\n if (result.getStatus() == SmartReplySuggestionResult.STATUS_NOT_SUPPORTED_LANGUAGE) {\n // The conversation's language isn't supported, so the\n // the result doesn't contain any suggestions.\n } else if (result.getStatus() == SmartReplySuggestionResult.STATUS_SUCCESS) {\n // Task completed successfully\n // ...\n }\n }\n })\n .addOnFailureListener(new OnFailureListener() {\n @Override\n public void onFailure(@NonNull Exception e) {\n // Task failed with an exception\n // ...\n }\n });\n\nKotlin \n\n val smartReply = FirebaseNaturalLanguage.getInstance().smartReply\n smartReply.suggestReplies(conversation)\n .addOnSuccessListener { result -\u003e\n if (result.getStatus() == SmartReplySuggestionResult.STATUS_NOT_SUPPORTED_LANGUAGE) {\n // The conversation's language isn't supported, so the\n // the result doesn't contain any suggestions.\n } else if (result.getStatus() == SmartReplySuggestionResult.STATUS_SUCCESS) {\n // Task completed successfully\n // ...\n }\n }\n .addOnFailureListener {\n // Task failed with an exception\n // ...\n }\n\nIf the operation succeeds, a `SmartReplySuggestionResult` object is passed to\nthe success handler. This object contains a list of up to 3 suggested replies,\nwhich you can present to your user: \n\nJava \n\n for (SmartReplySuggestion suggestion : result.getSuggestions()) {\n String replyText = suggestion.getText();\n }\n\nKotlin \n\n for (suggestion in result.suggestions) {\n val replyText = suggestion.text\n }\n\nNote that ML Kit might not return results if the model isn't confident in\nthe relevance of the suggested replies, the input conversation isn't in\nEnglish, or if the model detects sensitive subject matter."]]