Skip to content

Instantly share code, notes, and snippets.

@LintangWisesa
Created August 12, 2023 05:26
Show Gist options
  • Save LintangWisesa/a80a56fcf1e6526fbf41a370214a4fd8 to your computer and use it in GitHub Desktop.
Save LintangWisesa/a80a56fcf1e6526fbf41a370214a4fd8 to your computer and use it in GitHub Desktop.
Chatterbot - Webinar HIMTI UPI YAI - 12 Aug 2023
# 1. Basic Chatterbot
# python -m pip install ChatterBot==1.0.4
# pip install ChatterBot==1.0.4
from chatterbot import ChatBot
chatbot = ChatBot("Iron Man")
exit_text = ("x", "exit", "quit")
while True:
query = input(" You 🧑 : ")
if query in exit_text:
break
else:
print(f" Bot 🤖 : {chatbot.get_response(query)}")
# 2. Chatterbot List Trainer
from chatterbot import ChatBot
from chatterbot.trainers import ListTrainer
chatbot = ChatBot("Iron Man")
trainer = ListTrainer(chatbot)
trainer.train(["Siapa namamu?", "I am Iron Man"])
exit_text = ("x", "exit", "quit")
while True:
query = input(" You 🧑 : ")
if query in exit_text:
break
else:
print(f" Bot 🤖 : {chatbot.get_response(query)}")
# 3. Chatterbot Corpus
from chatterbot import ChatBot
from chatterbot.trainers import ChatterBotCorpusTrainer
chatbot = ChatBot("Iron Man")
trainer = ChatterBotCorpusTrainer(chatbot)
trainer.train('chatterbot.corpus.indonesia')
exit_text = ("x", "exit", "quit")
while True:
query = input(" You 🧑 : ")
if query in exit_text:
break
else:
print(f" Bot 🤖 : {chatbot.get_response(query)}")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment