الحل: إنشاء روبوت محادثة آمن يعمل بالذكاء الاصطناعي
قم بمراجعة الحل للتحدي الذي تمت مناقشته في الدرس السابق.
سنغطي ما يلي...
سنغطي ما يلي...
أحسنت على خوض هذا التحدي العملي! 🎉 سواءً نجحت في حل الشيفرة أو وجدت نفسك في حيرة من أمرك، فلا تقلق. صُمم هذا البرنامج ليمنحك خبرة عملية في تطبيق وتخصيص روبوتات الدردشة. مثل هذه التحديات هي طريقتنا في التعلم، بما في ذلك الأخطاء.
الآن، لنستعرض الحل خطوة بخطوة. ستجد أدناه الكود الكامل للمشكلة في أداة الكود. إذا لم تتمكن من حلها بنفسك، فراجع ما أضفناه وسبب إضافته. تذكر، الأمر لا يتعلق بالكمال، بل ببناء فهمك خطوة بخطوة. هيا بنا!
# function to create the chatbot # we have the read_only to false so the chatbot learns from the user input as def create_bot(name): from chatterbot import ChatBot Bot = ChatBot(name = name, read_only = False, logic_adapters = ["chatterbot.logic.BestMatch"], storage_adapter = "chatterbot.storage.SQLStorageAdapter") return Bot # function to train the bot with a variety of topics # the language we have chosen is english # we can train the bot for other languages as well def train_all_data(Bot): from chatterbot.trainers import ChatterBotCorpusTrainer corpus_trainer = ChatterBotCorpusTrainer(Bot) corpus_trainer.train("chatterbot.corpus.english") # function to train the bot with custom data # it uses ListTrainer to train data from lists def custom_train(Bot, conversation): from chatterbot.trainers import ListTrainer trainer = ListTrainer(Bot) trainer.train(conversation) # function to start and take responses from the chatbot # the chatbot stays running unless a word is typed from the bye_list def start_chatbot(Bot): print('\033c') print("Hello, I am Jordan. How can I help you") bye_list = ["bye jordan", "bye", "good bye"] while (True): user_input = input("me: ") if user_input.lower() in bye_list: print("Jordan: Good bye and have a blessed day!") break response = Bot.get_response(user_input) print("Jordan:", response)
Solution code
شرح الكود
في كود الحل أعلاه، أضفنا عدة إضافات للتعامل مع عمليات التحقق من ...