当前位置: 首页 > article >正文

Springboot引入通义千文大模型API

1、首先需要注册阿里云的账号(这里就不说了,很简单)
2、获得APIKEY 找到阿里云的这个网站
https://bailian.console.aliyun.com/#/app-center
或者直接在阿里云搜索阿里云百练
右上角用户的头像那里有个API-KEY,申请一个即可。
3、引入依赖

    <!--阿里巴巴大模型-->
            <!-- 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、编写代码

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

完事!!!


http://www.kler.cn/news/303140.html

相关文章:

  • 前端代码规范- Commit 提交规范
  • linux-L10.查看你硬盘容量
  • OpenAI「草莓」两周内发布?网传不是多模态,反应慢了10多秒
  • docker 多服务只暴露一个客户端
  • 003InputSystem新输入系统学习工作笔记
  • R和Python数据格式的通用性
  • Mysql | 知识 | 事务隔离级别
  • netty之NioEventLoop和NioEventLoopGroup
  • 统计信息的导出导入
  • 顶点照明渲染路径
  • Java异常处理机制详解
  • 如何把我另一个分支上的commit拿过来
  • C语言整型数据在内存中的存储(22)
  • python如何将DICOM图片转为JPG?
  • Docker torchserve 部署模型流程
  • MATLAB | R2024b更新了哪些好玩的东西?
  • 在Excel中通过Python运行公式和函数实现数据计算
  • 计算机网络27、28——Linux命令1、2
  • 这款神器,运维绝杀 !!! 【送源码】
  • 内部flash模拟成EepRom-重新梳理
  • codeup:将已有文件夹推送到已有仓库
  • 计算机毕业设计 | SpringBoot+vue 游戏商城 steam网站管理系统(附源码)
  • 【运维监控】Prometheus+grafana+kafka_exporter监控kafka运行情况
  • Leetcode 3282. Reach End of Array With Max Score
  • 波场TRON领航者孙宇晨:区块链行业的青年先锋与标杆
  • 代理导致的git错误
  • Grafana面板-linux主机详情(使用标签过滤主机监控)
  • 如何使用ssm实现基于VUE3+SSM框架的在线宠物商城+vue
  • 【Java】StringUtils 工具类常用的方法
  • 【JavaSE】--方法的使用