如今,越来越多的软件公司正致力于将大模型技术融入企业的业务、流程与数据之中,开发出各类应用,例如知识库系统、流程编排工具以及ChatBI等。今天,我们就基于 Spring AI 的相关内容,简要梳理一下开发这类应用所需关注的技术要点。大家也可以直接参考官方文档进行深入了解:

浏览了 Spring AI 所提供的工具库之后,我发现它已经非常强大,接下来我准备集中时间尽快上手掌握。最近,有同事向我展示了他基于 KIMI 的 OK Computer 开发的应用,效果相当惊艳。

对于未来大模型在企业中的应用趋势,我认为目前模型的训练难度和成本,还难以支撑这一方向全面铺开。相比之下,基于 MCP(Model Context Protocol)或 Function Call 的智能体应用,更有可能成为接下来百花齐放的领域。当前,那些数字化基础扎实、能够将更多工作封装为智能体并接入大模型的企业,将在未来几年中更好地利用大模型能力,逐步从数字化迈向智能化。

  1. . Maven添加Spring AI的相关依赖        
    <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>
    <dependencies>
        <!--deepseek-->
        <dependency>
            <groupId>org.springframework.ai</groupId>
            <artifactId>spring-ai-starter-model-deepseek</artifactId>
        </dependency>
    </dependencies>

2. 配置调用的大语言模型,以DeepSeek为例,自己配置好api key即可

spring:
  application:
    name: quick-start
  ai:
    deepseek:
      api-key: sk-XXXXXXXXXXXXXXXXXXXXXXX
      base-url: https://api.deepseek.com
      chat:
        options:
          model: deepseek-reasoner

3. 编写测试类

import org.junit.jupiter.api.Test;
import org.springframework.ai.deepseek.DeepSeekChatModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import reactor.core.publisher.Flux;

@SpringBootTest
public class TestDeepseek {
    @Test
    public void testDeepseek(@Autowired DeepSeekChatModel deepSeekChatModel) {
        //直接调用
        String content = deepSeekChatModel.call("who are you");
        System.out.println(content);
        //流式响应
        Flux<String> stream = deepSeekChatModel.stream("who are you");
        stream.toIterable().forEach(System.out::println);
    }

}

4、就是这么简单,我们就可以通过Spring AI提供的库与大模型进行交互了

2025-11-08T21:19:52.385+08:00  INFO 162984 --- [quick-start] [           main] org.ly.TestDeepseek                      : Starting TestDeepseek using Java 17.0.13 with PID 162984 (started by A in E:\Git\AILean\spring-ai-parent\quick-start)
2025-11-08T21:19:52.386+08:00  INFO 162984 --- [quick-start] [           main] org.ly.TestDeepseek                      : No active profile set, falling back to 1 default profile: "default"
2025-11-08T21:19:53.949+08:00  INFO 162984 --- [quick-start] [           main] org.ly.TestDeepseek                      : Started TestDeepseek in 1.784 seconds (process running for 2.467)
Java HotSpot(TM) 64-Bit Server VM warning: Sharing is only supported for boot loader classes because bootstrap classpath has been appended
Hello! I'm DeepSeek, an AI assistant created by DeepSeek Company. I'm here to help you with a wide variety of tasks - whether you need assistance with questions, analysis, writing, problem-solving, or just want to have a conversation!

I'm a text-based AI model with some great features:
- I can process uploaded files (images, PDFs, Word docs, Excel sheets, PowerPoint presentations, and text files)
- I have a 128K context window for handling long conversations
- I support web search functionality (though you'd need to manually enable it in the Web/App interface)
- I'm completely free to use with no charges

My knowledge cutoff is July 2024, and I'm the latest version of DeepSeek. I'm designed to be helpful, detailed, and warm in my responses.

What can I help you with today? Feel free to ask me anything! 😊

更多推荐