这是我的源代码,我得到一个响应,帮助我在chatbot中获得多个响应...我尝试了许多不同的方法,但是没有任何效果..帮助我解决这个问题 假设我发布一个问题,它应该从数据库中返回匹配的多个响应并返回那些答案
from chatterbot import ChatBot
from flask_restful import Resource
from chatterbot.trainers import ListTrainer
from flask import request
from flask_mysqldb import MySQL
from flask import json
from flask import jsonify
chatbot = ChatBot("Training Example",
storage_adapter='chatterbot.storage.SQLStorageAdapter',
database_uri =
"mysql://kiran:kiran@localhost/chatbot",
logic_adapters=[
{
'import_path': 'chatterbot.logic.BestMatch'
},
{
'import_path': 'chatterbot.logic.LowConfidenceAdapter',
'threshold': 0.65,
'default_response': ''
}
])
chatbot.set_trainer(ListTrainer)
chatbot.train([
"Hi there!",
"Hello"])
dd= ["hey","whats up","hello"]
chatbot.train(dd)
class Chatbott(Resource):
def __init__(self):
pass
def get(self):
return("hey")
def post(self):
try:
a = request.get_json()
name = a['name']
if a:
response = chatbot.get_response(name)
if response !=' ':
return response.text
else:
dd.append(a)
print(dd)
return("tiger zinda heeey")
except (KeyboardInterrupt,SystemExit):
print("\n Your loop has been closed . ")
答案 0 :(得分:0)
尝试使用websockes。例如,您可以使用flask-socketio