From ad527303ed8295bcafd3d770e07058d75dfe0c86 Mon Sep 17 00:00:00 2001 From: Mark Pollack Date: Wed, 8 May 2024 15:43:00 -0400 Subject: [PATCH] Rename Agent classes to use ChatBot --- .../ChatMemoryLongTermSystemPromptIT.java | 10 +++--- .../ChatMemoryShortTermMessageListIT.java | 10 +++--- .../ChatMemoryShortTermSystemPromptIT.java | 10 +++--- .../LongShortTermChatMemoryWithRagIT.java | 10 +++--- ...gentListener.java => ChatBotListener.java} | 4 +-- .../ai/chat/chatbot/DefaultChatBot.java | 32 +++++++++---------- .../chat/chatbot/DefaultStreamingChatBot.java | 32 +++++++++---------- ...er.java => ChatMemoryChatBotListener.java} | 6 ++-- ...VectorStoreChatMemoryChatBotListener.java} | 8 ++--- .../ai/chat/history/ChatMemoryTests.java | 20 ++++++------ .../ai/evaluation/BaseMemoryTest.java | 2 +- 11 files changed, 72 insertions(+), 72 deletions(-) rename spring-ai-core/src/main/java/org/springframework/ai/chat/chatbot/{ChatAgentListener.java => ChatBotListener.java} (88%) rename spring-ai-core/src/main/java/org/springframework/ai/chat/history/{ChatMemoryAgentListener.java => ChatMemoryChatBotListener.java} (91%) rename spring-ai-core/src/main/java/org/springframework/ai/chat/history/{VectorStoreChatMemoryAgentListener.java => VectorStoreChatMemoryChatBotListener.java} (90%) diff --git a/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/chatbot/ChatMemoryLongTermSystemPromptIT.java b/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/chatbot/ChatMemoryLongTermSystemPromptIT.java index 4f33bd993..546fc0726 100644 --- a/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/chatbot/ChatMemoryLongTermSystemPromptIT.java +++ b/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/chatbot/ChatMemoryLongTermSystemPromptIT.java @@ -29,7 +29,7 @@ import org.testcontainers.qdrant.QdrantContainer; import org.springframework.ai.chat.chatbot.DefaultChatBot; import org.springframework.ai.chat.chatbot.DefaultStreamingChatBot; import org.springframework.ai.chat.chatbot.StreamingChatBot; -import org.springframework.ai.chat.history.VectorStoreChatMemoryAgentListener; +import org.springframework.ai.chat.history.VectorStoreChatMemoryChatBotListener; import org.springframework.ai.chat.history.VectorStoreChatMemoryRetriever; import org.springframework.ai.chat.history.LastMaxTokenSizeContentTransformer; import org.springframework.ai.chat.history.SystemPromptChatMemoryAugmentor; @@ -98,26 +98,26 @@ public class ChatMemoryLongTermSystemPromptIT extends BaseMemoryTest { } @Bean - public ChatBot memoryChatAgent(OpenAiChatClient chatClient, VectorStore vectorStore, + public ChatBot memoryChatBot(OpenAiChatClient chatClient, VectorStore vectorStore, TokenCountEstimator tokenCountEstimator) { return DefaultChatBot.builder(chatClient) .withRetrievers(List.of(new VectorStoreChatMemoryRetriever(vectorStore, 10))) .withContentPostProcessors(List.of(new LastMaxTokenSizeContentTransformer(tokenCountEstimator, 1000))) .withAugmentors(List.of(new SystemPromptChatMemoryAugmentor())) - .withChatAgentListeners(List.of(new VectorStoreChatMemoryAgentListener(vectorStore))) + .withChatBotListeners(List.of(new VectorStoreChatMemoryChatBotListener(vectorStore))) .build(); } @Bean - public StreamingChatBot memoryStreamingChatAgent(OpenAiChatClient streamingChatClient, VectorStore vectorStore, + public StreamingChatBot memoryStreamingChatBot(OpenAiChatClient streamingChatClient, VectorStore vectorStore, TokenCountEstimator tokenCountEstimator) { return DefaultStreamingChatBot.builder(streamingChatClient) .withRetrievers(List.of(new VectorStoreChatMemoryRetriever(vectorStore, 10))) .withDocumentPostProcessors(List.of(new LastMaxTokenSizeContentTransformer(tokenCountEstimator, 1000))) .withAugmentors(List.of(new SystemPromptChatMemoryAugmentor())) - .withChatAgentListeners(List.of(new VectorStoreChatMemoryAgentListener(vectorStore))) + .withChatBotListeners(List.of(new VectorStoreChatMemoryChatBotListener(vectorStore))) .build(); } diff --git a/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/chatbot/ChatMemoryShortTermMessageListIT.java b/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/chatbot/ChatMemoryShortTermMessageListIT.java index 1c857ddbb..5d88ce34b 100644 --- a/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/chatbot/ChatMemoryShortTermMessageListIT.java +++ b/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/chatbot/ChatMemoryShortTermMessageListIT.java @@ -24,7 +24,7 @@ import org.springframework.ai.chat.chatbot.DefaultChatBot; import org.springframework.ai.chat.chatbot.DefaultStreamingChatBot; import org.springframework.ai.chat.chatbot.StreamingChatBot; import org.springframework.ai.chat.history.ChatMemory; -import org.springframework.ai.chat.history.ChatMemoryAgentListener; +import org.springframework.ai.chat.history.ChatMemoryChatBotListener; import org.springframework.ai.chat.history.ChatMemoryRetriever; import org.springframework.ai.chat.history.InMemoryChatMemory; import org.springframework.ai.chat.history.LastMaxTokenSizeContentTransformer; @@ -74,26 +74,26 @@ public class ChatMemoryShortTermMessageListIT extends BaseMemoryTest { } @Bean - public ChatBot memoryChatAgent(OpenAiChatClient chatClient, ChatMemory chatHistory, + public ChatBot memoryChatBot(OpenAiChatClient chatClient, ChatMemory chatHistory, TokenCountEstimator tokenCountEstimator) { return DefaultChatBot.builder(chatClient) .withRetrievers(List.of(new ChatMemoryRetriever(chatHistory))) .withContentPostProcessors(List.of(new LastMaxTokenSizeContentTransformer(tokenCountEstimator, 1000))) .withAugmentors(List.of(new MessageChatMemoryAugmentor())) - .withChatAgentListeners(List.of(new ChatMemoryAgentListener(chatHistory))) + .withChatBotListeners(List.of(new ChatMemoryChatBotListener(chatHistory))) .build(); } @Bean - public StreamingChatBot memoryStreamingChatAgent(OpenAiChatClient streamingChatClient, ChatMemory chatHistory, + public StreamingChatBot memoryStreamingChatBot(OpenAiChatClient streamingChatClient, ChatMemory chatHistory, TokenCountEstimator tokenCountEstimator) { return DefaultStreamingChatBot.builder(streamingChatClient) .withRetrievers(List.of(new ChatMemoryRetriever(chatHistory))) .withDocumentPostProcessors(List.of(new LastMaxTokenSizeContentTransformer(tokenCountEstimator, 1000))) .withAugmentors(List.of(new MessageChatMemoryAugmentor())) - .withChatAgentListeners(List.of(new ChatMemoryAgentListener(chatHistory))) + .withChatBotListeners(List.of(new ChatMemoryChatBotListener(chatHistory))) .build(); } diff --git a/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/chatbot/ChatMemoryShortTermSystemPromptIT.java b/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/chatbot/ChatMemoryShortTermSystemPromptIT.java index ac5b1d386..b3a9d43ed 100644 --- a/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/chatbot/ChatMemoryShortTermSystemPromptIT.java +++ b/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/chatbot/ChatMemoryShortTermSystemPromptIT.java @@ -25,7 +25,7 @@ import org.springframework.ai.chat.chatbot.DefaultChatBot; import org.springframework.ai.chat.chatbot.DefaultStreamingChatBot; import org.springframework.ai.chat.chatbot.StreamingChatBot; import org.springframework.ai.chat.history.ChatMemory; -import org.springframework.ai.chat.history.ChatMemoryAgentListener; +import org.springframework.ai.chat.history.ChatMemoryChatBotListener; import org.springframework.ai.chat.history.ChatMemoryRetriever; import org.springframework.ai.chat.history.InMemoryChatMemory; import org.springframework.ai.chat.history.LastMaxTokenSizeContentTransformer; @@ -75,26 +75,26 @@ public class ChatMemoryShortTermSystemPromptIT extends BaseMemoryTest { } @Bean - public ChatBot memoryChatAgent(OpenAiChatClient chatClient, ChatMemory chatHistory, + public ChatBot memoryChatBot(OpenAiChatClient chatClient, ChatMemory chatHistory, TokenCountEstimator tokenCountEstimator) { return DefaultChatBot.builder(chatClient) .withRetrievers(List.of(new ChatMemoryRetriever(chatHistory))) .withContentPostProcessors(List.of(new LastMaxTokenSizeContentTransformer(tokenCountEstimator, 1000))) .withAugmentors(List.of(new SystemPromptChatMemoryAugmentor())) - .withChatAgentListeners(List.of(new ChatMemoryAgentListener(chatHistory))) + .withChatBotListeners(List.of(new ChatMemoryChatBotListener(chatHistory))) .build(); } @Bean - public StreamingChatBot memoryStreamingChatAgent(OpenAiChatClient streamingChatClient, ChatMemory chatHistory, + public StreamingChatBot memoryStreamingChatBot(OpenAiChatClient streamingChatClient, ChatMemory chatHistory, TokenCountEstimator tokenCountEstimator) { return DefaultStreamingChatBot.builder(streamingChatClient) .withRetrievers(List.of(new ChatMemoryRetriever(chatHistory))) .withDocumentPostProcessors(List.of(new LastMaxTokenSizeContentTransformer(tokenCountEstimator, 1000))) .withAugmentors(List.of(new SystemPromptChatMemoryAugmentor())) - .withChatAgentListeners(List.of(new ChatMemoryAgentListener(chatHistory))) + .withChatBotListeners(List.of(new ChatMemoryChatBotListener(chatHistory))) .build(); } diff --git a/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/chatbot/LongShortTermChatMemoryWithRagIT.java b/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/chatbot/LongShortTermChatMemoryWithRagIT.java index c513c8776..8578be668 100644 --- a/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/chatbot/LongShortTermChatMemoryWithRagIT.java +++ b/models/spring-ai-openai/src/test/java/org/springframework/ai/openai/chat/chatbot/LongShortTermChatMemoryWithRagIT.java @@ -34,12 +34,12 @@ import org.testcontainers.qdrant.QdrantContainer; import org.springframework.ai.chat.chatbot.DefaultChatBot; import org.springframework.ai.chat.history.ChatMemory; -import org.springframework.ai.chat.history.ChatMemoryAgentListener; +import org.springframework.ai.chat.history.ChatMemoryChatBotListener; import org.springframework.ai.chat.history.ChatMemoryRetriever; import org.springframework.ai.chat.history.InMemoryChatMemory; import org.springframework.ai.chat.history.LastMaxTokenSizeContentTransformer; import org.springframework.ai.chat.history.SystemPromptChatMemoryAugmentor; -import org.springframework.ai.chat.history.VectorStoreChatMemoryAgentListener; +import org.springframework.ai.chat.history.VectorStoreChatMemoryChatBotListener; import org.springframework.ai.chat.history.VectorStoreChatMemoryRetriever; import org.springframework.ai.chat.messages.UserMessage; import org.springframework.ai.chat.prompt.Prompt; @@ -187,7 +187,7 @@ public class LongShortTermChatMemoryWithRagIT { } @Bean - public ChatBot memoryChatAgent(OpenAiChatClient chatClient, VectorStore vectorStore, + public ChatBot memoryChatBot(OpenAiChatClient chatClient, VectorStore vectorStore, TokenCountEstimator tokenCountEstimator, ChatMemory chatHistory) { return DefaultChatBot.builder(chatClient) @@ -214,8 +214,8 @@ public class LongShortTermChatMemoryWithRagIT { Set.of(TransformerContentType.LONG_TERM_MEMORY)), new SystemPromptChatMemoryAugmentor(Set.of(TransformerContentType.SHORT_TERM_MEMORY)))) - .withChatAgentListeners(List.of(new ChatMemoryAgentListener(chatHistory), - new VectorStoreChatMemoryAgentListener(vectorStore, + .withChatBotListeners(List.of(new ChatMemoryChatBotListener(chatHistory), + new VectorStoreChatMemoryChatBotListener(vectorStore, Map.of(TransformerContentType.LONG_TERM_MEMORY, "")))) .build(); } diff --git a/spring-ai-core/src/main/java/org/springframework/ai/chat/chatbot/ChatAgentListener.java b/spring-ai-core/src/main/java/org/springframework/ai/chat/chatbot/ChatBotListener.java similarity index 88% rename from spring-ai-core/src/main/java/org/springframework/ai/chat/chatbot/ChatAgentListener.java rename to spring-ai-core/src/main/java/org/springframework/ai/chat/chatbot/ChatBotListener.java index 68699a06f..7e591b46d 100644 --- a/spring-ai-core/src/main/java/org/springframework/ai/chat/chatbot/ChatAgentListener.java +++ b/spring-ai-core/src/main/java/org/springframework/ai/chat/chatbot/ChatBotListener.java @@ -19,13 +19,13 @@ package org.springframework.ai.chat.chatbot; import org.springframework.ai.chat.prompt.transformer.PromptContext; /** - * The ChatAgentListener is a callback interface that can be implemented by classes that + * The ChatBotListener is a callback interface that can be implemented by classes that * want to be notified of the completion of a ChatBot execution. * * @author Mark Pollack * @author Christian Tzolov */ -public interface ChatAgentListener { +public interface ChatBotListener { default void onStart(PromptContext promptContext) { diff --git a/spring-ai-core/src/main/java/org/springframework/ai/chat/chatbot/DefaultChatBot.java b/spring-ai-core/src/main/java/org/springframework/ai/chat/chatbot/DefaultChatBot.java index 3c8559865..ebbac06ca 100644 --- a/spring-ai-core/src/main/java/org/springframework/ai/chat/chatbot/DefaultChatBot.java +++ b/spring-ai-core/src/main/java/org/springframework/ai/chat/chatbot/DefaultChatBot.java @@ -38,21 +38,21 @@ public class DefaultChatBot implements ChatBot { private List augmentors; - private List chatAgentListeners; + private List chatBotListeners; public DefaultChatBot(ChatClient chatClient, List retrievers, List documentPostProcessors, List augmentors, - List chatAgentListeners) { + List chatBotListeners) { Objects.requireNonNull(chatClient, "chatClient must not be null"); this.chatClient = chatClient; this.retrievers = retrievers; this.documentPostProcessors = documentPostProcessors; this.augmentors = augmentors; - this.chatAgentListeners = chatAgentListeners; + this.chatBotListeners = chatBotListeners; } - public static DefaultChatAgentBuilder builder(ChatClient chatClient) { - return new DefaultChatAgentBuilder().withChatClient(chatClient); + public static DefaultChatBotBuilder builder(ChatClient chatClient) { + return new DefaultChatBotBuilder().withChatClient(chatClient); } @Override @@ -76,7 +76,7 @@ public class DefaultChatBot implements ChatBot { } // Invoke Listeners onStart - for (ChatAgentListener listener : this.chatAgentListeners) { + for (ChatBotListener listener : this.chatBotListeners) { listener.onStart(promptContextOnStart); } @@ -85,13 +85,13 @@ public class DefaultChatBot implements ChatBot { // Invoke Listeners onComplete ChatBotResponse chatBotResponse = new ChatBotResponse(promptContext, chatResponse); - for (ChatAgentListener listener : this.chatAgentListeners) { + for (ChatBotListener listener : this.chatBotListeners) { listener.onComplete(chatBotResponse); } return chatBotResponse; } - public static class DefaultChatAgentBuilder { + public static class DefaultChatBotBuilder { private ChatClient chatClient; @@ -101,35 +101,35 @@ public class DefaultChatBot implements ChatBot { private List augmentors = new ArrayList<>(); - private List chatAgentListeners = new ArrayList<>(); + private List chatBotListeners = new ArrayList<>(); - public DefaultChatAgentBuilder withChatClient(ChatClient chatClient) { + public DefaultChatBotBuilder withChatClient(ChatClient chatClient) { this.chatClient = chatClient; return this; } - public DefaultChatAgentBuilder withRetrievers(List retrievers) { + public DefaultChatBotBuilder withRetrievers(List retrievers) { this.retrievers = retrievers; return this; } - public DefaultChatAgentBuilder withContentPostProcessors(List documentPostProcessors) { + public DefaultChatBotBuilder withContentPostProcessors(List documentPostProcessors) { this.documentPostProcessors = documentPostProcessors; return this; } - public DefaultChatAgentBuilder withAugmentors(List augmentors) { + public DefaultChatBotBuilder withAugmentors(List augmentors) { this.augmentors = augmentors; return this; } - public DefaultChatAgentBuilder withChatAgentListeners(List chatAgentListeners) { - this.chatAgentListeners = chatAgentListeners; + public DefaultChatBotBuilder withChatBotListeners(List chatBotListeners) { + this.chatBotListeners = chatBotListeners; return this; } public DefaultChatBot build() { - return new DefaultChatBot(chatClient, retrievers, documentPostProcessors, augmentors, chatAgentListeners); + return new DefaultChatBot(chatClient, retrievers, documentPostProcessors, augmentors, chatBotListeners); } } diff --git a/spring-ai-core/src/main/java/org/springframework/ai/chat/chatbot/DefaultStreamingChatBot.java b/spring-ai-core/src/main/java/org/springframework/ai/chat/chatbot/DefaultStreamingChatBot.java index 15ea38f49..bdc79d0b8 100644 --- a/spring-ai-core/src/main/java/org/springframework/ai/chat/chatbot/DefaultStreamingChatBot.java +++ b/spring-ai-core/src/main/java/org/springframework/ai/chat/chatbot/DefaultStreamingChatBot.java @@ -41,21 +41,21 @@ public class DefaultStreamingChatBot implements StreamingChatBot { private List augmentors; - private List chatAgentListeners; + private List chatBotListeners; public DefaultStreamingChatBot(StreamingChatClient chatClient, List retrievers, List documentPostProcessors, List augmentors, - List chatAgentListeners) { + List chatBotListeners) { Objects.requireNonNull(chatClient, "chatClient must not be null"); this.streamingChatClient = chatClient; this.retrievers = retrievers; this.documentPostProcessors = documentPostProcessors; this.augmentors = augmentors; - this.chatAgentListeners = chatAgentListeners; + this.chatBotListeners = chatBotListeners; } - public static DefaultChatAgentBuilder builder(StreamingChatClient chatClient) { - return new DefaultChatAgentBuilder().withChatClient(chatClient); + public static DefaultChatBotBuilder builder(StreamingChatClient chatClient) { + return new DefaultChatBotBuilder().withChatClient(chatClient); } @Override @@ -79,7 +79,7 @@ public class DefaultStreamingChatBot implements StreamingChatBot { } // Invoke Listeners onStart - for (ChatAgentListener listener : this.chatAgentListeners) { + for (ChatBotListener listener : this.chatBotListeners) { listener.onStart(promptContextOnStart); } @@ -88,7 +88,7 @@ public class DefaultStreamingChatBot implements StreamingChatBot { Flux fluxChatResponse = new MessageAggregator() .aggregate(this.streamingChatClient.stream(promptContext.getPrompt()), chatResponse -> { - for (ChatAgentListener listener : this.chatAgentListeners) { + for (ChatBotListener listener : this.chatBotListeners) { listener.onComplete(new ChatBotResponse(promptContext2, chatResponse)); } }); @@ -97,7 +97,7 @@ public class DefaultStreamingChatBot implements StreamingChatBot { return new StreamingChatBotResponse(promptContext, fluxChatResponse); } - public static class DefaultChatAgentBuilder { + public static class DefaultChatBotBuilder { private StreamingChatClient chatClient; @@ -107,36 +107,36 @@ public class DefaultStreamingChatBot implements StreamingChatBot { private List augmentors = new ArrayList<>(); - private List chatAgentListeners = new ArrayList<>(); + private List chatBotListeners = new ArrayList<>(); - public DefaultChatAgentBuilder withChatClient(StreamingChatClient chatClient) { + public DefaultChatBotBuilder withChatClient(StreamingChatClient chatClient) { this.chatClient = chatClient; return this; } - public DefaultChatAgentBuilder withRetrievers(List retrievers) { + public DefaultChatBotBuilder withRetrievers(List retrievers) { this.retrievers = retrievers; return this; } - public DefaultChatAgentBuilder withDocumentPostProcessors(List documentPostProcessors) { + public DefaultChatBotBuilder withDocumentPostProcessors(List documentPostProcessors) { this.documentPostProcessors = documentPostProcessors; return this; } - public DefaultChatAgentBuilder withAugmentors(List augmentors) { + public DefaultChatBotBuilder withAugmentors(List augmentors) { this.augmentors = augmentors; return this; } - public DefaultChatAgentBuilder withChatAgentListeners(List chatAgentListeners) { - this.chatAgentListeners = chatAgentListeners; + public DefaultChatBotBuilder withChatBotListeners(List chatBotListeners) { + this.chatBotListeners = chatBotListeners; return this; } public DefaultStreamingChatBot build() { return new DefaultStreamingChatBot(chatClient, retrievers, documentPostProcessors, augmentors, - chatAgentListeners); + chatBotListeners); } } diff --git a/spring-ai-core/src/main/java/org/springframework/ai/chat/history/ChatMemoryAgentListener.java b/spring-ai-core/src/main/java/org/springframework/ai/chat/history/ChatMemoryChatBotListener.java similarity index 91% rename from spring-ai-core/src/main/java/org/springframework/ai/chat/history/ChatMemoryAgentListener.java rename to spring-ai-core/src/main/java/org/springframework/ai/chat/history/ChatMemoryChatBotListener.java index 6b92c365c..2ddf30489 100644 --- a/spring-ai-core/src/main/java/org/springframework/ai/chat/history/ChatMemoryAgentListener.java +++ b/spring-ai-core/src/main/java/org/springframework/ai/chat/history/ChatMemoryChatBotListener.java @@ -19,7 +19,7 @@ package org.springframework.ai.chat.history; import java.util.List; import org.springframework.ai.chat.chatbot.ChatBotResponse; -import org.springframework.ai.chat.chatbot.ChatAgentListener; +import org.springframework.ai.chat.chatbot.ChatBotListener; import org.springframework.ai.chat.messages.Message; import org.springframework.ai.chat.messages.MessageType; import org.springframework.ai.chat.prompt.transformer.PromptContext; @@ -28,11 +28,11 @@ import org.springframework.ai.chat.prompt.transformer.TransformerContentType; /** * @author Christian Tzolov */ -public class ChatMemoryAgentListener implements ChatAgentListener { +public class ChatMemoryChatBotListener implements ChatBotListener { private final ChatMemory chatHistory; - public ChatMemoryAgentListener(ChatMemory chatHistory) { + public ChatMemoryChatBotListener(ChatMemory chatHistory) { this.chatHistory = chatHistory; } diff --git a/spring-ai-core/src/main/java/org/springframework/ai/chat/history/VectorStoreChatMemoryAgentListener.java b/spring-ai-core/src/main/java/org/springframework/ai/chat/history/VectorStoreChatMemoryChatBotListener.java similarity index 90% rename from spring-ai-core/src/main/java/org/springframework/ai/chat/history/VectorStoreChatMemoryAgentListener.java rename to spring-ai-core/src/main/java/org/springframework/ai/chat/history/VectorStoreChatMemoryChatBotListener.java index 72b32c9c5..cf42bfb6e 100644 --- a/spring-ai-core/src/main/java/org/springframework/ai/chat/history/VectorStoreChatMemoryAgentListener.java +++ b/spring-ai-core/src/main/java/org/springframework/ai/chat/history/VectorStoreChatMemoryChatBotListener.java @@ -20,8 +20,8 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import org.springframework.ai.chat.chatbot.ChatBotListener; import org.springframework.ai.chat.chatbot.ChatBotResponse; -import org.springframework.ai.chat.chatbot.ChatAgentListener; import org.springframework.ai.chat.messages.Message; import org.springframework.ai.chat.messages.MessageType; import org.springframework.ai.chat.prompt.transformer.TransformerContentType; @@ -33,17 +33,17 @@ import org.springframework.util.CollectionUtils; /** * @author Christian Tzolov */ -public class VectorStoreChatMemoryAgentListener implements ChatAgentListener { +public class VectorStoreChatMemoryChatBotListener implements ChatBotListener { private final VectorStore vectorStore; private final Map additionalMetadata; - public VectorStoreChatMemoryAgentListener(VectorStore vectorStore) { + public VectorStoreChatMemoryChatBotListener(VectorStore vectorStore) { this(vectorStore, new HashMap<>()); } - public VectorStoreChatMemoryAgentListener(VectorStore vectorStore, Map additionalMetadata) { + public VectorStoreChatMemoryChatBotListener(VectorStore vectorStore, Map additionalMetadata) { this.vectorStore = vectorStore; this.additionalMetadata = additionalMetadata; } diff --git a/spring-ai-core/src/test/java/org/springframework/ai/chat/history/ChatMemoryTests.java b/spring-ai-core/src/test/java/org/springframework/ai/chat/history/ChatMemoryTests.java index 38099408c..f1b2fca90 100644 --- a/spring-ai-core/src/test/java/org/springframework/ai/chat/history/ChatMemoryTests.java +++ b/spring-ai-core/src/test/java/org/springframework/ai/chat/history/ChatMemoryTests.java @@ -61,15 +61,15 @@ public class ChatMemoryTests { ChatMemory chatHistory = new InMemoryChatMemory(); - DefaultChatBot chatAgent = DefaultChatBot.builder(chatClient) + DefaultChatBot chatBot = DefaultChatBot.builder(chatClient) .withRetrievers(List.of(new ChatMemoryRetriever(chatHistory))) .withContentPostProcessors( List.of(new LastMaxTokenSizeContentTransformer(new JTokkitTokenCountEstimator(), 10))) .withAugmentors(List.of(new MessageChatMemoryAugmentor())) - .withChatAgentListeners(List.of(new ChatMemoryAgentListener(chatHistory))) + .withChatBotListeners(List.of(new ChatMemoryChatBotListener(chatHistory))) .build(); - chatClientUserMessages(chatAgent, chatHistory); + chatClientUserMessages(chatBot, chatHistory); } @Test @@ -77,18 +77,18 @@ public class ChatMemoryTests { ChatMemory chatHistory = new InMemoryChatMemory(); - DefaultChatBot chatAgent = DefaultChatBot.builder(chatClient) + DefaultChatBot chatBot = DefaultChatBot.builder(chatClient) .withRetrievers(List.of(new ChatMemoryRetriever(chatHistory))) .withContentPostProcessors( List.of(new LastMaxTokenSizeContentTransformer(new JTokkitTokenCountEstimator(), 10))) .withAugmentors(List.of(new SystemPromptChatMemoryAugmentor())) - .withChatAgentListeners(List.of(new ChatMemoryAgentListener(chatHistory))) + .withChatBotListeners(List.of(new ChatMemoryChatBotListener(chatHistory))) .build(); - chatClientUserMessages(chatAgent, chatHistory); + chatClientUserMessages(chatBot, chatHistory); } - public void chatClientUserMessages(DefaultChatBot chatAgent, ChatMemory chatHistory) { + public void chatClientUserMessages(DefaultChatBot chatBot, ChatMemory chatHistory) { when(chatClient.call(promptCaptor.capture())) .thenReturn(new ChatResponse(List.of(new Generation("assistant:1")))) @@ -102,7 +102,7 @@ public class ChatMemoryTests { new UserMessage("user:4"), new UserMessage("user:5")))) .build(); - ChatBotResponse response1 = chatAgent.call(promptContext); + ChatBotResponse response1 = chatBot.call(promptContext); assertThat(response1.getChatResponse().getResult().getOutput().getContent()).isEqualTo("assistant:1"); @@ -112,7 +112,7 @@ public class ChatMemoryTests { List history = chatHistory.get("test-session-id", 1000); assertThat(history).hasSize(6); - ChatBotResponse response2 = chatAgent.call(PromptContext.builder() + ChatBotResponse response2 = chatBot.call(PromptContext.builder() .withConversationId("test-session-id") .withPrompt(new Prompt( List.of(new UserMessage("user:6"), new UserMessage("user:7"), new UserMessage("user:8")))) @@ -129,7 +129,7 @@ public class ChatMemoryTests { assertThat(contents.get(1).getContent()).isEqualTo("user:5"); assertThat(contents.get(2).getContent()).isEqualTo("assistant:1"); - ChatBotResponse response3 = chatAgent.call(PromptContext.builder() + ChatBotResponse response3 = chatBot.call(PromptContext.builder() .withConversationId("test-session-id") .withPrompt(new Prompt(List.of(new UserMessage("user:9")))).build()); assertThat(response3.getChatResponse().getResult().getOutput().getContent()).isEqualTo("assistant:3"); diff --git a/spring-ai-test/src/main/java/org/springframework/ai/evaluation/BaseMemoryTest.java b/spring-ai-test/src/main/java/org/springframework/ai/evaluation/BaseMemoryTest.java index 133b2b002..8060ae23b 100644 --- a/spring-ai-test/src/main/java/org/springframework/ai/evaluation/BaseMemoryTest.java +++ b/spring-ai-test/src/main/java/org/springframework/ai/evaluation/BaseMemoryTest.java @@ -51,7 +51,7 @@ public class BaseMemoryTest { } @Test - void memoryChatAgent() { + void memoryChatBot() { var prompt = new Prompt(new UserMessage("my name John Vincent Atanasoff")); PromptContext promptContext = new PromptContext(prompt);