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

springboot集成deepseek4j

1、文档地址

快速开始 - 零基础入门Java AI

免费的模型

Models

2、pom文件依赖 parent依赖

           <dependency>
                <groupId>com.squareup.okhttp3</groupId>
                <artifactId>okhttp</artifactId>
                <version>4.12.0</version>
            </dependency>
            <dependency>
                <groupId>com.squareup.okhttp3</groupId>
                <artifactId>okhttp-sse</artifactId>
                <version>4.12.0</version>
            </dependency>
            <dependency>
                <groupId>com.fasterxml.jackson</groupId>
                <artifactId>jackson-bom</artifactId>
                <version>2.12.4</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>

工程pom

      <dependency>
            <groupId>io.github.pig-mesh.ai</groupId>
            <artifactId>deepseek-spring-boot-starter</artifactId>
            <version>1.4.5</version>
        </dependency>

        <dependency>
            <groupId>com.squareup.okhttp3</groupId>
            <artifactId>okhttp</artifactId>
            <version>4.12.0</version>
        </dependency>
        <dependency>
            <groupId>com.squareup.okhttp3</groupId>
            <artifactId>okhttp-sse</artifactId>
            <version>4.12.0</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson</groupId>
            <artifactId>jackson-bom</artifactId>
            <version>2.12.4</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>

3、deepseek  api配置

deepseek:
  api-key: sk-xxxxxxxxxxx
  model: deepseek-r1
  base-url: https://xxx.xxxx.xxxx.xxxx.com/v1

4、代码

package com.yh.im.controller;

import io.github.pigmesh.ai.deepseek.core.DeepSeekClient;
import io.github.pigmesh.ai.deepseek.core.chat.ChatCompletionRequest;
import io.github.pigmesh.ai.deepseek.core.chat.ChatCompletionResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;
import reactor.core.publisher.Flux;

@RestController
public class DeepSeekController {

    @Autowired
    private DeepSeekClient deepSeekClient;

    @GetMapping(value = "/chat", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
    public Flux<ChatCompletionResponse> chat(String prompt) {
        return deepSeekClient.chatFluxCompletion(prompt);
    }

    @GetMapping(value = "/sync/chat")
    public ChatCompletionResponse syncChat(String prompt) {
        ChatCompletionRequest request = ChatCompletionRequest.builder()
                // 根据渠道模型名称动态修改这个参数
//                .model(deepSeekProperties.getModel())
                .addUserMessage(prompt).build();

        return deepSeekClient.chatCompletion(request).execute();
    }
}

相关文章:

  • 「Selenium+Python自动化从0到1①|2025最新环境搭建+浏览器驱动避坑指南(附验证代码)」
  • k8s中pod的调度策略之pod的亲和性调度与反亲和性调度 一文搞懂 k8s中创建的pod如何调度?
  • Spring Cloud Alibaba学习 3- Sentinel入门使用
  • java后端开发day20--面向对象进阶(一)--static继承
  • C# Unity 唐老狮 No.1 模拟面试题
  • 在Linux环境下利用MTCNN进行人脸检测(基于ncnn架构)
  • ARM Coretex-M核心单片机(STM32)分析hardfault的原因
  • Spring如何解决循环依赖?
  • CCF-CSP历年真题大全附题解python
  • 矩阵的奇异值(SVD)分解和线性变换
  • DeepSeek推出DeepEP:首个开源EP通信库,让MoE模型训练与推理起飞!
  • FastJSON 默认行为:JSON.toJSONString 忽略 null 字段
  • python 使用 venv 创建虚拟环境 (VSCode)
  • 关于命令行下的 git( git add、git commit、git push)
  • 字符串_替换数字
  • 蓝桥每日打卡
  • HBase与MapReduce结合(一)——HBase表中插入数据
  • Ubuntu 下 nginx-1.24.0 源码分析 - pool->cleanup
  • 半导体制造工艺(二)光刻工艺—掩模版
  • SpringAI从人工智障到人工智能的实战改造
  • 王沪宁主持召开全国政协主席会议
  • 五月院线片单:就看五一档表现了
  • 上海第三家“胖永辉”在浦东开业,设立了外贸产品专区
  • 马上评|演唱会云集,上海如何把“流量”变“留量”
  • 伊朗港口爆炸致18死800余伤,三分之二伤者已出院
  • 只在上海!德国剧团新作亚洲首演:一张古典与流行的声音网络