# -*- coding: utf-8 -*-fromchatterbotimportChatBot# Create a new chat bot named Charliechatbot=ChatBot('Charlie',trainer='chatterbot.trainers.ListTrainer')chatbot.train(["Hi, can I help you?","Sure, I'd like to book a flight to Iceland.","Your flight has been booked."])# Get a response to the input text 'How are you?'response=chatbot.get_response('I would like to book a flight.')print(response)

This example program shows how to create a simple terminal client
that allows you to communicate with your chat bot by typing into
your terminal.

# -*- coding: utf-8 -*-fromchatterbotimportChatBot# Uncomment the following lines to enable verbose logging# import logging# logging.basicConfig(level=logging.INFO)# Create a new instance of a ChatBotbot=ChatBot("Terminal",storage_adapter="chatterbot.storage.SQLStorageAdapter",logic_adapters=["chatterbot.logic.MathematicalEvaluation","chatterbot.logic.TimeLogicAdapter","chatterbot.logic.BestMatch"],input_adapter="chatterbot.input.TerminalAdapter",output_adapter="chatterbot.output.TerminalAdapter",database="../database.db")print("Type something to begin...")# The following loop will execute each time the user enters inputwhileTrue:try:# We pass None to this method because the parameter# is not used by the TerminalAdapterbot_input=bot.get_response(None)# Press ctrl-c or ctrl-d on the keyboard to exitexcept(KeyboardInterrupt,EOFError,SystemExit):break

Before you can use ChatterBot’s built in adapter for MongoDB,
you will need to install MongoDB. Make sure MongoDB is
running in your environment before you execute your program.
To tell ChatterBot to use this adapter, you will need to set
the storage_adapter parameter.

storage_adapter="chatterbot.storage.MongoDatabaseAdapter"

# -*- coding: utf-8 -*-fromchatterbotimportChatBot# Uncomment the following lines to enable verbose logging# import logging# logging.basicConfig(level=logging.INFO)# Create a new ChatBot instancebot=ChatBot('Terminal',storage_adapter='chatterbot.storage.MongoDatabaseAdapter',logic_adapters=['chatterbot.logic.BestMatch'],filters=['chatterbot.filters.RepetitiveResponseFilter'],input_adapter='chatterbot.input.TerminalAdapter',output_adapter='chatterbot.output.TerminalAdapter',database='chatterbot-database')print('Type something to begin...')whileTrue:try:bot_input=bot.get_response(None)# Press ctrl-c or ctrl-d on the keyboard to exitexcept(KeyboardInterrupt,EOFError,SystemExit):break

ChatterBot has natural language evaluation capabilities that
allow it to process and evaluate mathematical and time-based
inputs.

# -*- coding: utf-8 -*-fromchatterbotimportChatBotbot=ChatBot("Math & Time Bot",logic_adapters=["chatterbot.logic.MathematicalEvaluation","chatterbot.logic.TimeLogicAdapter"],input_adapter="chatterbot.input.VariableInputTypeAdapter",output_adapter="chatterbot.output.OutputAdapter")# Print an example of getting one math based responseresponse=bot.get_response("What is 4 + 9?")print(response)# Print an example of getting one time based responseresponse=bot.get_response("What time is it?")print(response)

ChatterBot works great with chat rooms. An example for the
popular service Gitter demonstrates this.

# -*- coding: utf-8 -*-fromchatterbotimportChatBotfromsettingsimportGITTER# Uncomment the following lines to enable verbose logging# import logging# logging.basicConfig(level=logging.INFO)chatbot=ChatBot('GitterBot',gitter_room=GITTER['ROOM'],gitter_api_token=GITTER['API_TOKEN'],gitter_only_respond_to_mentions=False,input_adapter='chatterbot.input.Gitter',output_adapter='chatterbot.output.Gitter',trainer='chatterbot.trainers.ChatterBotCorpusTrainer')chatbot.train('chatterbot.corpus.english')# The following loop will execute each time the user enters inputwhileTrue:try:response=chatbot.get_response(None)# Press ctrl-c or ctrl-d on the keyboard to exitexcept(KeyboardInterrupt,EOFError,SystemExit):break

# -*- coding: utf-8 -*-fromchatterbotimportChatBot# Uncomment the following lines to enable verbose logging# import logging# logging.basicConfig(level=logging.INFO)# Create a new instance of a ChatBotbot=ChatBot("SQLMemoryTerminal",storage_adapter='chatterbot.storage.SQLStorageAdapter',logic_adapters=["chatterbot.logic.MathematicalEvaluation","chatterbot.logic.TimeLogicAdapter","chatterbot.logic.BestMatch"],input_adapter="chatterbot.input.TerminalAdapter",output_adapter="chatterbot.output.TerminalAdapter",)print("Type something to begin...")# The following loop will execute each time the user enters inputwhileTrue:try:# We pass None to this method because the parameter# is not used by the TerminalAdapterbot_input=bot.get_response(None)# Press ctrl-c or ctrl-d on the keyboard to exitexcept(KeyboardInterrupt,EOFError,SystemExit):break

Your chat bot will learn based on each new input statement it receives.
If you want to disable this learning feature after your bot has been trained,
you can set read_only=True as a parameter when initializing the bot.