[go: up one dir, main page]

0% found this document useful (0 votes)
53 views2 pages

Chatterbot Terminal Version: From Import From Import

The document describes how to create a basic chatbot using the Chatterbot library in Python. It shows how to initialize a ChatBot instance, train it with sample responses, and run it in a loop to respond to user input. It also demonstrates how to store the chatbot's data in a SQLite database for persistence between sessions. The chatbot is initialized and run in a terminal interface to have a conversational back-and-forth with the user.

Uploaded by

upendhar rapolu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
53 views2 pages

Chatterbot Terminal Version: From Import From Import

The document describes how to create a basic chatbot using the Chatterbot library in Python. It shows how to initialize a ChatBot instance, train it with sample responses, and run it in a loop to respond to user input. It also demonstrates how to store the chatbot's data in a SQLite database for persistence between sessions. The chatbot is initialized and run in a terminal interface to have a conversational back-and-forth with the user.

Uploaded by

upendhar rapolu
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 2

Chatterbot terminal version

from chatterbot import ChatBot

from chatterbot.trainers import ListTrainer

# Uncomment the following lines to enable verbose logging


#import logging
#logging.basicConfig(level=logging.INFO)
# Create a new chat bot named Charlie
chatbot = ChatBot('Charlie')

trainer = ListTrainer(chatbot)

trainer.train([
"Hi, can I help you?",
"Sure, I'd like to book a flight to Iceland.",
"Your flight has been booked."])

print("Type something to begin...")

# The following loop will execute each time the user enters input
while True:
try:
user_input = input()

bot_response = chatbot.get_response(user_input)

print(bot_response)

# Press ctrl-c or ctrl-d on the keyboard to exit


except (KeyboardInterrupt, EOFError, SystemExit):
break

Chatterbot terminal with sqlite


from chatterbot import ChatBot

# Uncomment the following lines to enable verbose logging


# import logging
# logging.basicConfig(level=logging.INFO)

# Create a new instance of a ChatBot


bot = ChatBot(
'Terminal',
storage_adapter='chatterbot.storage.SQLStorageAdapter',
logic_adapters=[
'chatterbot.logic.MathematicalEvaluation',
'chatterbot.logic.TimeLogicAdapter',
'chatterbot.logic.BestMatch'
],
database_uri='sqlite:///database.db'
)

print('Type something to begin...')

# The following loop will execute each time the user enters input
while True:
try:
user_input = input()
bot_response = bot.get_response(user_input)

print(bot_response)

# Press ctrl-c or ctrl-d on the keyboard to exit


except (KeyboardInterrupt, EOFError, SystemExit):
break

More on https://chatterbot.readthedocs.io/en/latest/examples.html#terminal-example

You might also like