Python?NLP開(kāi)發(fā)之實(shí)現(xiàn)聊天機(jī)器人
1、簡(jiǎn)介
AI 聊天機(jī)器人使用自然語(yǔ)言處理 (NLP) 來(lái)幫助用戶通過(guò)文本、圖形或語(yǔ)音與 Web 服務(wù)或應(yīng)用進(jìn)行交互。聊天機(jī)器人可以理解自然人類語(yǔ)言、模擬人類對(duì)話并運(yùn)行簡(jiǎn)單的自動(dòng)化任務(wù)。此外,AI 聊天機(jī)器人還利用預(yù)測(cè)智能和分析技術(shù)來(lái)了解用戶的偏好,并利用了解的這些信息來(lái)提供建議和預(yù)測(cè)需求
AI 聊天機(jī)器人用于各種渠道,例如消息傳遞應(yīng)用、移動(dòng)應(yīng)用、網(wǎng)站、電話線路和支持語(yǔ)音的應(yīng)用。它們可以針對(duì)不同目的而開(kāi)發(fā),無(wú)論是僅處理一些簡(jiǎn)單的命令,還是充當(dāng)復(fù)雜的數(shù)字助理和交互式代理。AI 聊天機(jī)器人可以是大型應(yīng)用程序的一部分,也可以完全獨(dú)立存在
2、代碼測(cè)試
2.1 open.drea.cc
import requests import json while True: msg = input('我:') sess = requests.get( ('https://open.drea.cc/bbsapi/chat/get?keyWord=' + msg + '&userName=type%3Dbbs')) js = sess.text js = json.loads(js) print('微夢(mèng)機(jī)器人:', js['data']['reply'])
2.2 api.ruyi.ai
import requests import json while True: msg = input('我:') sess = requests.get(('http://api.ruyi.ai/v1/message?app_key=your_key&user_id=test123&q=' + msg)) js = sess.text js = json.loads(js) js = js['result']['intents'] js = js[0]['result']['text'] print('海知機(jī)器人:', js)
2.3 route.showapi.com
import requests import json while True: msg = input('我:') sess = requests.get( ('http://route.showapi.com/60-27?&showapi_appid=102421&userid=userid&showapi_sign=your_key&info=' + msg)) js = sess.text js = json.loads(js) print('萬(wàn)維易源機(jī)器人:', js['showapi_res_body']['text'])
2.4 api.binstd.com
import requests import json while True: msg = input('我:') sess = requests.get( ('https://api.binstd.com/iqa/query?appkey=your_key&question=' + msg)) js = sess.text js = json.loads(js) print('進(jìn)制機(jī)器人:', js['result']['content'])
2.5 api.jisuapi.com
import requests import json while True: msg = input('我:') sess = requests.get(('https://api.jisuapi.com/iqa/query?appkey=c0e4885a90566a7b&question=' + msg)) js = sess.text js = json.loads(js) print('極速機(jī)器人:', js['result']['content'])
2.6 api.fanyi.baidu.com
import requests import string import time import hashlib import json #init api_url = "http://api.fanyi.baidu.com/api/trans/vip/translate" my_appid = 'your_key' cyber = 'your_cyber ' lower_case = list(string.ascii_lowercase) def requests_for_dst(word): #init salt and final_sign salt = str(time.time())[:10] final_sign = str(my_appid)+word+salt+cyber final_sign = hashlib.md5(final_sign.encode("utf-8")).hexdigest() #區(qū)別en,zh構(gòu)造請(qǐng)求參數(shù) if list(word)[0] in lower_case: paramas = { 'q': word, 'from': 'en', 'to': 'zh', 'appid': '%s' % my_appid, 'salt': '%s' % salt, 'sign': '%s' % final_sign } my_url = api_url+'?appid=' + \ str(my_appid)+'&q='+word+'&from='+'en'+'&to=' + \ 'zh'+'&salt='+salt+'&sign='+final_sign else: paramas = { 'q': word, 'from': 'zh', 'to': 'en', 'appid': '%s' % my_appid, 'salt': '%s' % salt, 'sign': '%s' % final_sign } my_url = api_url+'?appid=' + \ str(my_appid)+'&q='+word+'&from='+'zh'+'&to=' + \ 'en'+'&salt='+salt+'&sign='+final_sign response = requests.get(api_url, params=paramas).content content = str(response, encoding="utf-8") json_reads = json.loads(content) print('小度機(jī)器人:這句話翻譯為中文是',json_reads['trans_result'][0]['dst']) while True: word = input("我: ") requests_for_dst(word)
2.7 aiml
import aiml import sys import os def get_module_dir(name): print("module", sys.modules[name]) path = getattr(sys.modules[name], '__file__', None) print(path) if not path: raise AttributeError('module %s has not attribute __file__' % name) return os.path.dirname(os.path.abspath(path)) alice_path = get_module_dir('aiml') + '\\botdata\\alice' os.chdir(alice_path) alice = aiml.Kernel() alice.learn("startup.xml") alice.respond('LOAD ALICE') while True: message = input("我:") if("exit" == message): exit() response = alice.respond(message) print('AIML機(jī)器人:',response)
2.8 api.tianapi.com
import requests import json while True: msg = input('我:') sess = requests.get(('http://api.tianapi.com/txapi/robot/index?key=your_key&question=' + msg)) js = sess.text js = json.loads(js) print('天行機(jī)器人:', js['newslist'])
2.9 nlp.xiaoi.com
import urllib.request,re while True: msg = input("我:") msg = urllib.parse.quote(msg) link = urllib.request.urlopen( "http://nlp.xiaoi.com/robot/webrobot?&callback=__webrobot_processMsg&data=%7B%22sessionId%22%3A%22ff725c236e5245a3ac825b2dd88a7501%22%2C%22robotId%22%3A%22webbot%22%2C%22userId%22%3A%227cd29df3450745fbbdcf1a462e6c58e6%22%2C%22body%22%3A%7B%22content%22%3A%22" + msg + "%22%7D%2C%22type%22%3A%22txt%22%7D") html_doc = link.read().decode() reply_list = re.findall(r'\"content\":\"(.+?)\\r\\n\"', html_doc) print("小i機(jī)器人:" + reply_list[-1])
2.10 api.qingyunke.com
import requests,json while True: msg = input("我:") js = requests.get("http://api.qingyunke.com/api.php",{'key': 'free', 'appid': 0, 'msg': msg}) js.encoding = 'utf8' js = js.json() print('青云客機(jī)器人:', js['content'])
2.11 api.ownthink.com
import requests,json while True: msg = input('我:') sess = requests.get(('https://api.ownthink.com/bot?spoken=' + msg)) js = sess.text js = json.loads(js) print('思知機(jī)器人:', js['data']['info']['text'])
以上就是Python NLP開(kāi)發(fā)之實(shí)現(xiàn)聊天機(jī)器人的詳細(xì)內(nèi)容,更多關(guān)于Python聊天機(jī)器人的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
jupyter notebook 的工作空間設(shè)置操作
這篇文章主要介紹了jupyter notebook 的工作空間設(shè)置操作,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2020-04-04使用python數(shù)據(jù)清洗代碼實(shí)例
這篇文章主要介紹了使用python數(shù)據(jù)清洗代碼實(shí)例,分享一下近期用python做數(shù)據(jù)清洗匯總的相關(guān)代碼,這里我們用到的python包有pandas、numpy、os等,需要的朋友可以參考下2023-07-07在pytorch中為Module和Tensor指定GPU的例子
今天小編就為大家分享一篇在pytorch中為Module和Tensor指定GPU的例子,具有很好的參考價(jià)值,希望對(duì)大家有所幫助。一起跟隨小編過(guò)來(lái)看看吧2019-08-08