欧美bbbwbbbw肥妇,免费乱码人妻系列日韩,一级黄片

Python?NLP開發(fā)之實現聊天機器人

 更新時間:2023年05月08日 08:40:58   作者:愛看書的小沐  
這篇文章主要為大家介紹了Python如何實現聊天機器人,即使用自然語言處理?(NLP)?來幫助用戶通過文本、圖形或語音與?Web?服務或應用進行交互,感興趣的可以了解一下

1、簡介

AI 聊天機器人使用自然語言處理 (NLP) 來幫助用戶通過文本、圖形或語音與 Web 服務或應用進行交互。聊天機器人可以理解自然人類語言、模擬人類對話并運行簡單的自動化任務。此外,AI 聊天機器人還利用預測智能和分析技術來了解用戶的偏好,并利用了解的這些信息來提供建議和預測需求

AI 聊天機器人用于各種渠道,例如消息傳遞應用、移動應用、網站、電話線路和支持語音的應用。它們可以針對不同目的而開發(fā),無論是僅處理一些簡單的命令,還是充當復雜的數字助理和交互式代理。AI 聊天機器人可以是大型應用程序的一部分,也可以完全獨立存在

2、代碼測試

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('微夢機器人:', 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('海知機器人:', 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('萬維易源機器人:', 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('進制機器人:', 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('極速機器人:', 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構造請求參數
    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('小度機器人:這句話翻譯為中文是',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機器人:',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('天行機器人:', 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機器人:" + 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('青云客機器人:', 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('思知機器人:', js['data']['info']['text'])

以上就是Python NLP開發(fā)之實現聊天機器人的詳細內容,更多關于Python聊天機器人的資料請關注腳本之家其它相關文章!

相關文章

  • python三大器之裝飾器詳解

    python三大器之裝飾器詳解

    這篇文章主要介紹了Python中的裝飾器,涉及到Python中很多重要的特性,小編覺得這篇文章寫的還不錯,需要的朋友可以參考下
    2021-10-10
  • jupyter notebook 的工作空間設置操作

    jupyter notebook 的工作空間設置操作

    這篇文章主要介紹了jupyter notebook 的工作空間設置操作,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2020-04-04
  • 詳解Python如何優(yōu)雅地解析命令行

    詳解Python如何優(yōu)雅地解析命令行

    隨著我們編程經驗的增長,對命令行的熟悉程度日漸加深,想來很多人會漸漸地體會到使用命令行帶來的高效率。本文將介紹Python解析命令行的兩種方法,需要的可以參考一下
    2022-06-06
  • 使用python數據清洗代碼實例

    使用python數據清洗代碼實例

    這篇文章主要介紹了使用python數據清洗代碼實例,分享一下近期用python做數據清洗匯總的相關代碼,這里我們用到的python包有pandas、numpy、os等,需要的朋友可以參考下
    2023-07-07
  • 在pytorch中為Module和Tensor指定GPU的例子

    在pytorch中為Module和Tensor指定GPU的例子

    今天小編就為大家分享一篇在pytorch中為Module和Tensor指定GPU的例子,具有很好的參考價值,希望對大家有所幫助。一起跟隨小編過來看看吧
    2019-08-08
  • Python異常處理例題整理

    Python異常處理例題整理

    在本篇文章里
    2019-07-07
  • Python計算矩陣的和積的實例詳解

    Python計算矩陣的和積的實例詳解

    在本篇內容里小編給大家整理的是關于Python計算矩陣的和積的實例詳解內容,需要的朋友們參考下。
    2020-09-09
  • Python 使用openpyxl處理Excel文件詳情

    Python 使用openpyxl處理Excel文件詳情

    這篇文章主要介紹了Python 使用openpyxl處理Excel文件詳情,文章圍繞主題展開詳細的內容介紹,具有一定的參考價值,需要的小伙伴可以參考一下
    2022-08-08
  • python驗證碼圖片處理(二值化)

    python驗證碼圖片處理(二值化)

    這篇文章主要介紹了python驗證碼圖片處理(二值化),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧
    2019-11-11
  • python匿名函數的使用方法解析

    python匿名函數的使用方法解析

    這篇文章主要介紹了python匿名函數的使用方法解析,文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友可以參考下
    2019-10-10

最新評論