SpringBoot接入千问大模型 流式输出

SpringBoot接入千问大模型 流式输出

环境准备

Spring Boot=2.7.6
maven=3.8.1
  1. 需要搭建好一个最基本的SpringBoot应用,至少包含spring-boot-starter-webspring-boot-starter-webflux依赖。

  2. 注册阿里云账号,开通模型使用权限。

    阿里云控制台:https://www.aliyun.com/product/bailian

    API文档:https://help.aliyun.com/zh/model-studio/developer-reference/use-qwen-by-calling-api

  3. 取得sk-*********样式的apiKey。

  4. 选择DashScope方式接入,导入SDK依赖

    <!-- https://mvnrepository.com/artifact/com.alibaba/dashscope-sdk-java -->
    <dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>dashscope-sdk-java</artifactId>
        <version>2.16.9</version>
    </dependency>
    
  5. 构建一个简单的前端页面,用于发送和接收消息

    <!DOCTYPE html>
    <html lang="zh">
    <head>
        <meta charset="UTF-8">
        <title>AI Chat</title>
        <link rel="stylesheet" href="./css/styles.css">
    </head>
    <body>
    <div class="chat-container">
        <h1>AI Chat</h1>
        <div class="chat-messages" id="messages">
        </div>
        <form class="chat-input" id="chat-form" action="#">
                <input type="text" placeholder="输入消息..." required>
            <button type="submit" class="btn-primary">发送</button>
            <button type="button" class="btn-danger" id="btn-close-chat">停止</button>
        </form>
    </div>
    </body>
    </html>
    
    body {
         
        font-family: Arial, sans-serif;
        background-color: #f4f4f9;
        display: flex;
        justify-content: center;
        align-items: center;
        height: 100vh;
        margin: 0;
    }
    h1 {
         
        text-align: center;
        color: #333;
    }
    
    
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值