Files
spring-ai/session-memory/src/broken/LegacyChatMemory.java
T

24 lines
1.1 KiB
Java

import org.springframework.ai.chat.client.ChatClient;
import org.springframework.ai.chat.client.advisor.MessageChatMemoryAdvisor;
import org.springframework.ai.chat.memory.ChatMemory;
import org.springframework.ai.chat.memory.InMemoryChatMemoryRepository;
import org.springframework.ai.chat.memory.MessageWindowChatMemory;
import org.springframework.ai.chat.model.ChatModel;
/** The 2.0 way of keeping a conversation. Compiles on 2.1.0, with deprecation warnings. Not part of the build. */
class LegacyChatMemory {
String ask(ChatModel model, String conversationId, String text) {
ChatMemory memory = MessageWindowChatMemory.builder()
.chatMemoryRepository(new InMemoryChatMemoryRepository())
.maxMessages(20)
.build();
ChatClient chat = ChatClient.builder(model)
.defaultAdvisors(MessageChatMemoryAdvisor.builder(memory).build())
.build();
return chat.prompt().user(text)
.advisors(a -> a.param(ChatMemory.CONVERSATION_ID, conversationId))
.call().content();
}
}