def test_valid_logic_adapter(self):
     kwargs = get_kwargs()
     kwargs['logic_adapters'] = ['chatterbot.logic.BestMatch']
     try:
         self.chatbot = ChatBot('Test Bot', **kwargs)
     except Adapter.InvalidAdapterTypeException:
         self.fail('Test raised InvalidAdapterException unexpectedly!')
 def test_valid_storage_adapter(self):
     kwargs = get_kwargs()
     kwargs['storage_adapter'] = 'chatterbot.storage.SQLStorageAdapter'
     try:
         self.chatbot = ChatBot('Test Bot', **kwargs)
     except Adapter.InvalidAdapterTypeException:
         self.fail('Test raised InvalidAdapterException unexpectedly!')
 def test_invalid_adapter_dictionary(self):
     kwargs = get_kwargs()
     kwargs['storage_adapter'] = {
         'import_path': 'chatterbot.logic.BestMatch'
     }
     with self.assertRaises(Adapter.InvalidAdapterTypeException):
         self.chatbot = ChatBot('Test Bot', **kwargs)
    def __init__(self, *args, **kwargs):
        """
        Create & set window variables.
        """
        tk.Tk.__init__(self, *args, **kwargs)

        self.chatbot = ChatBot(
            "GUI Bot",
            storage_adapter="chatterbot.storage.SQLStorageAdapter",
            logic_adapters=[
                "chatterbot.logic.BestMatch"
            ],
            database_uri="sqlite:///database.sqlite3"
        )

        self.title("Chatterbot")

        self.initialize()
class TkinterGUIExample(tk.Tk):

    def __init__(self, *args, **kwargs):
        """
        Create & set window variables.
        """
        tk.Tk.__init__(self, *args, **kwargs)

        self.chatbot = ChatBot(
            "GUI Bot",
            storage_adapter="chatterbot.storage.SQLStorageAdapter",
            logic_adapters=[
                "chatterbot.logic.BestMatch"
            ],
            database_uri="sqlite:///database.sqlite3"
        )

        self.title("Chatterbot")

        self.initialize()

    def initialize(self):
        """
        Set window layout.
        """
        self.grid()

        self.respond = ttk.Button(self, text='Get Response', command=self.get_response)
        self.respond.grid(column=0, row=0, sticky='nesw', padx=3, pady=3)

        self.usr_input = ttk.Entry(self, state='normal')
        self.usr_input.grid(column=1, row=0, sticky='nesw', padx=3, pady=3)

        self.conversation_lbl = ttk.Label(self, anchor=tk.E, text='Conversation:')
        self.conversation_lbl.grid(column=0, row=1, sticky='nesw', padx=3, pady=3)

        self.conversation = ScrolledText.ScrolledText(self, state='disabled')
        self.conversation.grid(column=0, row=2, columnspan=2, sticky='nesw', padx=3, pady=3)

    def get_response(self):
        """
        Get a response from the chatbot and display it.
        """
        user_input = self.usr_input.get()
        self.usr_input.delete(0, tk.END)

        response = self.chatbot.get_response(user_input)

        self.conversation['state'] = 'normal'
        self.conversation.insert(
            tk.END, "Human: " + user_input + "\n" + "ChatBot: " + str(response.text) + "\n"
        )
        self.conversation['state'] = 'disabled'

        time.sleep(0.5)
