Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def setUp(self):
self.test_data_directory = None
self.chatbot = ChatBot('Test Bot', **self.get_kwargs())
def test_invalid_storage_adapter(self):
kwargs = self.get_kwargs()
kwargs['storage_adapter'] = 'chatterbot.logic.LogicAdapter'
with self.assertRaises(Adapter.InvalidAdapterTypeException):
self.chatbot = ChatBot('Test Bot', **kwargs)
# -*- coding: utf-8 -*-
from chatterbot import ChatBot
from chatterbot.trainers import ChatterBotCorpusTrainer
from settings import HIPCHAT
'''
See the HipChat api documentation for how to get a user access token.
https://developer.atlassian.com/hipchat/guide/hipchat-rest-api/api-access-tokens
'''
chatbot = ChatBot(
'HipChatBot',
hipchat_host=HIPCHAT['HOST'],
hipchat_room=HIPCHAT['ROOM'],
hipchat_access_token=HIPCHAT['ACCESS_TOKEN'],
input_adapter='chatterbot.input.HipChat',
output_adapter='chatterbot.output.HipChat'
)
trainer = ChatterBotCorpusTrainer(chatbot)
trainer.train('chatterbot.corpus.english')
# The following loop will execute each time the user enters input
while True:
try:
response = chatbot.get_response(None)
def getBot(name):
botfolder = "./data/__chatbot/" + name
if not os.path.exists(botfolder):
os.makedirs(botfolder)
dbpath = "sqlite:///" + botfolder + "/bot.db"
bot = ChatBot(
name,
storage_adapter='chatterbot.storage.SQLStorageAdapter',
database_uri=dbpath,
filters=["chatterbot.filters.RepetitiveResponseFilter"],
preprocessors=[
'chatterbot.preprocessors.clean_whitespace',
'chatterbot.preprocessors.convert_to_ascii'
],
logic_adapters=[
{
'import_path': 'chatterbot.logic.BestMatch',
"statement_comparision_function": "chatterbot.comparisions.levenshtein_distance",
"response_selection_method": "chatterbot.response_selection.get_first_response"
}
]
)
from chatterbot import ChatBot
# Create a new instance of a ChatBot
bot = ChatBot(
'Exact Response Example Bot',
storage_adapter='chatterbot.storage.SQLStorageAdapter',
logic_adapters=[
{
'import_path': 'chatterbot.logic.BestMatch'
},
{
'import_path': 'chatterbot.logic.SpecificResponseAdapter',
'input_text': 'Help me!',
'output_text': 'Ok, here is a link: http://chatterbot.rtfd.org'
}
]
)
# Get a response given the specific input
response = bot.get_response('Help me!')
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 get_cb(db):
global cb_cache
if not cb_cache:
cb_cache = ChatBot(
"Sigma",
database='chatterbot',
database_uri=db.db_address,
storage_adapter='chatterbot.storage.MongoDatabaseAdapter',
output_format='text'
)
return cb_cache
def handle(self, *args, **options):
from chatterbot import ChatBot
from chatterbot.ext.django_chatterbot import settings
chatterbot = ChatBot(**settings.CHATTERBOT)
chatterbot.train(chatterbot.training_data)
style = self.style.SUCCESS
self.stdout.write(style('Starting training...'))
training_class = chatterbot.trainer.__class__.__name__
self.stdout.write(style('ChatterBot trained using "%s"' % training_class))
# chatbot/bot.py
from chatterbot import ChatBot
from chatterbot.trainers import ChatterBotCorpusTrainer
diego = ChatBot("Diego")
trainer = ChatterBotCorpusTrainer(diego)
trainer.train(
"chatterbot.corpus.english.greetings",
"chatterbot.corpus.english.conversations",
)