DeepSeek4j 1.4: A Java Framework for Seamless DeepSeek AI Integration with Full Chain‑of‑Thought and Streaming Support
The article introduces DeepSeek4j 1.4, a Java‑centric framework that overcomes Spring AI’s limitations by preserving DeepSeek’s chain‑of‑thought, supporting streaming output, and offering a simple Spring Boot starter with reactive, configurable, and ready‑to‑use APIs for AI developers.
DeepSeek R1 is popular for its chain‑of‑thought capabilities, but mainstream frameworks like Spring AI lack proper support for chain preservation and streaming output. The newly released DeepSeek4j 1.4 addresses these gaps.
Why DeepSeek4j?
DeepSeek4j is a Java‑focused integration framework for DeepSeek models, offering an elegant API that requires only a single line of code to connect to DeepSeek.
Limitations of Existing Frameworks
Chain content loss: The core reasoning process of R1 is ignored.
Incompatible response mode: Cannot handle "think first, conclude later" output.
Parameter restrictions: Settings such as temperature and top_p are ineffective.
Incomplete streaming: Poor user experience.
Solution
The open‑source project Pig, built on the excellent OpenAI4J architecture, created DeepSeek4j as a ready‑to‑use solution specifically for DeepSeek.
Enhanced support for DeepSeek’s unique chain‑of‑thought and billing features.
Full reactive support via Project Reactor.
Spring Boot Starter for automatic configuration.
Core Features
Complete preservation of chain‑of‑thought and billing.
Reactive streaming processing.
Simple and elegant API design.
Out‑of‑box Spring Boot integration for both 2.x and 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 (application.yml):
deepseek:
api-key: your-api-key-here
base-url: https://api.deepseek.com/v1 # optional, defaults to official API, supports alternativesBasic Usage:
@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);
}Front‑end Debugging: Double‑click the sse.html file in the project root to open the debugging page, enter the backend SSE endpoint, and view the inference process and final result in real time. The page includes the complete front‑end implementation for reference.
Project address: https://github.com/pig-mesh/deepseek4j
Documentation: https://javaai.pig4cloud.com/deepseek
Java Architect Essentials
Committed to sharing quality articles and tutorials to help Java programmers progress from junior to mid-level to senior architect. We curate high-quality learning resources, interview questions, videos, and projects from across the internet to help you systematically improve your Java architecture skills. Follow and reply '1024' to get Java programming resources. Learn together, grow 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.