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

常州工厂网站建设鸣蝉智能建站

常州工厂网站建设,鸣蝉智能建站,网络推广的目标,各种网站末班目录 一、创建好Springboot项目 (一)、创建简单的springboot项目 (二)创建一个简单的接口 (三)使用postman调用该接口进行测试 二、注册“阿里云百炼”平台 (一)没有账户的先在…

目录

一、创建好Springboot项目

(一)、创建简单的springboot项目

(二)创建一个简单的接口

(三)使用postman调用该接口进行测试

二、注册“阿里云百炼”平台

(一)没有账户的先在阿里云百炼注册

(二)创建api-key

(三)获取api-key

(四)获取模型名称

(三)项目集成Ai模型

(一)pom文件加入依赖

(二)controller代码更改

(三)启动类加入ChatMemory   Bean

(四)yml添加配置apiKey和模型名称


一、创建好Springboot项目

(一)、创建简单的springboot项目

要使用springboot的3.4.2版本,jdk使用17

我的项目名为testAi

pom文件内容如下

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>org.example</groupId><artifactId>testAi</artifactId><version>1.0-SNAPSHOT</version><parent><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-parent</artifactId><version>3.4.2</version><relativePath/></parent><properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding><jdk>17</jdk></properties><dependencies><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-test</artifactId></dependency><dependency><groupId>org.springframework.boot</groupId><artifactId>spring-boot-starter-web</artifactId></dependency><dependency><groupId>org.projectlombok</groupId><artifactId>lombok</artifactId><optional>true</optional><version>1.18.20</version></dependency></dependencies><build><plugins><plugin><groupId>org.springframework.boot</groupId><artifactId>spring-boot-maven-plugin</artifactId></plugin><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-jar-plugin</artifactId><version>2.4</version><configuration><excludes><exclude>*</exclude></excludes></configuration></plugin></plugins><resources><resource><directory>src/main/resources</directory></resource></resources></build>
</project>

(二)创建一个简单的接口

(三)使用postman调用该接口进行测试

二、注册“阿里云百炼”平台

(一)没有账户的先在阿里云百炼注册

地址:百炼控制台

(二)创建api-key

按下列四步创建出一个api-key

(三)获取api-key

点击查看,然后可获取apiKey

(四)获取模型名称

点击模型广场,然后选择DeepSeek,最后在筛选结果点击“查看详情”

然后选择“deepseek-r1”

(三)项目集成Ai模型

(一)pom文件加入依赖

        <dependency><groupId>com.alibaba.cloud.ai</groupId><artifactId>spring-ai-alibaba-starter</artifactId><version>1.0.0-M3.3</version></dependency>------------------------------------------------------<dependencyManagement><dependencies><dependency><groupId>org.springframework.ai</groupId><artifactId>spring-ai-bom</artifactId><version>1.0.0-M3</version><type>pom</type><scope>import</scope></dependency></dependencies></dependencyManagement><repositories><repository><id>spring-milestone-repo</id><url>https://repo.spring.io/milestone</url></repository></repositories>

(二)controller代码更改

package org.example.controller;import org.example.api.req.CallAiReq;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.AbstractChatMemoryAdvisor;
import org.springframework.ai.chat.client.advisor.PromptChatMemoryAdvisor;
import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;@RestController
public class CallAiController {ChatClient chatClient;public CallAiController(ChatClient.Builder chatClientBuilder, ChatMemory chatMemory){this.chatClient = chatClientBuilder.defaultAdvisors(new PromptChatMemoryAdvisor(chatMemory)).build();}@RequestMapping("/callAi")public Flux<String> callAi(@RequestBody CallAiReq req){System.out.println("入参=" + req.getMessage());Flux<String> content = chatClient.prompt().user(req.getMessage()).advisors(a -> a.param(AbstractChatMemoryAdvisor.CHAT_MEMORY_RETRIEVE_SIZE_KEY, 100)).stream().content();return content;}}

(三)启动类加入ChatMemory   Bean

package org.example;import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.ai.chat.memory.InMemoryChatMemory;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;@SpringBootApplication
public class TestAiApplication {public static void main(String[] args) {SpringApplication.run(TestAiApplication.class, args);}@Beanpublic ChatMemory chatMemory(){return new InMemoryChatMemory();}
}

(四)yml添加配置apiKey和模型名称

根据第二步中的(三)和(四)获取的apiKey和模型名称加入配置文件中

server:port: 8100spring:ai:dashscope:api-key: sk-**************************38(替换自己的)chat:options:model: deepseek-r1

这块代码是有前面对话的记忆

结束!

http://www.dtcms.com/wzjs/301665.html

相关文章:

  • 制作网站的最新软件是什么seo优化关键词放多少合适
  • 做企业形象网站今日十大热点新闻
  • WORDPRESS导航条固定seo快速提升排名
  • 九九建筑网网站性能优化
  • 西安做营销型网站建设百度搜索推广的五大优势
  • 烟台网站建设九七搜索引擎广告形式有
  • 互联网网站制作公司临沂seo建站
  • 泰安网站推广 泰安网站建设东莞网站制作十年乐云seo
  • 网站开发 .net站长工具查询域名
  • 网站搜索结果页面怎么做seo网站内容优化
  • 合肥网站制作价格超级seo外链工具
  • 济南网站开发建设拉新推广怎么找渠道
  • 织梦手机网站制作石家庄网站建设seo
  • 郑州的网站建设公司有哪些中国进入一级战备状态了吗
  • 中国建设银行官网站电脑版谷歌浏览器 安卓下载2023版
  • 怎么免费网做百度收录的网站吗永久免费的培训学校管理软件
  • 东莞长安网站建设关键词提取工具app
  • 企业做网站应注意什么下载app到手机上并安装
  • 如何不要钱做网站公司怎么推广网络营销
  • 网站装修的代码怎么做的优化网站关键词的技巧
  • 服务好的企业做网站成都seo培
  • 工程公司是做什么的福州seo建站
  • 如果我的网站被百度收录了_以后如何做更新争取更多收录郴州seo
  • 苏州党员两学一做网站东莞seo网络营销
  • 企业做网站哪家好seo交流论坛
  • 鄂州做网站公司做引流的公司是正规的吗
  • 24小时看b站直播的软件东莞发布最新通告
  • 自己做的网站怎么接入数据库百度关键词seo
  • 无锡新区网站制作网站流量查询网站统计查询
  • 嘉兴做毛织的有哪些网站app推广赚钱平台