<filename>src/Chatbot/tuliing-html/tuling_test.py
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
#-------------------------------------------------------------------------------
'''
@Author  :   {SEASON}
@License :   (C) Copyright 2013-2022, {OLD_IT_WANG}
@Contact :   {<EMAIL>}
@Software:   PyCharm
@File    :   NLP_DEMO -- tuling_test
@Time    :   2020/6/3 15:18
@Desc    :
api 文档：https://www.kancloud.cn/turing/www-tuling123-com/718227

'''
#-------------------------------------------------------------------------------

import json
import urllib.request

api_url = "http://openapi.tuling123.com/openapi/api/v2"
text_input = input('我：')

req = {
    "perception":
    {
        "inputText":
        {
            "text": text_input
        },
    },

    "userInfo":
    {
        "apiKey": "8a55d83078324f189cfa7a0c6e769b06",
        "userId": "OnlyUseAlphabet"
    }
}
# print(req)
# 将字典格式的req编码为utf8
req = json.dumps(req).encode('utf8')
# print(req)

http_post = urllib.request.Request(api_url, data=req, headers={'content-type': 'application/json'})
response = urllib.request.urlopen(http_post)
response_str = response.read().decode('utf8')
# print(response_str)
response_dic = json.loads(response_str)
# print(response_dic)

intent_code = response_dic['intent']['code']
results_text = response_dic['results'][0]['values']['text']
print('Turing的回答：')
print('code：' + str(intent_code))
print('text：' + results_text)
<filename>src/Chatbot/tuliing-html/tuling_test.py
#!/usr/bin/env python
# -*- encoding: utf-8 -*-
#-------------------------------------------------------------------------------
'''
@Author  :   {SEASON}
@License :   (C) Copyright 2013-2022, {OLD_IT_WANG}
@Contact :   {<EMAIL>}
@Software:   PyCharm
@File    :   NLP_DEMO -- tuling_test
@Time    :   2020/6/3 15:18
@Desc    :
api 文档：https://www.kancloud.cn/turing/www-tuling123-com/718227

'''
#-------------------------------------------------------------------------------

import json
import urllib.request

api_url = "http://openapi.tuling123.com/openapi/api/v2"
text_input = input('我：')

req = {
    "perception":
    {
        "inputText":
        {
            "text": text_input
        },
    },

    "userInfo":
    {
        "apiKey": "8a55d83078324f189cfa7a0c6e769b06",
        "userId": "OnlyUseAlphabet"
    }
}
# print(req)
# 将字典格式的req编码为utf8
req = json.dumps(req).encode('utf8')
# print(req)

http_post = urllib.request.Request(api_url, data=req, headers={'content-type': 'application/json'})
response = urllib.request.urlopen(http_post)
response_str = response.read().decode('utf8')
# print(response_str)
response_dic = json.loads(response_str)
# print(response_dic)

intent_code = response_dic['intent']['code']
results_text = response_dic['results'][0]['values']['text']
print('Turing的回答：')
print('code：' + str(intent_code))
print('text：' + results_text)
#!/usr/bin/env python # -*- encoding: utf-8 -*- #------------------------------------------------------------------------------- @Author  :   {SEASON} @License :   (C) Copyright 2013-2022, {OLD_IT_WANG} @Contact :   {<EMAIL>} @Software:   PyCharm @File    :   NLP_DEMO -- tuling_test @Time    :   2020/6/3 15:18 @Desc    : api 文档：https://www.kancloud.cn/turing/www-tuling123-com/718227 #------------------------------------------------------------------------------- # print(req) # 将字典格式的req编码为utf8 # print(req) # print(response_str) # print(response_dic)