快速开始

本文主要介绍如何使用API调用阿里云百炼的流程编排应用,也就是从应用中心中创建的流程编排应用。

快速开始

前提条件

示例代码

以下示例展示了调用流程编排应用来调用自定义插件进行实时天气查询问答。

说明

需要使用您的API-KEY替换示例中的YOUR_API_KEY,并将APP-ID替换示例中的YOUR_APP_ID,代码才能正常运行。

python sdk version: dashscope>=1.10.0

java sdk version: >=2.5.0

设置API-KEY

export DASHSCOPE_API_KEY=YOUR_API_KEY

流程编排应用示例

from http import HTTPStatus
from dashscope import Application


def flow_call():
    response = Application.call(app_id='YOUR_APP_ID',
                                prompt='杭州的天气怎么样',
                                )

    if response.status_code != HTTPStatus.OK:
        print('request_id=%s, code=%s, message=%s\n' % (response.request_id, response.status_code, response.message))
    else:
        print('request_id=%s\n output=%s\n usage=%s\n' % (response.request_id, response.output, response.usage))


if __name__ == '__main__':
    flow_call()
import com.alibaba.dashscope.app.*;
import com.alibaba.dashscope.exception.ApiException;
import com.alibaba.dashscope.exception.InputRequiredException;
import com.alibaba.dashscope.exception.NoApiKeyException;
import java.util.List;


public class Main{
    public static void flowCall()
            throws ApiException, NoApiKeyException, InputRequiredException {
        ApplicationParam param = ApplicationParam.builder()
                .appId("YOUR_APP_ID")
                .prompt("杭州的天气怎么样")
                .build();

        Application application = new Application();
        ApplicationResult result = application.call(param);

        System.out.printf("requestId: %s, text: %s, finishReason: %s\n",
                result.getRequestId(), result.getOutput().getText(), result.getOutput().getFinishReason());
    }

    public static void main(String[] args) {
        try {
            flowCall();
        } catch (ApiException | NoApiKeyException | InputRequiredException e) {
            System.out.printf("Exception: %s", e.getMessage());
        }
        System.exit(0);
    }  
}

流程编排应用示例结果

request_id=0656f381-561f-9c9c-b5f8-549a2e7a18eb
 output={"text": " 杭州的天气为小到中雨,气温在15~27℃之间。", "finish_reason": "stop", "session_id": "3741d1ab9be******720dd172330b", "thoughts": [{"thought": " 首先调用查询天气插件,输入参数为杭州,以获取杭州的天气信息。\n", "action_type": "api", "response": null, "action_name": "查询天气插件", "action": "plg_aa02454d04884113aa0a697d4c4fa813", "action_input_stream": " {\"city\": \"杭州\"}", "action_input": null, "observation": "{\"data\":\"小到中雨,气温15~27℃\",\"errorInfo\":\"\",\"status\":\"success\"}"}, {"thought": " 调用查询天气插件后,根据返回的成功状态和天气数据,直接告知用户杭州的天气情况。\n", "action_type": "response", "response": " 杭州的天气为小到中雨,气温在15~27℃之间。", "action_name": null, "action": null, "action_input_stream": null, "action_input": null, "observation": null}], "doc_references": null}
 usage={"models": [{"model_id": "pre-plugin-888", "input_tokens": 459, "output_tokens": 68}, {"model_id": "pre-plugin-888", "input_tokens": 583, "output_tokens": 51}]}

了解更多

有关流程编排应用API的详细调用文档可前往API详情页面进行了解。