日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程语言 > python >内容正文

python

python微信集成_Python微信公众号后台开发005:集成智能聊天机器人​

發(fā)布時(shí)間:2024/9/27 python 28 豆豆
生活随笔 收集整理的這篇文章主要介紹了 python微信集成_Python微信公众号后台开发005:集成智能聊天机器人​ 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

?給公眾號(hào)集成一個(gè)智能聊天機(jī)器人

一、前述

ChatterBot是一個(gè)基于機(jī)器學(xué)習(xí)的聊天機(jī)器人引擎,構(gòu)建在python上,主要特點(diǎn)是可以自可以從已有的對(duì)話中進(jìn)行學(xué)(jiyi)習(xí)(pipei)。

二、具體

1、安裝

是的,安裝超級(jí)簡(jiǎn)單,用pip就可以啦

pip install chatterbot

2、流程

大家已經(jīng)知道chatterbot的聊天邏輯和輸入輸出以及存儲(chǔ),是由各種adapter來(lái)限定的,我們先看看流程圖,一會(huì)再一起看點(diǎn)例子,看看怎么用。

image

3、每個(gè)部分都設(shè)計(jì)了不同的“適配器”(Adapter)。

機(jī)器人應(yīng)答邏輯 => Logic Adapters

Closest Match Adapter 字符串模糊匹配(編輯距離)

Closest Meaning Adapter ?借助nltk的WordNet,近義詞評(píng)估

Time Logic Adapter 處理涉及時(shí)間的提問(wèn)

Mathematical Evaluation Adapter?涉及數(shù)學(xué)運(yùn)算

存儲(chǔ)器后端 => Storage Adapters

Read Only Mode 只讀模式,當(dāng)有輸入數(shù)據(jù)到chatterbot的時(shí)候,數(shù)

據(jù)庫(kù)并不會(huì)發(fā)生改變

Json Database Adapter 用以存儲(chǔ)對(duì)話數(shù)據(jù)的接口,對(duì)話數(shù)據(jù)以Json格式

進(jìn)行存儲(chǔ)。

Mongo Database Adapter ?以MongoDB database方式來(lái)存儲(chǔ)對(duì)話數(shù)據(jù)

輸入形式 => Input Adapters

Variable input type adapter 允許chatter bot接收不同類(lèi)型的輸入的,如strings,dictionaries和Statements

Terminal adapter 使得ChatterBot可以通過(guò)終端進(jìn)行對(duì)話

HipChat Adapter 使得ChatterBot 可以從HipChat聊天室獲取輸入語(yǔ)句,通過(guò)HipChat 和 ChatterBot 進(jìn)行對(duì)話

Speech recognition 語(yǔ)音識(shí)別輸入,詳見(jiàn)chatterbot-voice

輸出形式 => Output Adapters

Output format adapter支持text,json和object格式的輸出

Terminal adapter

HipChat Adapter

Mailgun adapter允許chat bot基于Mailgun API進(jìn)行郵件的發(fā)送

Speech synthesisTTS(Text to speech)部分,詳見(jiàn)chatterbot-voice

4、代碼

計(jì)算模式

from chatterbot import ChatBot

bot = ChatBot(

"Math & Time Bot",

logic_adapters=[

"chatterbot.logic.MathematicalEvaluation",

"chatterbot.logic.TimeLogicAdapter"

],

input_adapter="chatterbot.input.VariableInputTypeAdapter",

output_adapter="chatterbot.output.OutputAdapter"

)

# 進(jìn)行數(shù)學(xué)計(jì)算

question = "What is 4 + 9?"

print(question)

response = bot.get_response(question)

print(response)

print("\n")

# 回答和時(shí)間相關(guān)的問(wèn)題

question = "What time is it?"

print(question)

response = bot.get_response(question)

print(response)

image

利用已經(jīng)提供好的小中文語(yǔ)料庫(kù)

from chatterbot import ChatBot

from chatterbot.trainers import ChatterBotCorpusTrainer

chatbot = ChatBot("ChineseChatBot")

trainer = ChatterBotCorpusTrainer(chatbot)

# 使用中文語(yǔ)料庫(kù)訓(xùn)練它

trainer.train("chatterbot.corpus.chinese")

def response_text(sentence):

res_text = chatbot.get_response(sentence)

print(sentence , "----", res_text)

return res_text

#

if __name__ == '__main__':

# 開(kāi)始對(duì)話

while True:

print(chatbot.get_response(input(">")))

# print(response_text("你是誰(shuí)"))

image

小黃雞語(yǔ)料更智能(推薦)

from chatterbot import ChatBot

bot = ChatBot('my-chat', database_uri='sqlite:///db.sqlite3')

def response_text(sentence):

temp = bot.get_response(sentence)

return temp.text

if __name__ == '__main__':

# bot_response = response_text("你幾歲了")

# print(bot_response)

# 開(kāi)始對(duì)話

while True:

print(response_text(input(">")))

image

小黃雞語(yǔ)料數(shù)據(jù)庫(kù):

Snip20191204_47.png

總結(jié)

以上是生活随笔為你收集整理的python微信集成_Python微信公众号后台开发005:集成智能聊天机器人​的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。