DeepSeek4j 1.4: Java Integration Framework for DeepSeek with Full Chain‑of‑Thought and Streaming Support
The article introduces DeepSeek4j 1.4, a Java‑based framework that overcomes Spring AI’s limitations by fully preserving DeepSeek’s chain‑of‑thought and billing features, adding reactive streaming, providing Spring Boot starter integration, and offering quick‑start code samples and configuration guidance.
DeepSeek R1 is popular for its powerful chain‑of‑thought capabilities, but mainstream frameworks like Spring AI lack proper support for chain‑of‑thought content retention and streaming output.
The newly released DeepSeek4j 1.4 version addresses these gaps with important updates.
Project address: https://github.com/pig-mesh/deepseek4j
Documentation address: https://javaai.pig4cloud.com/deepseek
Why DeepSeek4j is needed
DeepSeek4j is a DeepSeek model integration framework built specifically for the Java ecosystem. Its API is concise and elegant, requiring only a single line of code to integrate DeepSeek.
Limitations of existing frameworks
Chain‑of‑thought loss: The core reasoning process of R1 is completely ignored.
Incompatible response mode: Unable to handle “think first, conclude later” output patterns.
Parameter restrictions: Settings such as temperature and top_p become ineffective.
Incomplete streaming support: Poor user experience.
Solution
The author of the open‑source project Pig, based on the excellent architecture of OpenAI4J, created an out‑of‑the‑box solution for DeepSeek—DeepSeek4j.
Enhanced support for DeepSeek’s unique chain‑of‑thought and billing features.
Full reactive support via Project Reactor.
Spring Boot starter integration with automatic configuration.
Core Features
Complete preservation of chain‑of‑thought capability and billing.
Reactive streaming processing.
Simple and elegant API design.
Ready‑to‑use Spring Boot integration supporting 2.x / 3.x.
Built‑in debugging page.
Detailed request‑response logging.
Flexible proxy configuration.
Comprehensive reactive programming support.
Quick Start
Add dependency:
<dependency>
<groupId>io.github.pig-mesh.ai</groupId>
<artifactId>deepseek-spring-boot-starter</artifactId>
<version>1.1.0</version>
</dependency>Configuration parameters (application.yml):
deepseek:
api-key: your-api-key-here
base-url: https://api.deepseek.com/v1 # optional, defaults to official API address, supports Volcano, Gitee, Silicon FlowBasic usage (Java):
@Autowired
private DeepSeekClient deepSeekClient;
// SSE streaming response
@GetMapping(value = "/chat", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
public Flux<ChatCompletionResponse> chat(String prompt) {
return deepSeekClient.chatFluxCompletion(prompt);
}Frontend debugging: Double‑click the sse.html file in the project root to open the debugging page, enter the backend SSE endpoint, and view the reasoning process and final result in real time. The page includes the complete front‑end implementation code for reference.
Top Architect
Top Architect focuses on sharing practical architecture knowledge, covering enterprise, system, website, large‑scale distributed, and high‑availability architectures, plus architecture adjustments using internet technologies. We welcome idea‑driven, sharing‑oriented architects to exchange and learn together.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.