一、SpringAI 接入 DeepSeek 所需环境
- JDK17+(JDK8 无法支持)
- SpringBoot 3.x
- Maven 3.6+
官方文档
SpringAI 接入 DeepSeek 方式有多种,下面演示原生方式接入。
二、Maven 依赖
- SpringBoot 版本修改
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.4.5</version>
<relativePath/>
</parent>
- SpringAI OpenAI Starter 依赖
<dependency>
<groupId>org.springframework.ai</groupId>
<artifactId>spring-ai-openai-spring-boot-starter</artifactId>
<version>1.0.0-M6</version>
</dependency>
三、配置文件
spring.ai.openai.api-key=xxx(修改成自己的密钥)
spring.ai.openai.base-url=https://api.deepseek.com
spring.ai.openai.chat.options.model=deepseek-chat
四、代码实现
配置类
org.springframework.ai.chat.client.ChatClient;
org.springframework.context.annotation.Bean;
org.springframework.context.annotation.Configuration;
{
ChatClient {
builder.defaultSystem().build();
}
}

