全部产品

Python SDK

Python SDK

AliNLP2.0 SDK访问

pip install aliyun-python-sdk-alinlp==1.0.16

  1. import json
  2. # 这里以分词为例,其它算法的API名称和参数请参考文档
  3. from aliyunsdkalinlp.request.v20200629 import GetWsCustomizedChGeneralRequest
  4. from aliyunsdkcore.client import AcsClient
  5. from aliyunsdkcore.acs_exception.exceptions import ClientException
  6. from aliyunsdkcore.acs_exception.exceptions import ServerException
  7. # 创建AcsClient实例
  8. client = AcsClient(
  9. "<your-access-id-key>",
  10. "<your-access-id-secret>",
  11. "cn-hangzhou"
  12. )
  13. request = GetWsCustomizedChGeneralRequest.GetWsCustomizedChGeneralRequest()
  14. request.set_Text("云麦好轻智能体脂秤精准蓝牙秤体重测人体脂肪秤家用称健康电子秤")
  15. request.set_OutType("1")
  16. request.set_ServiceCode("alinlp")
  17. request.set_TokenizerId("GENERAL_CHN")
  18. response = client.do_action_with_exception(request)
  19. resp_obj = json.loads(response)
  20. print(resp_obj)

Common Request方式访问

common request文档

  1. import json
  2. from aliyunsdkcore.client import AcsClient
  3. from aliyunsdkcore.request import CommonRequest
  4. # 创建AcsClient实例
  5. client = AcsClient(
  6. "<your-access-id-key>",
  7. "<your-access-id-secret>",
  8. "cn-hangzhou"
  9. )
  10. request = CommonRequest()
  11. # domain和version是固定值
  12. request.set_domain('alinlp.cn-hangzhou.aliyuncs.com')
  13. request.set_version('2020-06-29')
  14. # action name可以在API文档里查到
  15. request.set_action_name('GetWsCustomizedChGeneral')
  16. # 需要add哪些param可以在API文档里查到
  17. request.add_query_param('ServiceCode', 'alinlp')
  18. request.add_query_param('Text', '云麦好轻智能体脂秤精准蓝牙秤体重测人体脂肪秤家用称健康电子秤')
  19. request.add_query_param('TokenizerId', 'GENERAL_CHN')
  20. response = client.do_action_with_exception(request)
  21. resp_obj = json.loads(response)
  22. print(resp_obj)