Productai

使用API进行开发

目前ProductAI支持4种语言SDK。对于使用其他语言开发客户端的客户需要调用API的方式来使用ProductAI平台的服务。每一个帐号都会被分配一个唯一的access_key_id。请登录控制台获取你的access_key_id(查看方法参考这里)。调用ProductAI服务时,需要把该值放入HTTPS请求的Header中,用于服务端识别不同的客户。一个完整的API请求中,Header至少要包含如下字段:

名称类型必需说明
x-ca-version字符串API版本,当前请填写’1’
x-ca-accesskeyid字符串分配给用户调用API的id。请在对应服务的“测试服务”功能界面或前往“账户设置”获取

创建第一个搜索服务

创建一个数据集。https://api.productai.cn/image_sets/_0000014是操作数据集的API地址。

cURL

curl -X POST \
-H 'x-ca-version: 1.0' \
-H 'x-ca-accesskeyid: ACCESS_KEY_ID' \
-H 'Content-Type: application/json' \
-d '{"name": "1426", "description": "test"}' \
https://api.productai.cn/image_sets/_0000014

返回结果为一段json如下。其中id是新创建的数据集唯一ID

{
"created_at": "2017-12-13T08:40:51Z",
"creator_id": ...,
"description": "yyy",
"id": "l5qwws5f",
"modified_at": "2017-12-13T08:40:51Z",
"n_downloaded": 0,
"n_failed": 0,
"n_items": 0,
"name": "xxx",
"request_id": "53361e08-dfe1-11e7-a97c-664c03c7cfbb",
"status": "not-downloaded"
}

向数据集中添加图片数据

cURL

curl -X POST \
-H 'x-ca-version: 1.0' \
-H 'x-ca-accesskeyid: ACCESS_KEY_ID' \
-d 'image_url=http://yyyy' \
https://api.productai.cn/image_sets/_0000014/l5qwws5f

在数据集上启动一个搜索服务

cURL

curl -X POST \
-H 'x-ca-version: 1.0' \
-H 'x-ca-accesskeyid: ACCESS_KEY_ID' \
-H 'Content-Type: application/json' \
-d '{"name": "1426", "scenario": "fashion_5_7"}' \
https://api.productai.cn/image_sets/_0000014/l5qwws5f/services

返回结果为一段json如下。其中id是新创建的服务唯一ID

{
"created_at": "2017-12-17T13:49:56Z",
"creator_id": ...,
"id": "790jvquc",
"image_set_id": "0mspcj1m",
"indexed_ratio": 0,
"last_indexed_time": null,
"last_updated_at": null,
"n_indexed": 0,
"name": "xxx",
"request_id": "298f4aea-e331-11e7-a97c-664c03c7cfbb",
"scenario": "fashion",
"status": "running",
"status_duration": 0
}

针对搜索服务,使用URL进行搜索

cURL

curl -X POST \
-H 'x-ca-version: 1.0' \
-H 'x-ca-accesskeyid: ACCESS_KEY_ID' \
-d 'url=https://yyyy' \
https://api.productai.cn/search/SERVICE_ID

返回结果为一段json如下:

{
"detect_time": "0.000",
"detection_score": null,
"download_time": "0.004",
"ds": "70awubt0",
"is_err": 0,
"loc": [
0,
0,
1080,
1920
],
"preprocess_time": "0.005",
"request_id": "d2605570-e33a-11e7-9a73-92019f9dce87",
"results": [
{
"metadata": "10544127897",
"score": 0.6035475711762495,
"url": "http://k1"
},
{
"metadata": "10544127898",
"score": 0.5894687892431159,
"url": "http://k2"
},
...
],
"searchtime": "0.307",
"time": "0.324",
"ver": "20171113-135702"
}