Spring AI快速入门

一、引入依赖

复制代码
<dependency>
	<groupId>org.springframework.ai</groupId>
	<artifactId>spring-ai-starter-model-openai</artifactId>
</dependency>

<dependencyManagement>
		<dependencies>
			<dependency>
				<groupId>org.springframework.ai</groupId>
				<artifactId>spring-ai-bom</artifactId>
				<version>${spring-ai.version}</version>
				<type>pom</type>
				<scope>import</scope>
			</dependency>
		</dependencies>
	</dependencyManagement>

二、配置模型

复制代码
spring:
  ai:
    openai:
      base-url: https://dashscope.aliyuncs.com/compatible-mode/
      api-key: 【换成自己的秘钥】
      chat:
        options:
          model: deepseek-r1
          temperature: 0.7
logging:
    level:
        com.itheima.ai: debug

三、配置客户端

复制代码
@Bean 
public ChatClient chatClient(OllamaChatModel model){
    return ChatClient.builder(model) //创建ChatClient工厂实例化
                    .defaultSystem("你是可爱的助手,名字叫小团团")
                    .defaultAdvisors(new SimpleLoggerAdvisor()) //配置日志Advisor
                    .build;
}

生成提示词:

java 复制代码
String content = chatClient.prompt()
        .user("你是谁?")
        .call()
        .content();

或者

java 复制代码
Flux<String> content = chatClient.prompt()
        .user("你是谁?")
        .stream()
        .content();
相关推荐
阿里云大数据AI技术5 小时前
StarRocks x Fluss x Paimon湖流一体方案:构建秒级响应、湖流一体的实时数据引擎
大数据·人工智能
Databend6 小时前
Agent 轨迹分析与归因的数据工程实践
大数据·数据库·agent
喵个咪7 小时前
Go Wind UBA 拆解系列 - 架构总览:三服务、数据流与契约优先
大数据·后端·go
喵个咪7 小时前
Go Wind UBA 拆解系列 - 多租户与安全:两套隔离机制的边界
大数据·后端·go
喵个咪7 小时前
Go Wind UBA 拆解系列 - OLAP 与 SQL 硬核:25 个分析模型怎么落地
大数据·后端·go
喵个咪7 小时前
Go Wind UBA 拆解系列 - SDK 与采集层:从浏览器到 Kafka
大数据·后端·go
SamDeepThinking10 小时前
裁掉那个差程序员后,给你看团队里高手的代码:这个习惯,希望你有
java·后端·程序员
朕瞧着你甚好11 小时前
技术雷达 & Java 集成评估报告 — Apache Tika 3.3.1
java·ai编程
QCC产品中心11 小时前
MiniMax Agent 接入实测:企业查询、股权穿透与 UBO 识别(附 Prompt 模板)
大数据·mcp·金融/非金融
MacroZheng12 小时前
短短几天,暴涨2.8万Star!又一款编程神器开源!
java·人工智能·后端