Python + 图灵机器人APIv2.0 = 实现两个机器人互相聊天
获取图灵机器人API KEY
首先,前往图灵机器人官方网站 http://www.tuling123.com/ 注册账号。
登录后点击 创建机器人 ,填写一些简单的基本信息之后即可创建。
Python3源代码
基本原理就是使用urllib.request模块,向接口地址发送HTTP POST请求,请求中加入了聊天内容。
import json
import urllib.request
import time
api_url = "http://openapi.tuling123.com/openapi/api/v2"
api_key_1 = "请替换为你的API KEY 1"
api_key_2 = "请替换为你的API KEY 2"
tag = 0
api_key = api_key_1
text_input = input('对话起点:')
while True:
req = {
"perception":
{
"inputText":