图灵机器人

图灵机器人网址:http://www.turingapi.com/

步骤:注册一个账号 --> 登录 --> 创建机器人 --> 打开机器人 --> 获取apikey --> 打开api使用文档 --> 接入教程 --> API V2.0接入文档 --> 获取接口地址

那么现在开始写程序:

play.py

#!/usr/bin/env python
# _*_ coding: UTF-8 _*_
"""=================================================
@Project -> File    : Operate_system_ModeView_structure -> play.py
@IDE     : PyCharm
@Author  : zihan
@Date    : 2020/5/7 14:50
@Desc    :图灵机器人  -- 没绑定微信版
================================================="""
import requests


def get_response(msg):
    url = "http://openapi.tuling123.com/openapi/api/v2"
    data = {
        "reqType": 0,
        "perception": {
            "inputText": {
                "text": msg
            },
        },
        "userInfo": {
            "apiKey": apikey,
            "userId": "zihan"
        }
    }
    result = requests.post(url, json=data).json()

    return result['results'][0]['values']['text']


def main():
    # 用户输入
    while True:
        # 输入自己说的话
        msg = input('我:')

        # 获取机器人回复的消息
        msg_response = get_response(msg)

        # 输出机器人回的话
        print("机器人:" + msg_response)


if __name__ == '__main__':
    main()

效果图:

这个也就是用来好玩的,哈哈哈。

原文地址:https://www.cnblogs.com/smart-zihan/p/12848588.html