获取服务列表
更新时间:2024-12-26
注意:
- 为提升开发者使用体验,推荐使用模型服务V2版本接口,功能更全面、且接口更规范,详见模型服务API列表。
- 模型服务V1版本接口功能不再升级,本文档于2024年8月5日下线;由于V1版本接口后续可能下线停止服务,为避免影响使用,建议接入模型服务V2版本接口。
功能介绍
本接口用于根据服务类型获取服务列表,如服务类型为chat类型,可以获取所有chat类型的服务列表。
SDK调用
用于根据服务类型获取服务列表,例如服务类型为chat类型,可以获取所有chat类型的服务列表。
使用说明
调用本文API,需使用安全认证AK/SK鉴权,调用流程及鉴权介绍详见SDK安装及使用流程。
调用示例
import os
from qianfan import resources
# 使用安全认证AK/SK鉴权,通过环境变量方式初始化;替换下列示例中参数,安全认证Access Key替换your_iam_ak,Secret Key替换your_iam_sk
os.environ["QIANFAN_ACCESS_KEY"] = "your_iam_ak"
os.environ["QIANFAN_SECRET_KEY"] = "your_iam_sk"
from qianfan.resources.console.service import Service
resp = Service.list(["embeddings"])
print(resp)
返回示例
QfResponse(code=200,
headers={...},
body={'log_id': '3014762423',
'result': {'common': [{'apiType': 'embeddings',
'chargeStatus': 'OPENED',
'name': 'Embedding-V1',
'url': 'https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/embeddings/embedding-v1',
'versionList': [{'serviceStatus': 'Done',
'trainType': 'embedding'}]},
{'apiType': 'embeddings',
'chargeStatus': 'OPENED',
'name': 'bge-large-zh',
'url': 'https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/embeddings/bge_large_zh',
'versionList': [{'serviceStatus': 'Done',
'trainType': 'embedding'}]},
{'apiType': 'embeddings',
'chargeStatus': 'OPENED',
'name': 'bge-large-en',
'url': 'https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/embeddings/bge_large_en',
'versionList': [{'serviceStatus': 'Done',
'trainType': 'embedding'}]},
{'apiType': 'embeddings',
'chargeStatus': 'OPENED',
'name': 'tao-8k',
'url': 'https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/embeddings/tao_8k',
'versionList': [{'serviceStatus': 'Done',
'trainType': 'embedding'}]}],
'custom': []}},
statistic={'request_latency': 0.526946,
'total_latency': 0.5281059946864843})
请求参数
名称 | 类型 | 必填 | 描述 |
---|---|---|---|
api_type_filter | List[str] | 否 | 根据服务类型apiType筛选,可选值如下: · chat · completions · embeddings · text2image · image2text |
返回参数
名称 | 类型 | 描述 |
---|---|---|
log_id | string | 请求ID |
result | dict | 请求结果 |
result说明
名称 | 类型 | 描述 |
---|---|---|
common | array(serviceItem) | 预置服务 |
custom | array(serviceItem) | 自定义服务 |
serviceItem说明
名称 | 类型 | 描述 |
---|---|---|
serviceId | int | 服务id |
serviceUuid | string | 服务uuid |
name | string | 服务名称 |
url | string | 服务endpoint |
apiType | string | 服务类型,说明: · chat · completions · embeddings · text2image · image2text |
chargeStatus | string | 付费状态,说明: · OPENING · OPENED · STOP · FREE |
versionList | array(version) | 服务版本列表 |
version说明
名称 | 类型 | 描述 |
---|---|---|
aiModelId | string | 发布该服务版本的模型id,只有自定义服务会返回该字段 |
aiModelVersionId | string | 发布该服务版本的模型版本id,只有自定义服务会返回该字段 |
trainType | string | 服务基础模型类型 |
serviceStatus | string | 服务状态,说明 (1)该字段值对应状态说明: · Done:已发布 · New:待发布 · Deploying:发布中 · Failed:发布失败 · Stopped:暂停服务 (2)如果是预置服务,该字段为固定值Done |
HTTP调用
鉴权说明
调用本文API,使用“基于安全认证AK/SK”进行签名计算鉴权,即使用安全认证中的Access Key ID 和 Secret Access Key进行鉴权,具体鉴权认证机制参考HTTP调用鉴权说明。
请求说明
- 基本信息
请求地址: https://qianfan.baidubce.com/wenxinworkshop/service/list
请求方式: POST
- Header参数
名称 | 类型 | 必填 | 描述 |
---|---|---|---|
Content-Type | string | 是 | 固定值:application/json |
x-bce-date | string | 否 | 当前时间,遵循ISO8601规范,格式如2016-04-06T08:23:49Z |
Authorization | string | 是 | 用于验证请求合法性的认证信息,更多内容请参考鉴权认证机制,签名工具可参考IAM签名工具 |
- Body参数
名称 | 类型 | 必填 | 描述 |
---|---|---|---|
apiTypefilter | array | 否 | 根据服务类型apiType筛选,可选值如下: · chat · completions · embeddings · text2image · image2text |
响应说明
名称 | 类型 | 描述 |
---|---|---|
log_id | string | 请求ID |
result | object | 请求结果 |
result说明
名称 | 类型 | 描述 |
---|---|---|
common | array(serviceItem) | 预置服务 |
custom | array(serviceItem) | 自定义服务 |
serviceItem说明
名称 | 类型 | 描述 |
---|---|---|
serviceId | int | 服务id |
serviceUuid | string | 服务uuid |
name | string | 服务名称 |
url | string | 服务endpoint |
apiType | string | 服务类型,说明: · chat · completions · embeddings · text2image · image2text |
chargeStatus | string | 付费状态,说明: · NOTOPEN · OPENED · STOP · FREE |
versionList | array(version) | 服务版本列表 |
version说明
名称 | 类型 | 描述 |
---|---|---|
aiModelId | string | 发布该服务版本的模型id,只有自定义服务会返回该字段 |
aiModelVersionId | string | 发布该服务版本的模型版本id,只有自定义服务会返回该字段 |
trainType | string | 服务基础模型类型 |
serviceStatus | string | 服务状态,说明 (1)该字段值对应状态说明: · Done:已发布 · New:待发布 · Deploying:发布中 · Failed:发布失败 · Stopped:暂停服务 (2)如果是预置服务,该字段为固定值Done |
请求示例
curl --location 'https://qianfan.baidubce.com/wenxinworkshop/service/list' \
--header 'Authorization: bce-auth-v1/047ab241bad24166b42a4d2e3e28b1ac/2023-10-10T07:48:39Z/1800/host;x-bce-date/c26e0a21944cc53773f3e7ec48affb9d7b9565ce6d627e77329ee2f2d10cb53f' \
--header 'x-bce-date: 2023-10-10T07:48:17Z' \
--header 'Content-Type: application/json' \
--data '{"apiTypefilter":["chat", "completions", "embeddings", "text2image"]}'
响应示例
{
"log_id": "4102908182"
"success": true,
"result": {
// 预置服务
"common": [{
"name": "ERNIE-Bot 4.0",
"url": "https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/completions_pro",
"apiType": "chat",
"chargeStatus": "OPENED",
"versionList": [{
"trainType": "ernieBot_4",
"serviceStatus": "Done" // 服务状态,已发布
}]
}],
// 自定义服务
"custom": [{
"serviceId":"123", // 服务id
"serviceUuid":"svco-xxxxaaa", // 服务id
"name": "conductor_liana2",
"url": "https://aip.baidubce.com/rpc/2.0/ai_custom/v1/wenxinworkshop/chat/ca6zisxxxx",
"apiType": "chat",
"chargeStatus": "NOTOPEN",
"versionList": [{
"aiModelId":"xxx-123", // 发布该服务的模型id
"aiModelVersionId":"xxx-456", // 发布该服务的模型版本id
"trainType": "llama2-7b",
"serviceStatus": "Done" // 服务状态,已发布
}]
}]
}
}
错误码
若请求错误,服务器将返回的JSON文本包含以下参数:
名称 | 描述 |
---|---|
error_code | 错误码 |
error_msg | 错误描述信息,帮助理解和解决发生的错误 |
例如参数错误返回:
{
"error_code": 500001,
"error_msg": "param invalid"
}
更多错误码,请查看错误码说明。