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;
    }

完事!!!

相关推荐
京东云开发者2 分钟前
库存平台稳定性建设实践
后端
wenb1n2 分钟前
SmartDB:AI与数据库的“翻译官”,开启无缝交互新时代!
后端
Warren985 分钟前
软件测试-Selenium学习笔记
java·javascript·笔记·学习·selenium·测试工具·安全
bobz96515 分钟前
Supervisord 自动重启子进程
后端
ezl1fe19 分钟前
RAG 每日一技(十八):手写SQL-RAG太累?LangChain的SQL智能体(Agent)前来救驾!
数据库·人工智能·后端
费益洲30 分钟前
Docker 核心技术:Linux Cgroups
后端
没有bug.的程序员31 分钟前
JVM 运行时数据区详解:内存模型与对象生命周期全景解析
java·jvm·运行时数据区·内存模型·对象生命周期
杨DaB32 分钟前
【SpringBoot】Dubbo、Zookeeper
spring boot·后端·zookeeper·dubbo·java-zookeeper
一语长情1 小时前
Netty流量整形:保障微服务通信稳定性的关键策略
java·后端·架构
冲鸭ONE1 小时前
java数据类型与语句结构
后端