本文整理汇总了Python中chatterbot.ChatBot方法的典型用法代码示例。如果您正苦于以下问题:Python chatterbot.ChatBot方法的具体用法?Python chatterbot.ChatBot怎么用?Python chatterbot.ChatBot使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类chatterbot
的用法示例。
在下文中一共展示了chatterbot.ChatBot方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import chatterbot [as 别名]
# 或者: from chatterbot import ChatBot [as 别名]
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()
示例2: get_response
# 需要导入模块: import chatterbot [as 别名]
# 或者: from chatterbot import ChatBot [as 别名]
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)
示例3: __init__
# 需要导入模块: import chatterbot [as 别名]
# 或者: from chatterbot import ChatBot [as 别名]
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!")
示例4: learn_stop
# 需要导入模块: import chatterbot [as 别名]
# 或者: from chatterbot import ChatBot [as 别名]
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
示例5: predict
# 需要导入模块: import chatterbot [as 别名]
# 或者: from chatterbot import ChatBot [as 别名]
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
示例6: __init__
# 需要导入模块: import chatterbot [as 别名]
# 或者: from chatterbot import ChatBot [as 别名]
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)
示例7: getBot
# 需要导入模块: import chatterbot [as 别名]
# 或者: from chatterbot import ChatBot [as 别名]
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
示例8: setUp
# 需要导入模块: import chatterbot [as 别名]
# 或者: from chatterbot import ChatBot [as 别名]
def setUp(self):
super().setUp()
self.chatbot = ChatBot(**test_settings.CHATTERBOT)
示例9: setUp
# 需要导入模块: import chatterbot [as 别名]
# 或者: from chatterbot import ChatBot [as 别名]
def setUp(self):
self.chatbot = ChatBot('Test Bot', **self.get_kwargs())
示例10: setUp
# 需要导入模块: import chatterbot [as 别名]
# 或者: from chatterbot import ChatBot [as 别名]
def setUp(self):
from chatterbot import ChatBot
self.chatbot = ChatBot('Agent Jr.')
示例11: test_valid_storage_adapter
# 需要导入模块: import chatterbot [as 别名]
# 或者: from chatterbot import ChatBot [as 别名]
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!')
示例12: test_invalid_logic_adapter
# 需要导入模块: import chatterbot [as 别名]
# 或者: from chatterbot import ChatBot [as 别名]
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)
示例13: test_valid_logic_adapter
# 需要导入模块: import chatterbot [as 别名]
# 或者: from chatterbot import ChatBot [as 别名]
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!')
示例14: test_valid_adapter_dictionary
# 需要导入模块: import chatterbot [as 别名]
# 或者: from chatterbot import ChatBot [as 别名]
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!')
示例15: test_invalid_adapter_dictionary
# 需要导入模块: import chatterbot [as 别名]
# 或者: from chatterbot import ChatBot [as 别名]
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)