deepseek4j Documentation

repository·main·Indexed 20 days ago

https://github.com/pig-mesh/deepseek4j

A Java SDK for integrating DeepSeek R1 and V3 models into Java applications. It features a Spring Boot starter for auto-configuration, support for reasoning chains, function calling, structured outputs, and reactive programming via Project Reactor for streaming chat responses.

Tokens
552
Snippets
3
Records
4
Agent score
23%

What's inside deepseek4j

  1. Overview of deepseek4j features

    main

    deepseek4j is a Java SDK for DeepSeek models (supporting R1 and V3 series). Key capabilities include:

    • Full API Support: Includes Chain of Thought (CoT) reasoning and session billing data.
    • WebSearch: Support for internet-connected searches.
    • Advanced Capabilities: Function calling, JSON structured output, and embedding generation via OpenAI-compatible protocols.
    • Customization: Support for custom connection parameters, proxy configurations, timeout settings, and request/response logging.
    • Reactive Programming: Built-in Reactor support for simplified streaming response development.
  2. Install deepseek4j via Maven

    main

    To use the DeepSeek Java SDK with Spring Boot, add the deepseek-spring-boot-starter dependency to your pom.xml. This starter provides auto-configuration and ready-to-use client instances for Spring Boot 2.x/3.x and Solon frameworks.

    <dependency>
        <groupId>io.github.pig-mesh.ai</groupId>
        <artifactId>deepseek-spring-boot-starter</artifactId>
        <version>1.5.0</version>
    </dependency>
  3. Use DeepSeekClient for streaming chat responses

    main

    Inject DeepSeekClient into your service or controller to interact with DeepSeek models. For real-time streaming (SSE), use the chatFluxCompletion method, which returns a Flux<ChatCompletionResponse> compatible with Project Reactor.

    @Autowired
    private DeepSeekClient deepSeekClient;
    
    // sse 流式返回
    @GetMapping(value = "/chat", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
    public Flux<ChatCompletionResponse> chat(String prompt) {
        return deepSeekClient.chatFluxCompletion(prompt);
    }