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

springboot3.x对接AI智谱清言

spring引入智谱清言ai包

<!--版本管理--><dependencyManagement><dependencies><dependency><groupId>org.springframework.ai</groupId><artifactId>spring-ai-bom</artifactId><version>1.0.0-SNAPSHOT</version><type>pom</type><scope>import</scope></dependency></dependencies></dependencyManagement>
<!-- Spring AI BOM 声明了特定版本的 Spring AI依赖项的推荐版本   --><repositories><repository><id>spring-snapshots</id><name>Spring Snapshots</name><url>https://repo.spring.io/snapshot</url><releases><enabled>false</enabled></releases></repository></repositories>
<!-- 智谱清言AI --><dependency><groupId>org.springframework.ai</groupId><artifactId>spring-ai-starter-model-zhipuai</artifactId><exclusions><exclusion><groupId>io.swagger.core.v3</groupId><artifactId>swagger-annotations</artifactId></exclusion></exclusions></dependency>

这里如果使用了springdoc/swagger,需要exclude这个包,不然会出现包冲突,导致项目启动失败

spring新增智谱清言ai配置

  ai:zhipuai:api-key: xxxx # 你自己的智谱清言keybase-url: https://open.bigmodel.cn/api/paaschat:options:model: glm-4-flash # 免费模型# model: glm-4-plus #付费模型temperature: 0.5  # 响应随机性

定义智谱清言AI配置类

@Configuration
public class ZhipuAiConfig {@Beanpublic ChatClient chatClient(ChatModel chatModel) {return ChatClient.builder(chatModel).build();}
}

AiService类

@Service
public class AiServiceImpl implements AiService{private final ChatClient chatClient;public AiCheckServiceImpl(ChatClient chatClient) {this.chatClient = chatClient;}@Overridepublic String sendMessage(String message) {return chatClient.prompt().user(message).call().content();}
}

以上就完成了AiService类的编写,controller类可以通过调用sendMessage方法和智谱清言AI接口进行对话。

相关文章:

  • 前端获取接口数据流程
  • 利用coze工作流制作一个自动生成PPT的智能体
  • ORACLE 修改端口号之后无法启动?
  • 安装Openstack
  • pgsql batch insert optimization (reWriteBatchedInserts )
  • 线性规划饮食问题求解:FastAPI作为服务端+libhv作为客户端实现
  • Web应用安全漏洞全解析:从原理到实战防御
  • 词法分析和词性标注 自然语言处理
  • 【OSG学习笔记】Day 16: 骨骼动画与蒙皮(osgAnimation)
  • day27-shell编程(自动化)
  • 食养有方:进行性核上性麻痹患者的健康饮食指南
  • Java线程同步技术深度解析与实践
  • 【2025年6月8日】Claude 4 国内使用全攻略
  • LLMs基础学习(八)强化学习专题(1)
  • android binder(四)binder驱动详解2
  • MyBatis中include标签用法详解
  • ARM SMMUv3 STE表和CD表数据格式分析(三)
  • 利用Pandas AI完成Excel大模型的结合实现自然语言问数
  • AtCoder Beginner Contest 409
  • OD 算法题 B卷【正整数到Excel编号之间的转换】
  • perl网站建设/搜索引擎优化是什么
  • 自建网站免费/怎么自己做一个网址
  • 白领兼职做网站/免费做网站怎么做网站吗
  • 如何设计制作一般企业网站/色盲悖论
  • 免费ppt模板在线下载/seo内容优化方法
  • 做景观设施的网站/快速排名官网