阿里模型调用体验

时间:2024-07-05 07:32:59

引言

随着人工智能技术的飞速发展,大型模型已成为推动技术进步的关键因素之一。阿里大模型作为国内领先的人工智能技术之一,其在多个领域的应用展示了强大的潜力。本文将通过调用案例,简单解析阿里大模型在特定场景中的应用及其效果。

1.导入依赖

      <!-- https://mvnrepository.com/artifact/com.alibaba/dashscope-sdk-java -->
        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>dashscope-sdk-java</artifactId>
            <version>2.15.1</version>
        </dependency>

 2.测试代码

这里要将API-Key 和appId 替换成真实的key和appId

   public static void callAgentApp()
            throws ApiException, NoApiKeyException, InputRequiredException {
        ApplicationParam param = ApplicationParam.builder()
                .apiKey("API-Key")
                .appId("appId")
                .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 {
            callAgentApp();
        } catch (ApiException | NoApiKeyException | InputRequiredException e) {
            System.out.printf("Exception: %s", e.getMessage());
        }
        System.exit(0);
    }

 3.测试