spring-ai-alibaba-demo/src/test/java/com/baoshi/ChatModelTest.java

52 lines
1.5 KiB
Java
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package com.baoshi;
import com.alibaba.cloud.ai.dashscope.chat.DashScopeChatModel;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.PromptChatMemoryAdvisor;
import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.ai.chat.model.ChatModel;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
/**
* @author Wen
* @date 2026/3/20 18:26
*/
@SpringBootTest(classes = Main.class)
public class ChatModelTest {
private ChatClient chatClient;
@BeforeEach
public void init(@Autowired
ChatModel ollamaChatModel,
@Autowired ChatMemory chatMemory) {
chatClient = ChatClient
.builder(ollamaChatModel)
.defaultAdvisors(
PromptChatMemoryAdvisor.builder(chatMemory).build()
)
.build();
}
@Test
public void test() {
String content = chatClient.prompt()
.user("我叫邹志文?")
.call()
.content();
System.out.println(content);
System.out.println("--------------------------------------------------------------------------");
content = chatClient.prompt()
.user("我叫什么 ")
.call()
.content();
System.out.println(content);
}
}