Python chatterbot.ChatBot() Examples
The following are 18
code examples of chatterbot.ChatBot().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
chatterbot
, or try the search function
.

Example #1
Source File: tkinter_gui.py From ChatterBot with BSD 3-Clause "New" or "Revised" License | 7 votes |
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()
Example #2
Source File: chat_bot1.py From BotHub with Apache License 2.0 | 6 votes |
def learn_stop(event): if event.fwd_from: return chat = event.pattern_match.group(1) if MONGO_URI is None: await event.edit("Critical Error: Add Your MongoDB connection String in Env vars.") return if chat: try: learn_chat.delete_one({'chat_id':int(chat)}) await event.edit("ChatBot Auto learning stopped for Chat: "+chat) except Exception as e: await event.edit("Error:\n{}".format(str(e))) else: chat = event.chat_id learn_chat.delete_one({'chat_id':chat}) await event.edit("ChatBot Auto learning stopped for Chat: "+str(chat)) await asyncio.sleep(1) await event.delete() #ChatBot Event Handler
Example #3
Source File: base_case.py From ChatterBot with BSD 3-Clause "New" or "Revised" License | 6 votes |
def setUp(self): super().setUp() self.chatbot = ChatBot(**test_settings.CHATTERBOT)
Example #4
Source File: tkinter_gui.py From ChatterBot with BSD 3-Clause "New" or "Revised" License | 6 votes |
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)
Example #5
Source File: base_case.py From ChatterBot with BSD 3-Clause "New" or "Revised" License | 6 votes |
def setUp(self): self.chatbot = ChatBot('Test Bot', **self.get_kwargs())
Example #6
Source File: test_turing.py From ChatterBot with BSD 3-Clause "New" or "Revised" License | 6 votes |
def setUp(self): from chatterbot import ChatBot self.chatbot = ChatBot('Agent Jr.')
Example #7
Source File: chatbot.py From messenger-maid-chan with MIT License | 6 votes |
def __init__(self, storage_adapter): self.initialize() # Initialize corpus files self.chatbot = ChatBot( 'Maid-chan', trainer='chatterbot.trainers.ChatterBotCorpusTrainer', output_adapter="chatterbot.output.OutputAdapter", output_format='text', storage_adapter=storage_adapter ) self.chatbot.train( "chatterbot.corpus.indonesia.conversations", "chatterbot.corpus.indonesia.greetings", "chatterbot.corpus.english.conversations", "chatterbot.corpus.english.greetings", "chatterbot.corpus.maidcorpus" # Custom! ) logging.info("Chatterbot is initialized!")
Example #8
Source File: test_adapter_validation.py From ChatterBot with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_invalid_logic_adapter(self): kwargs = self.get_kwargs() kwargs['logic_adapters'] = ['chatterbot.storage.StorageAdapter'] with self.assertRaises(Adapter.InvalidAdapterTypeException): self.chatbot = ChatBot('Test Bot', **kwargs)
Example #9
Source File: chatter.py From Trusty-cogs with MIT License | 5 votes |
def __init__(self, bot): self.bot = bot default_guild = { "auto_train": False, "blacklist": [], "whitelist": [], "auto_response": False, } default_channel = {"message": None, "author": None} self.config = Config.get_conf(self, 218773382617890828) self.config.register_guild(**default_guild) self.config.register_channel(**default_channel) # https://github.com/bobloy/Fox-V3/blob/master/chatter/chat.py path = cog_data_path(self) data_path = path / "database.sqlite3" self.chatbot = ChatBot( "ChatterBot", storage_adapter="chatterbot.storage.SQLStorageAdapter", database=str(data_path), statement_comparison_function=levenshtein_distance, response_selection_method=get_first_response, logic_adapters=[ {"import_path": "chatterbot.logic.BestMatch", "default_response": ":thinking:"} ], ) self.trainer = ListTrainer(self.chatbot)
Example #10
Source File: chat_bot1.py From BotHub with Apache License 2.0 | 5 votes |
def learn_start(event): if event.fwd_from: return chat = event.pattern_match.group(1) if MONGO_URI is None: await event.edit("Critical Error: Add Your MongoDB connection String in Env vars.") return chats = learn_chat.find({}) if chat: try: for c in chats: if int(chat) == c['chat_id']: await event.edit("This Chat is Already in Learning Chats.") return learn_chat.insert_one({'chat_id':int(chat)}) await event.edit("ChatBot Auto learning started for Chat: "+chat) except Exception as e: await event.edit("Error:\n{}".format(str(e))) else: chat = event.chat_id for c in chats: if int(chat) == c['chat_id']: await event.edit("This Chat is Already in Learning Chats.") return learn_chat.insert_one({'chat_id':chat}) await event.edit("ChatBot Auto learning started for Chat: "+str(chat)) await asyncio.sleep(1) await event.delete()
Example #11
Source File: talk.py From PantherBot with Mozilla Public License 2.0 | 5 votes |
def run(response, args=[]): response_obj = Response(sys.modules[__name__]) cb = ChatBot('PantherBot') cb.set_trainer(ChatterBotCorpusTrainer) cb.train( "chatterbot.corpus.english" ) try: response_obj.messages_to_send.append(cb.get_response(" ".join(args)).text) except: response_obj.messages_to_send.append("I'm feeling sick... come back later") return response_obj
Example #12
Source File: test_adapter_validation.py From ChatterBot with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_invalid_adapter_dictionary(self): kwargs = self.get_kwargs() kwargs['storage_adapter'] = { 'import_path': 'chatterbot.logic.BestMatch' } with self.assertRaises(Adapter.InvalidAdapterTypeException): self.chatbot = ChatBot('Test Bot', **kwargs)
Example #13
Source File: test_adapter_validation.py From ChatterBot with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_valid_adapter_dictionary(self): kwargs = self.get_kwargs() kwargs['storage_adapter'] = { 'import_path': 'chatterbot.storage.SQLStorageAdapter' } try: self.chatbot = ChatBot('Test Bot', **kwargs) except Adapter.InvalidAdapterTypeException: self.fail('Test raised InvalidAdapterException unexpectedly!')
Example #14
Source File: test_adapter_validation.py From ChatterBot with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_valid_logic_adapter(self): kwargs = self.get_kwargs() kwargs['logic_adapters'] = ['chatterbot.logic.BestMatch'] try: self.chatbot = ChatBot('Test Bot', **kwargs) except Adapter.InvalidAdapterTypeException: self.fail('Test raised InvalidAdapterException unexpectedly!')
Example #15
Source File: chatterbot.py From Trusty-cogs-archive with MIT License | 5 votes |
def __init__(self, bot): self.bot = bot self.settings = dataIO.load_json("data/chatterbot/settings.json") self.log = dataIO.load_json("data/chatterbot/log.json") self.chatbot = chatterbot.ChatBot("redbot", storage_adapter="chatterbot.storage.MongoDatabaseAdapter", # database="data/chatterbot/db", logic_adapters=[ "chatterbot.logic.BestMatch", "chatterbot.logic.TimeLogicAdapter", "chatterbot.logic.MathematicalEvaluation"] ) self.chatbot.set_trainer(ListTrainer)
Example #16
Source File: test_adapter_validation.py From ChatterBot with BSD 3-Clause "New" or "Revised" License | 5 votes |
def test_valid_storage_adapter(self): kwargs = self.get_kwargs() kwargs['storage_adapter'] = 'chatterbot.storage.SQLStorageAdapter' try: self.chatbot = ChatBot('Test Bot', **kwargs) except Adapter.InvalidAdapterTypeException: self.fail('Test raised InvalidAdapterException unexpectedly!')
Example #17
Source File: chatbot.py From sia-cog with MIT License | 5 votes |
def predict(name, text): botfolder = "./data/__chatbot/" + name service = projectmgr.GetService(name, constants.ServiceTypes.ChatBot) botjson = json.loads(service.servicedata) bot = getBot(name) response = bot.get_response(text.lower()) result = {"confidence": response.confidence, "response_text": response.text} if float(response.confidence) < float(botjson["threshold"]): result = {"confidence": response.confidence, "response_text": botjson["default_response"]} return result
Example #18
Source File: chatbot.py From sia-cog with MIT License | 5 votes |
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" } ] ) return bot