示例#1
0
文件: app.py 项目: udayanvv/datathon
def get_bot_response():
    userText = request.args.get('msg')
    english_bot = ChatBot(
        "Chatterbot",
        storage_adapter="chatterbot.storage.SQLStorageAdapter",
        preprocessors=[
            'chatterbot.preprocessors.clean_whitespace',
            'chatterbot.preprocessors.unescape_html',
            'chatterbot.preprocessors.convert_to_ascii'
        ],
        silence_performance_warning=True,
        response_selection_method=get_most_frequent_response,
        read_only=True,
        logic_adapters=[{
            'import_path': 'chatterbot.logic.BestMatch',
            'default_response': 'I am sorry, but I do not understand.',
            'maximum_similarity_threshold': 0.95
        }])
    english_bot.read_only = True
    return str(english_bot.get_response(userText))
示例#2
0
    "ChatBot",
    logic_adapters=[{
        'import_path': 'chatterbot.logic.BestMatch'
    }, {
        'import_path': 'chatterbot.logic.LowConfidenceAdapter',
        'threshold': confidenceLevel,
        'default_response': 'IDKresponse'
    }],
    response_selection_method=
    get_random_response,  #Comment this out if you want best response
    input_adapter="chatterbot.input.VariableInputTypeAdapter",
    output_adapter="chatterbot.output.OutputAdapter",
    storage_adapter="chatterbot.storage.SQLStorageAdapter",
    database="botData.sqlite3")

bot.read_only = True  #Comment this out if you want the bot to learn based on experience
print("Bot Learn Read Only:" + str(bot.read_only))

#You can comment these out for production later since you won't be training everytime:
#bot.set_trainer(ChatterBotCorpusTrainer)
#bot.train("data/trainingdata.yml")


def tryGoogle(myQuery):
    #print("<br>Try this from my friend Google: <a target='_blank' href='" + j + "'>" + query + "</a>")
    return "<br><br>You can try this from my friend Google: <a target='_blank' href='https://www.google.com/search?q=" + myQuery + "'>" + myQuery + "</a>"


@application.route("/")
def home():
    return render_template("index.html",
示例#3
0
            "import_path": "chatterbot.logic.BestMatch",
            #"statement_comparison_function": "chatterbot.comparisons.JaccardSimilarity",
            #"response_selection_method": "chatterbot.response_selection.get_first_response"
        },
        {
            'import_path':
            'chatterbot.logic.LowConfidenceAdapter',
            'threshold':
            0.1,  #0.6 originally 0.75 not bad
            'default_response':
            "sorry i didn't get you. Did you or didn't you go anywhere this chirstmas?"
        }
    ],
)

chatbot.read_only = True

#chatbot2 first time
chatbot2 = ChatBot(
    "first time",
    storage_adapter="chatterbot.storage.MongoDatabaseAdapter",  # 使用mongo存储数据
    database="2dbn",
    database_uri="mongodb://127.0.0.1:27017/",
    logic_adapters=[
        {
            "import_path": "chatterbot.logic.BestMatch",
            #"statement_comparison_function": "chatterbot.comparisons.JaccardSimilarity",
            #"response_selection_method": "chatterbot.response_selection.get_first_response"
        },
        {
            'import_path':
示例#4
0
from chatterbot import ChatBot
from chatterbot.trainers import ChatterBotCorpusTrainer

# Uncomment the following lines to enable verbose logging
import logging
# logging.basicConfig(level=logging.INFO)
logging.basicConfig(level=logging.DEBUG)

bot = ChatBot(
    "NoteBot",
    storage_adapter="chatterbot.storage.SQLStorageAdapter",
    database_uri="sqlite:///2003database.db",
    logic_adapters=[
        {
            'import_path': 'chatterbot.logic.BestMatch'
        },
        {
            'import_path': 'chatterbot.logic.LowConfidenceAdapter',
            'threshold': 0.25,
            'default_response': 'What?'
        },
    ],
    input_adapter="chatterbot.input.VariableInputTypeAdapter",
    output_adapter="chatterbot.output.OutputAdapter",
)
bot.set_trainer(ChatterBotCorpusTrainer)
bot.train("corpus.out_2003")
bot.read_only = True

print("Train Complete")
示例#5
0
		'import_path': 'acronym_logic_adapter.AcronymLogicAdapter'
	},
	{
		'import_path': 'greeting_logic_adapter.GreetingLogicAdapter'
	},
	{
		'import_path': 'chatterbot.logic.LowConfidenceAdapter',
		'threshold': 0.75,
		'default_response': 'Acronym not found'
	}],
	trainer='chatterbot.trainers.ChatterBotCorpusTrainer'
)

bot.train('data/acronyms/acronyms.yml')
debug("chatterbot is running  ...") #Changement type de training de corpus vers listrainer
bot.read_only = True #desactivation d'apprentissage automatique


@app.route('/message',methods=['POST'])
def post_message():
	request_response = request.get_json(force=True,silent=True)
	content = request_response['content'] #message from user
	print('session ',bot.default_session.id_string)
	response_dict = {'message': bot.get_response(content).text }
	return jsonify(response_dict)

@app.route('/message',methods=['GET'])
def get_message():
	response_dict = {'message': bot.get_response('ITG').text }
	response_json = jsonify(response_dict)
	print(type(response_json))
示例#6
0
## Initialize ChatterBot
bot = ChatBot(
    "ChatBot",
    logic_adapters=[{
        'import_path': 'chatterbot.logic.BestMatch'
    }, {
        'import_path': 'chatterbot.logic.LowConfidenceAdapter',
        'threshold': confidenceLevel,
        'default_response': 'IDKresponse'
    }],
    response_selection_method=
    get_random_response,  #Art der Anwortauswahl -> random
    storage_adapter="chatterbot.storage.SQLStorageAdapter",
    database=currentPath + "/database/botData.sqlite3")

bot.read_only = True  #Comment out um den Bot basierend auf Erfahrungen lernen zu lassen.
logging.info("Bot Learn Read Only:" + str(bot.read_only))

# Diesen Teil nach Deployment ausgrauen, um dauerhaftes Lernen zu vermeiden
bot.set_trainer(ChatterBotCorpusTrainer)
bot.train("chatterbot.corpus.english.greetings",
          "chatterbot.corpus.english.conversations",
          currentPath + "/data/dialogues.yml")

# bot.storage.drop()


## Google fallback if response == IDKresponse
def tryGoogle(myQuery):
    return "<br><br>Gerne kannst du die Hilfe meines Freundes Google in Anspruch nehmen: <a target='_blank' href='https://www.google.com/search?q=" + myQuery + "'>" + myQuery + "</a>"
示例#7
0
from chatterbot import ChatBot
from chatterbot.trainers import ChatterBotCorpusTrainer

bot = ChatBot("Chatterbot",
              storage_adapter="chatterbot.storage.SQLStorageAdapter")
trainer = ChatterBotCorpusTrainer(bot)
trainer.train("data/learning_corpus")  #train the bot
bot.read_only = True  #if True, bot will NOT learning after training