How DeepSeek4j 1.4 Solves Spring AI’s Chain‑of‑Thought and Streaming Gaps

The article explains why existing Java AI frameworks struggle with DeepSeek R1’s chain‑of‑thought and streaming features, introduces DeepSeek4j 1.4 as a targeted solution, details its core capabilities, and provides a step‑by‑step guide to integrate it with Spring Boot and Project Reactor.

Java Web Project
Java Web Project
Java Web Project
How DeepSeek4j 1.4 Solves Spring AI’s Chain‑of‑Thought and Streaming Gaps

Problem with existing Java AI frameworks

DeepSeek R1’s chain‑of‑thought reasoning is lost when using frameworks such as Spring AI because they do not preserve the 思维链内容保留 (chain‑of‑thought) field and they lack proper streaming support. Additional issues include ignored parameters (e.g., temperature, top_p) and incompatibility with the “think first, answer later” response mode.

DeepSeek4j 1.4 solution

DeepSeek4j is a Java‑centric integration library built on the OpenAI4J architecture. It provides:

Full preservation of chain‑of‑thought and billing information.

Reactive streaming via Project Reactor.

Spring Boot Starter for automatic configuration (compatible with Spring Boot 2.x and 3.x).

Built‑in debugging page and detailed request/response logging.

Flexible proxy configuration and comprehensive reactive programming support.

Project resources

https://github.com/pig-mesh/deepseek4j
https://javaai.pig4cloud.com/deepseek

Quick start

Add Maven dependency

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

Configuration (application.yml)

deepseek:
  api-key: your-api-key-here
  base-url: https://api.deepseek.com/v1  # optional, defaults to official API; supports volcanic, gitee, silicon‑flow endpoints

Basic usage (Spring controller)

@Autowired
private DeepSeekClient deepSeekClient;

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

Front‑end debugging

Open sse.html located in the project root, enter the backend SSE endpoint URL, and click Send. The page displays the incremental inference steps and final result, and its source code can be used as a reference implementation.

Key implementation details

Chain‑of‑thought is kept in the messages payload under the role: "assistant" entries, allowing downstream consumers to reconstruct the reasoning path.

Streaming is implemented with Flux<ChatCompletionResponse> from Project Reactor, which forwards each server‑sent event to the client without buffering.

Proxy configuration can be set via standard Spring properties ( deepseek.proxy.host, deepseek.proxy.port).

Debug page is served at /deepseek/debug when the starter is on the classpath, exposing request headers, payload, and raw response.

Version and compatibility

DeepSeek4j 1.4 targets DeepSeek API version 1.0 and requires Java 17+. The starter works with Spring Boot 2.7+ and Spring Boot 3.x.

JavaSpring BootreactiveDeepSeekchain of thoughtAI integration
Java Web Project
Written by

Java Web Project

Focused on Java backend technologies, trending internet tech, and the latest industry developments. The platform serves over 200,000 Java developers, inviting you to learn and exchange ideas together. Check the menu for Java learning resources.

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.