Back to Repositories

Testing DeepSeek Chat Model Integration in ruoyi-vue-pro

This test suite validates the DeepSeekChatModel implementation, focusing on chat functionality and streaming responses in a Spring AI context. It tests both synchronous and streaming message processing capabilities.

Test Coverage Overview

The test suite covers core functionality of DeepSeekChatModel with both synchronous and streaming API tests.

Key areas tested include:
  • Message processing with system and user messages
  • Synchronous chat responses
  • Streaming message handling
  • Integration with Spring AI chat framework

Implementation Analysis

The testing approach utilizes JUnit 5 with @Test and @Disabled annotations for controlled execution. The implementation demonstrates Spring AI message handling patterns and reactor-based streaming for asynchronous operations.

Technical patterns include:
  • Message list construction
  • Prompt-based chat interactions
  • Reactive streaming with Flux

Technical Details

Testing infrastructure includes:
  • JUnit Jupiter test framework
  • Spring AI chat message types (SystemMessage, UserMessage)
  • Reactor Core for reactive streams
  • ChatResponse handling
  • DeepSeek API integration with authentication

Best Practices Demonstrated

The test suite exemplifies several testing best practices:

  • Isolated test methods for distinct functionality
  • Clear test method naming
  • Proper setup of test dependencies
  • Controlled test execution with @Disabled
  • Structured message preparation
  • Proper error handling in streaming tests

yunaiv/ruoyi-vue-pro

yudao-module-ai/yudao-spring-boot-starter-ai/src/test/java/cn/iocoder/yudao/framework/ai/chat/DeepSeekChatModelTests.java

            
package cn.iocoder.yudao.framework.ai.chat;

import cn.iocoder.yudao.framework.ai.core.model.deepseek.DeepSeekChatModel;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.ai.chat.messages.Message;
import org.springframework.ai.chat.messages.SystemMessage;
import org.springframework.ai.chat.messages.UserMessage;
import org.springframework.ai.chat.model.ChatResponse;
import org.springframework.ai.chat.prompt.Prompt;
import reactor.core.publisher.Flux;

import java.util.ArrayList;
import java.util.List;

/**
 * {@link DeepSeekChatModel} 集成测试
 *
 * @author 芋道源码
 */
public class DeepSeekChatModelTests {

    private final DeepSeekChatModel chatModel = new DeepSeekChatModel("sk-e94db327cc7d457d99a8de8810fc6b12");

    @Test
    @Disabled
    public void testCall() {
        // 准备参数
        List<Message> messages = new ArrayList<>();
        messages.add(new SystemMessage("你是一个优质的文言文作者,用文言文描述着各城市的人文风景。"));
        messages.add(new UserMessage("1 + 1 = ?"));

        // 调用
        ChatResponse response = chatModel.call(new Prompt(messages));
        // 打印结果
        System.out.println(response);
    }

    @Test
    @Disabled
    public void testStream() {
        // 准备参数
        List<Message> messages = new ArrayList<>();
        messages.add(new SystemMessage("你是一个优质的文言文作者,用文言文描述着各城市的人文风景。"));
        messages.add(new UserMessage("1 + 1 = ?"));

        // 调用
        Flux<ChatResponse> flux = chatModel.stream(new Prompt(messages));
        // 打印结果
        flux.doOnNext(System.out::println).then().block();
    }

}