Exemple #6
0
class TuringTests(TestCase):
    def setUp(self):
        from app.chatterbot_api.chatterbot import ChatBot

        self.chatbot = ChatBot('Agent Jr.')

    @expectedFailure
    def test_ask_name(self):
        response = self.chatbot.get_response('What is your name?')
        self.assertIn('Agent', response.text)

    @expectedFailure
    def test_repeat_information(self):
        """
        Test if we can detect any repeat responses from the agent.
        """
        self.fail('Condition not met.')

    @expectedFailure
    def test_repeat_input(self):
        """
        Test what the responses are like if we keep giving the same input.
        """
        self.fail('Condition not met.')

    @expectedFailure
    def test_contradicting_responses(self):
        """
        Test if we can get the agent to contradict themselves.
        """
        self.fail('Condition not met.')

    @expectedFailure
    def test_mathematical_ability(self):
        """
        The math questions inherently suggest that the agent
        should get some math problems wrong in order to seem
        more human. My view on this is that it is more useful
        to have a bot that is good at math, which could just
        as easily be a human.
        """
        self.fail('Condition not met.')

    @expectedFailure
    def test_response_time(self):
        """
        Does the agent respond in a realistic amount of time?
        """
        self.fail('Condition not met.')
 def test_invalid_logic_adapter(self):
     kwargs = get_kwargs()
     kwargs['logic_adapters'] = ['chatterbot.storage.StorageAdapter']
     with self.assertRaises(Adapter.InvalidAdapterTypeException):
         self.chatbot = ChatBot('Test Bot', **kwargs)
 def test_invalid_storage_adapter(self):
     kwargs = get_kwargs()
     kwargs['storage_adapter'] = 'chatterbot.logic.LogicAdapter'
     with self.assertRaises(Adapter.InvalidAdapterTypeException):
         self.chatbot = ChatBot('Test Bot', **kwargs)
Exemple #9
0
from app.chatterbot_api.chatterbot import ChatBot
from app.chatterbot_api.chatterbot.trainers import ListTrainer

# Create a new instance of a ChatBot
bot = ChatBot('Example Bot',
              storage_adapter='chatterbot.storage.SQLStorageAdapter',
              logic_adapters=[{
                  'import_path': 'chatterbot.logic.BestMatch',
                  'default_response': 'I am sorry, but I do not understand.',
                  'maximum_similarity_threshold': 0.90
              }])

trainer = ListTrainer(bot)

# Train the chat bot with a few responses
trainer.train([
    'How can I help you?', 'I want to create a chat bot',
    'Have you read the documentation?', 'No, I have not',
    'This should help get you started: http://chatterbot.rtfd.org/en/latest/quickstart.html'
])

# Get a response for some unexpected input
response = bot.get_response('How do I make an omelette?')
print(response)
Exemple #10
0
from app.chatterbot_api.chatterbot import ChatBot


bot = ChatBot(
    'Math & Time Bot',
    logic_adapters=[
        'chatterbot.logic.MathematicalEvaluation',
        'chatterbot.logic.TimeLogicAdapter'
    ]
)

# Print an example of getting one math based response
response = bot.get_response('What is 4 + 9?')
print(response)

# Print an example of getting one time based response
response = bot.get_response('What time is it?')
print(response)
from app.chatterbot_api.chatterbot import ChatBot
from app.chatterbot_api.chatterbot.trainers import ChatterBotCorpusTrainer

'''
This is an example showing how to create an export file from
an existing chat bot that can then be used to train other bots.
'''

chatbot = ChatBot('Export Example Bot')

# First, lets train our bot with some data
trainer = ChatterBotCorpusTrainer(chatbot)

trainer.train('chatterbot.corpus.english')

# Now we can export the data to a file
trainer.export_for_training('./my_export.json')
from app.chatterbot_api.chatterbot import ChatBot
from app.chatterbot_api.chatterbot.conversation import Statement
"""
This example shows how to create a chat bot that
will learn responses based on an additional feedback
element from the user.
"""

# Uncomment the following line to enable verbose logging
# import logging
# logging.basicConfig(level=logging.INFO)

# Create a new instance of a ChatBot
bot = ChatBot('Feedback Learning Bot',
              storage_adapter='chatterbot.storage.SQLStorageAdapter')


def get_feedback():

    text = input()

    if 'yes' in text.lower():
        return True
    elif 'no' in text.lower():
        return False
    else:
        print('Please type either "Yes" or "No"')
        return get_feedback()


