通过curl命令使用AI引擎RESTful API示例

Lindorm AI引擎提供了一系列RESTful风格的API,您可以通过curl命令调用这些API进行模型管理和推理等操作。本文提供使用curl命令调用RESTful API接口的示例。

前提条件

  • 已开通AI引擎。具体操作,请参见开通指南

  • 已将客户端的IP地址加入到Lindorm实例的白名单中。具体操作,请参见设置白名单

参数说明

说明

以下参数说明适用于本文所有示例。

参数

说明

url

AI引擎的连接地址。请联系Lindorm技术支持(钉钉号:s0s3eg3)获取。

username

访问AI引擎的用户名和密码。获取方式,请参见访问实例

password

模型管理

创建模型

在AI引擎中创建模型bge_m3_model。

curl -X POST "http://<url>/v1/ai/models/create" \
-H "x-ld-ak: <username>" \
-H "x-ld-sk: <password>" \
-H "Content-Type: application/json" \
-d '{
    "model_name": "bge_m3_model",
    "model_path": "huggingface://BAAI/bge-m3",
    "task": "FEATURE_EXTRACTION",
    "algorithm": "BGE_M3"
}' 

返回结果:

{"code": 0,"msg": "SUCCESS","data": null,"success": true}

查看所有模型信息

curl -X GET "http://<url>/v1/ai/models/list" \
-H "x-ld-ak: <username>" \
-H "x-ld-sk: <password>" 

返回结果:

{
  "code": 0,
  "msg": "SUCCESS",
  "data": {
    "models": [{
      "name": "bge_m3_model",
      "status": "READY",
      "created_time": "...",
      "updated_time": "...",
      ...
    }, {
      "name": "bge_model",
      "status": "READY",
      ...
    }]
  },
  "success": true
  "request_id":"..."
}

查看模型的详细信息

curl -X GET "http://<url>/v1/ai/models/bge_m3_model/status" \
-H "x-ld-ak: <username>" \
-H "x-ld-sk: <password>" 

返回结果:

{
  "code": 0,
  "msg": "SUCCESS",
  "data": {
    "name": "bge_m3_model",
    "status": "READY",
    "task_type":"FEATURE_EXTRACTION",
    "algorithm":"BGE_M3",
    "settings": "...",
    "error":"...",
    "progress": "...",
    ...
  },
  "success": true
}

删除模型

删除模型bge_m3_model。

curl -X POST "http://<url>/v1/ai/models/bge_m3_model/drop" \
-H "x-ld-ak: <username>" \
-H "x-ld-sk: <password>"

返回结果:

{"code": 0,"msg": "SUCCESS","data": null,"success": true}

模型推理

使用已创建的模型推理

curl -X POST "http://<url>/v1/ai/models/bge_m3_model/infer" \
  -H "x-ld-ak: <username>" \
  -H "x-ld-sk: <password>" \
  -H "Content-Type: application/json" \
  -d '{"input":["你好","我们"]}' \

返回推理结果如下:

{
  "code": 0,
  "msg": "SUCCESS",
  "data": [[0.027204733341932297,0.004229982383549213, ...], 
  [-0.05367295444011688,0.022600287571549416, ...]],
  "success": true
}

参数调整

调整已部署模型的参数配置。

curl -X POST "http://<url>/v1/ai/models/bge_m3_model/update_config" \
  -H "x-ld-ak: <username>" \
  -H "x-ld-sk: <password>" \
  -H "Content-Type: application/json" \
  -d '{"instance_count": "2"}' \

调整成功将返回如下结果:

{"code": 0,"msg": "SUCCESS","data": null,"success": true}