52 lines
1.5 KiB
Java
52 lines
1.5 KiB
Java
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);
|
||
}
|
||
|
||
}
|