AIGC宇宙 AIGC宇宙

Spring 宣布接入 DeepSeek

作者:不才陈某
2025-02-17 12:25
DeepSeek 是深度求索公司发布的大模型,是国产之光。 大家应该学会如何使用 DeepSeek 大模型,下面我们将看下如何开发基于 DeepSeek 大模型的智能应用。 DeepSeek 大模型DeepSeek 推出两款模型;DeepSeek V 系列,对于V系列主要 对话,模型名称:deepseek-chatDeepSeek R 系统,对于R系统主要 推理, 模型名称:deepseek-reasonerDeepSeek 官方更新日志,可以看到模型发布和演化的过程。

DeepSeek 是深度求索公司发布的大模型,是国产之光。大家应该学会如何使用 DeepSeek 大模型,下面我们将看下如何开发基于 DeepSeek 大模型的智能应用。

DeepSeek 大模型

DeepSeek 推出两款模型;

  • DeepSeek V 系列,对于V系列主要 对话,模型名称:deepseek-chat
  • DeepSeek R 系统,对于R系统主要 推理, 模型名称:deepseek-reasoner

DeepSeek 官方更新日志,可以看到模型发布和演化的过程。

https://api-docs.deepseek.com/zh-cn/updates

集成 DeepSeek 大模型

DeepSeek AI提供开源的 DeepSeek V3 模型,该模型以其尖端的推理和解决问题的能力而闻名。

Spring AI 通过重用现有的 OpenAI 客户端与 DeepSeek AI 集成。首先,您需要获取 DeepSeek API 密钥,配置基本 URL,并选择其中一个受支持的模型。

图片

接入前准备

  1. 创建 API 密钥:访问此处:https://api-docs.deepseek.com/zh-cn/创建 API 密钥。使用 Spring AI 项目中的 spring.ai.openai.api-key 属性对其进行配置。
  2. 设置 DeepSeek 基本 URL:将 spring.ai.openai.base-url 属性设置为 api.deepseek.com。
  3. 选择 DeepSeek 模型:使用属性 spring.ai.openai.chat.model=<model name> 指定模型。有关可用选项,请参阅支持的型号。

集成 DeepSeek 示例

1、引入依赖

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

2、配置

复制
spring:
  ai:
    openai:
      api-key: sk-xxx   // 填写自己申请的key
      base-url: https://api.deepseek.com
      chat:
        options:
          model: deepseek-chat

3、简单的聊天示例

复制
package com.ivy.controller;

import org.springframework.ai.chat.messages.UserMessage;
import org.springframework.ai.chat.model.ChatResponse;
import org.springframework.ai.chat.prompt.Prompt;
import org.springframework.ai.openai.OpenAiChatModel;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

import java.util.Map;


@RestController
public class ChatController {

    private final OpenAiChatModel chatModel;
    
    public ChatController(OpenAiChatModel chatModel) {
        this.chatModel = chatModel;
    }

    @GetMapping("/ai/generate")
    public Map<String, String> generate(@RequestParam(value = "message", defaultValue = "Tell me a joke") String message) {
        return Map.of("generation", this.chatModel.call(message));
    }

    @GetMapping("/ai/generateStream")
    public Flux<ChatResponse> generateStream(@RequestParam(value = "message", defaultValue = "Tell me a joke") String message) {
        Prompt prompt = new Prompt(new UserMessage(message));
        return this.chatModel.stream(prompt);
    }
}

现阶段 DeepSeek 服务受资源限制可能无法提供在线服务,那么可以本地部署一个DeepSeek 大模型进行学习和使用。

总结

Spring AI 接入 DeepSeek 大模型是非常简单的,实现了阻塞和流式聊天模式。对于 DeepSeek 大模型的函数调用,角色定义以及结构化输出等和之前文章中讲解的内容是一致的,没有什么特别的地方,这里也不再赘述了。

源码案例:https://github.com/Fj-ivy/spring-ai-examples

相关标签:

相关资讯

基于 Spring AI + MCP + DeepSeek-R1-7B 构建企业级智能 Agent 工具调用系统

在大模型 Agent 发展浪潮下,如何通过模型驱动外部工具调用(Tool Calling)已成为构建智能业务系统的关键能力。 本文将手把手带你通过 Spring AI MCP(Model Context Protocol) DeepSeek-R1-7B 打造一个可落地的企业级智能 Agent。 项目背景与架构设计技术选型Spring AISpring 官方推出的 AI 接入框架,支持 LangChain、MCP、RAG 等能力;MCP(Model Context Protocol)模型与工具之间通信的协议桥梁;DeepSeek-R1-7B国产高性能开源大模型,已支持 Chat Completion、Tool Calling 接口;Ragflow用作 RAG 架构引擎(可选);系统功能用户向模型提问模型判断是否调用工具(如数据库查询)MCP 注册的工具服务完成任务模型生成最终响应环境准备安装依赖复制本地部署 DeepSeek-R1-7B 模型推荐使用 vLLM 启动 DeepSeek-R1-7B 模型服务:复制构建 Spring AI MCP 工具服务示例业务:产品信息查询复制注册 MCP 工具复制模型端配置(Ragflow 示例)在 ragflow.config.yaml 中配置模型地址及 MCP 工具启用:复制前端调用(可选)复制测试效果用户输入:复制输出结果:复制模型会自动触发 query-product 工具,无需用户指定,展示 Agent 工具能力。
4/21/2025 4:22:00 AM
编程疏影

重磅开源!基于 Spring Boot 的企业级 DeepSeek 知识库与智能对话方案

本项目基于 Spring Boot 3.4 构建,旨在打造一款高效、智能的企业级知识库与智能对话平台,充分集成 DeepSeek 大语言模型,以支持企业级私有化部署和智能客服应用。 项目目标该方案通过整合 DeepSeek 强大的自然语言处理能力,实现高效、精准的对话交互,同时支持企业知识库的管理,助力企业构建智能化的客户支持与内部知识共享体系。 技术架构后端基于 Spring Boot 3.4 开发,提供 RESTful API 以处理业务逻辑,并与 DeepSeek 模型进行高效交互。
3/7/2025 7:57:56 AM
路条编程

o3被曝成绩「造假」,60多位数学泰斗集体被耍!OpenAI暗中操控,考卷提前看光

不久前,OpenAI在「圣诞12连更」中发布的最强推理模型「o3」,毫无疑问地惊艳了所有人。 尤其是对于新近发布的数学基准FrontierMath,其准确率相比o1直接翻了12倍。 图片要知道FrontierMath可是Epoch AI联合六十余位全世界的数学家,其中包括教授、IMO命题人、菲尔兹奖获得者,共同推出的。
1/20/2025 12:09:18 PM
新智元
  • 1