Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def get_list_trainer(chatbot):
return ListTrainer(
chatbot,
show_training_progress=False
)
def setUp(self):
super().setUp()
self.trainer = ListTrainer(
self.chatbot,
show_training_progress=False
)
def setUp(self):
super().setUp()
from chatterbot.trainers import ListTrainer
from chatterbot.comparisons import sentiment_comparison
self.trainer = ListTrainer(
self.chatbot,
show_training_progress=False
)
self.adapter = BestMatch(
self.chatbot,
statement_comparison_function=sentiment_comparison
)
return transcript
def speak_text(text):
engine = pyttsx3.init()
engine.say(text)
engine.runAndWait()
# works on Drupal FAQ forms
page=requests.get('http://cyberlaunch.vc/faq-page')
soup=BeautifulSoup(page.content, 'lxml')
g=soup.find_all(class_="faq-question-answer")
y=list()
# initialize chatbot parameters
chatbot = ChatBot("CyberLaunch")
chatbot.set_trainer(ListTrainer)
# parse through soup and get Q&A
for i in range(len(g)):
entry=g[i].get_text().replace('\xa0','').split(' \n\n')
newentry=list()
for j in range(len(entry)):
if j==0:
qa=entry[j].replace('\n','')
newentry.append(qa)
else:
qa=entry[j].replace('\n',' ').replace(' ','')
newentry.append(qa)
y.append(newentry)
# train chatbot with Q&A training corpus
def init_chatbot(self):
self.deepThought = ChatBot("deepThought", read_only=True)
self.deepThought.set_trainer(ListTrainer)
self.deepThought.train([
"action",
"嗳,渡边君,真喜欢我?",
"那还用说",
"那么,可依得我两件事?",
"三件也依得",
])
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)
# 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)
def train_by_data_from_database(cls):
cls.set_trainer(ListTrainer)
db = Database()
cur = db.get_cursor()
query = """SELECT msg, replay_to_id FROM messages WHERE replay_to_id IS NOT NULL order by id desc"""
result = db.execute(query)
count = 0
for row in result:
count += 1
answer = row[0]
query = """SELECT msg FROM messages WHERE telegram_id = {replay_to_id}""".format(replay_to_id=row[1])
temp = db.execute(query)
if len(temp) > 0:
statement = temp[0][0]
data_set = [unicode(statement.replace('\n','').strip(), errors='replace'), unicode(answer.replace('\n','').strip(), errors='replace')]
def train(name, data):
bot = getBot(name)
bot.set_trainer(ListTrainer)
bot.train(data)