print('Type something to begin...')
from app.chatterbot_api.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.sqlite3')

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
Exemple #14
0
from app.chatterbot_api.chatterbot import ChatBot

bot = ChatBot('Jeff', logic_adapters=[])
from app.chatterbot_api.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('SQLMemoryTerminal',
              storage_adapter='chatterbot.storage.SQLStorageAdapter',
              database_uri=None,
              logic_adapters=[
                  'chatterbot.logic.MathematicalEvaluation',
                  'chatterbot.logic.TimeLogicAdapter',
                  'chatterbot.logic.BestMatch'
              ])

# Get a few responses from the bot

bot.get_response('What time is it?')

bot.get_response('What is 7 plus 7?')
Exemple #16
0
from app.chatterbot_api.chatterbot import ChatBot
from app.chatterbot_api.chatterbot.trainers import ListTrainer


'''
This is an example showing how to train a chat bot using the
ChatterBot ListTrainer.
'''

chatbot = ChatBot('Example Bot')

# Start by training our bot with the ChatterBot corpus data
trainer = ListTrainer(chatbot)

trainer.train([
    'Hello, how are you?',
    'I am doing well.',
    'That is good to hear.',
    'Thank you'
])

# You can train with a second list of data to add response variations

trainer.train([
    'Hello, how are you?',
    'I am great.',
    'That is awesome.',
    'Thanks'
])

# Now let's get a response to a greeting
from app.chatterbot_api.chatterbot import ChatBot
from app.chatterbot_api.chatterbot.conversation import Statement

chatbot = ChatBot(
    'Example Bot',
    # This database will be a temporary in-memory database
    database_uri=None)

label_a_statements = [
    Statement(text='Hello', tags=['label_a']),
    Statement(text='Hi', tags=['label_a']),
    Statement(text='How are you?', tags=['label_a'])
]

label_b_statements = [
    Statement(text='I like dogs.', tags=['label_b']),
    Statement(text='I like cats.', tags=['label_b']),
    Statement(text='I like animals.', tags=['label_b'])
]

chatbot.storage.create_many(label_a_statements + label_b_statements)

# Return a response from "label_a_statements"
response_from_label_a = chatbot.get_response(
    'How are you?',
    additional_response_selection_parameters={'tags': ['label_a']})

# Return a response from "label_b_statements"
response_from_label_b = chatbot.get_response(
    'How are you?',
    additional_response_selection_parameters={'tags': ['label_b']})
from app.chatterbot_api.chatterbot import ChatBot

bot = ChatBot('Unit Converter',
              logic_adapters=[
                  'chatterbot.logic.UnitConversion',
              ])

questions = [
    'How many meters are in a kilometer?', 'How many meters are in one inch?',
    '0 celsius to fahrenheit', 'one hour is how many minutes ?'
]

# Prints the convertion given the specific question
for question in questions:
    response = bot.get_response(question)
    print(question + ' -  Response: ' + response.text)
Exemple #19
0
from app.chatterbot_api.chatterbot import ChatBot

# Uncomment the following lines to enable verbose logging
# import logging
# logging.basicConfig(level=logging.INFO)

# Create a new ChatBot instance
bot = ChatBot('Terminal',
              storage_adapter='chatterbot.storage.MongoDatabaseAdapter',
              logic_adapters=['chatterbot.logic.BestMatch'],
              database_uri='mongodb://localhost:27017/chatterbot-database')

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

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
Exemple #20
0
    def setUp(self):
        from app.chatterbot_api.chatterbot import ChatBot

        self.chatbot = ChatBot('Agent Jr.')
Exemple #21
0
 def setUp(self):
     self.chatbot = ChatBot('Test Bot', **self.kwargs)
from app.chatterbot_api.chatterbot import ChatBot
from app.chatterbot_api.chatterbot.trainers import ListTrainer

# 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."
])

# Get a response to the input text 'I would like to book a flight.'
response = chatbot.get_response('I would like to book a flight.')

print(response)