Springboot引入通义千文大模型API

1、首先需要注册阿里云的账号(这里就不说了,很简单)

2、获得APIKEY 找到阿里云的这个网站

https://bailian.console.aliyun.com/#/app-center

或者直接在阿里云搜索阿里云百练

右上角用户的头像那里有个API-KEY,申请一个即可。

3、引入依赖

bash 复制代码
    <!--阿里巴巴大模型-->
            <!-- https://mvnrepository.com/artifact/com.alibaba/dashscope-sdk-java -->
            <dependency>
                <groupId>com.alibaba</groupId>
                <artifactId>dashscope-sdk-java</artifactId>
                <exclusions>
                    <exclusion>
                        <groupId>org.slf4j</groupId>
                        <artifactId>slf4j-simple</artifactId>
                    </exclusion>
                </exclusions>
                <version>2.8.3</version>
            </dependency>
            <dependency>
                <groupId>org.apache.commons</groupId>
                <artifactId>commons-pool2</artifactId>
                <version>2.11.1</version>
            </dependency>

4、编写代码

java 复制代码
 public static GenerationResult callWithMessage() throws NoApiKeyException, ApiException, InputRequiredException {
        Constants.apiKey = "你的API-KEY";
        Generation gen = new Generation();
        MessageManager msgManager = new MessageManager(10);
        Message systemMsg =
                Message.builder().role(Role.SYSTEM.getValue()).content("You are a helpful assistant.").build();
        Message userMsg = Message.builder().role(Role.USER.getValue()).content("请问杭州阿里巴巴工作环境咋样?").build();
        msgManager.add(systemMsg);
        msgManager.add(userMsg);
        QwenParam param =
                QwenParam.builder().model(Generation.Models.QWEN_TURBO).messages(msgManager.get())
                        .resultFormat(QwenParam.ResultFormat.MESSAGE)
                        .topP(0.8)
                        .enableSearch(true)
                        .build();
        GenerationResult result = gen.call(param);
        log.info("千问api回答的话语为:{}", result);
        System.out.println(result);
        return result;
    }

完事!!!

相关推荐
m0_74823364几秒前
RabbitMQ 进阶
android·前端·后端
羱滒2 分钟前
sql调优之数据库开发规范
java·数据库·数据库开发
m0_7482386310 分钟前
Spring Boot项目接收前端参数的11种方式
前端·spring boot·后端
Forget the Dream31 分钟前
设计模式之责任链模式
java·c++·设计模式·责任链模式
jonyleek34 分钟前
「JVS更新日志」低代码、企业会议、智能BI、智能排产2.26更新说明
java·大数据·低代码·数据分析·软件需求
计算机小白一个1 小时前
蓝桥杯 Java B 组之最短路径算法(Dijkstra、Floyd-Warshall)
java·数据结构·算法·蓝桥杯
曼岛_1 小时前
[密码学实战]Java实现SM4加解密(ecb,cbc)及工具验证
java·密码学
菜鸟阿达1 小时前
spring boot 2.7 + seata +微服务 降级失败问题修复
spring boot·后端·微服务
清河__1 小时前
【Go】十七、grpc 服务的具体功能编写
开发语言·后端·golang
Forget the Dream1 小时前
设计模式之代理模式
java·c++·设计模式·代理模式