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

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程语言 > python >内容正文

python

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

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

?給公眾號集成一個智能聊天機器人

一、前述

ChatterBot是一個基于機器學習的聊天機器人引擎,構建在python上,主要特點是可以自可以從已有的對話中進行學(jiyi)習(pipei)。

二、具體

1、安裝

是的,安裝超級簡單,用pip就可以啦

pip install chatterbot

2、流程

大家已經知道chatterbot的聊天邏輯和輸入輸出以及存儲,是由各種adapter來限定的,我們先看看流程圖,一會再一起看點例子,看看怎么用。

image

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

機器人應答邏輯 => Logic Adapters

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

Closest Meaning Adapter ?借助nltk的WordNet,近義詞評估

Time Logic Adapter 處理涉及時間的提問

Mathematical Evaluation Adapter?涉及數學運算

存儲器后端 => Storage Adapters

Read Only Mode 只讀模式,當有輸入數據到chatterbot的時候,數

據庫并不會發生改變

Json Database Adapter 用以存儲對話數據的接口,對話數據以Json格式

進行存儲。

Mongo Database Adapter ?以MongoDB database方式來存儲對話數據

輸入形式 => Input Adapters

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

Terminal adapter 使得ChatterBot可以通過終端進行對話

HipChat Adapter 使得ChatterBot 可以從HipChat聊天室獲取輸入語句,通過HipChat 和 ChatterBot 進行對話

Speech recognition 語音識別輸入,詳見chatterbot-voice

輸出形式 => Output Adapters

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

Terminal adapter

HipChat Adapter

Mailgun adapter允許chat bot基于Mailgun API進行郵件的發送

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

4、代碼

計算模式

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"

)

# 進行數學計算

question = "What is 4 + 9?"

print(question)

response = bot.get_response(question)

print(response)

print("\n")

# 回答和時間相關的問題

question = "What time is it?"

print(question)

response = bot.get_response(question)

print(response)

image

利用已經提供好的小中文語料庫

from chatterbot import ChatBot

from chatterbot.trainers import ChatterBotCorpusTrainer

chatbot = ChatBot("ChineseChatBot")

trainer = ChatterBotCorpusTrainer(chatbot)

# 使用中文語料庫訓練它

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__':

# 開始對話

while True:

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

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

image

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

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)

# 開始對話

while True:

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

image

小黃雞語料數據庫:

Snip20191204_47.png

總結

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

如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。