-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbase.py
More file actions
39 lines (29 loc) · 1.13 KB
/
Copy pathbase.py
File metadata and controls
39 lines (29 loc) · 1.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
from chatterbot.adapters.logic import LogicAdapter
from chatterbot.conversation import Statement
from chatterbot import ChatBot
from flask import Flask
SESSION = {}
class CustomLogicAdapter(LogicAdapter):
def __init__(self, **kwargs):
super(CustomLogicAdapter, self).__init__(kwargs)
def can_process(self, statement):
# Return true if the statement contains the search text
return 'Search for' in statement.text
def process(self, statement, search_text):
text = search_text # ... something you return based on your search
response = Statement(text)
confidence = 0.5
return confidence, response
class OpenStackBot(object):
def __init__(self):
self.trainer = 'chatterbot.trainers.ChatterBotCorpusTrainer'
self.corpus = 'chatterbot.corpus.openstack'
self.chatbot = ChatBot(
'OpenStack Bot',
trainer=self.trainer
)
self.chatbot.train("chatterbot.corpus.english.greetings", self.corpus)
def get_response(self, question):
return self.chatbot.get_response(question)
bot = OpenStackBot()
app = Flask(__name__)