文档

快速开始

更新时间:
一键部署

前提条件

1. 创建专属服务

下面的命令使用模型qwen-turbo,创建一个专属服务qwen-turbo-5790cf81,使用2个算力单元:

curl 'https://dashscope.aliyuncs.com/api/v1/deployments' \
    --header 'Authorization: bearer <your-dashscope-api-key>' \
    --header 'Content-Type: application/json' \
    --data '{        
                "model_name": "qwen-turbo",
                "capacity": 2
            }'
说明

执行命令前,需要使用您的API-KEY替换示例中的<your-dashscope-api-key>。

命令执行成功后,返回如下结果:

{
    "request_id":"12869b6a-4785-9d65-91c1-0a1c102aadd4",
    "output":{
        "deployed_model":"qwen-turbo-5790cf81",
        "status":"PENDING",
        "model_name":"qwen-turbo"
    }
}

其中deployed_model为专属服务的唯一ID。

2. 查询服务状态

通过以下命令查询指定专属服务的详细信息:

curl 'https://dashscope.aliyuncs.com/api/v1/deployments/qwen-turbo-5790cf81' \
    --header 'Authorization: bearer <your-dashscope-api-key>' \
    --header 'Content-Type: application/json' 

命令执行成功后,返回如下结果:

{
    "request_id":"b34157d6-8c85-9dc8-a086-c619e8ade696",
    "output":{
        "deployed_model":"qwen-turbo-5790cf81",
        "status":"PENDING",
        "model_name":"qwen-turbo"
        "capacity":2
    }
}

当服务状态为RUNNING时,服务部署完成。

3. 执行推理请求

通过SDK对专属服务发起请求:

from dashscope import Generation
from http import HTTPStatus

response = Generation.call(
    model='qwen-turbo-5790cf81',
    prompt='万有引力是谁发现的?'
)

if response.status_code == HTTPStatus.OK:
    print(response.output)
    print(response.usage)
else:
    print(response.code)
    print(response.message)
说明

执行推理请求使用的API-KEY需要与创建服务使用的API-KEY相同,或归属于相同的阿里云账号。若首次使用DashScope SDK,请参考安装百炼SDK获取API-KEY

代码执行成功后,返回如下结果:

{"text": "万有引力是爱因斯坦发现的。"}
{"input_tokens": 29, "output_tokens": 13}

4. 删除专属服务

不再使用的专属服务,可以通过下面的命令删除:

curl --request DELETE 'https://dashscope.aliyuncs.com/api/v1/deployments/qwen-turbo-5790cf81' \
    --header 'Authorization: bearer <your-dashscope-api-key>' \
    --header 'Content-Type: application/json' 

命令执行成功后,返回以下结果:

{
    "request_id":"4bb4d869-bb24-9439-8fb2-e67231228144",
    "output":{
        "deployed_model":"qwen-turbo-5790cf81",
        "status":"DELETING",
        "model_name":"qwen-turbo",
        "capacity":2
    }
}

  • 本页导读 (1)
文档反馈