Remove deprecations/cleanup
- Remove deprecated AbstractChatMemoryAdvisor#DEFAULT_CHAT_MEMORY_CONVERSATION_ID - Remove deprecated InMemoryChatMemory and replace it with MessageWindowChatMemory - Update references - Remove deprecated TemplateFormat Signed-off-by: Ilayaperumal Gopinathan <ilayaperumal.gopinathan@broadcom.com>
This commit is contained in:
@@ -53,13 +53,6 @@ public abstract class AbstractChatMemoryAdvisor<T> implements CallAdvisor, Strea
|
||||
*/
|
||||
public static final String CHAT_MEMORY_RETRIEVE_SIZE_KEY = "chat_memory_response_size";
|
||||
|
||||
/**
|
||||
* The default conversation id to use when no conversation id is provided.
|
||||
* @deprecated in favor of {@link ChatMemory#DEFAULT_CONVERSATION_ID}.
|
||||
*/
|
||||
@Deprecated
|
||||
public static final String DEFAULT_CHAT_MEMORY_CONVERSATION_ID = "default";
|
||||
|
||||
/**
|
||||
* The default chat memory retrieve size to use when no retrieve size is provided.
|
||||
*/
|
||||
|
||||
@@ -1,62 +0,0 @@
|
||||
/*
|
||||
* Copyright 2023-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.ai.chat.memory;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
||||
import org.springframework.ai.chat.messages.Message;
|
||||
|
||||
/**
|
||||
* The InMemoryChatMemory class is an implementation of the ChatMemory interface that
|
||||
* represents an in-memory storage for chat conversation history.
|
||||
*
|
||||
* This class stores the conversation history in a ConcurrentHashMap, where the keys are
|
||||
* the conversation IDs and the values are lists of messages representing the conversation
|
||||
* history.
|
||||
*
|
||||
* @see ChatMemory
|
||||
* @author Christian Tzolov
|
||||
* @since 1.0.0 M1
|
||||
* @deprecated in favor of {@link MessageWindowChatMemory}, which internally uses
|
||||
* {@link InMemoryChatMemoryRepository}.
|
||||
*/
|
||||
@Deprecated
|
||||
public class InMemoryChatMemory implements ChatMemory {
|
||||
|
||||
Map<String, List<Message>> conversationHistory = new ConcurrentHashMap<>();
|
||||
|
||||
@Override
|
||||
public void add(String conversationId, List<Message> messages) {
|
||||
this.conversationHistory.putIfAbsent(conversationId, new ArrayList<>());
|
||||
this.conversationHistory.get(conversationId).addAll(messages);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<Message> get(String conversationId, int lastN) {
|
||||
List<Message> all = this.conversationHistory.get(conversationId);
|
||||
return all != null ? all.stream().skip(Math.max(0, all.size() - lastN)).toList() : List.of();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void clear(String conversationId) {
|
||||
this.conversationHistory.remove(conversationId);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -29,7 +29,8 @@ import reactor.core.publisher.Flux;
|
||||
|
||||
import org.springframework.ai.chat.client.advisor.PromptChatMemoryAdvisor;
|
||||
import org.springframework.ai.chat.memory.ChatMemory;
|
||||
import org.springframework.ai.chat.memory.InMemoryChatMemory;
|
||||
import org.springframework.ai.chat.memory.InMemoryChatMemoryRepository;
|
||||
import org.springframework.ai.chat.memory.MessageWindowChatMemory;
|
||||
import org.springframework.ai.chat.messages.AssistantMessage;
|
||||
import org.springframework.ai.chat.messages.Message;
|
||||
import org.springframework.ai.chat.messages.MessageType;
|
||||
@@ -76,8 +77,10 @@ public class ChatClientAdvisorTests {
|
||||
.willReturn(new ChatResponse(List.of(new Generation(new AssistantMessage("Your name is John"))),
|
||||
chatResponseMetadata));
|
||||
|
||||
// Initialize an in-memory chat memory to store conversation history
|
||||
ChatMemory chatMemory = new InMemoryChatMemory();
|
||||
// Initialize a message window chat memory to store conversation history
|
||||
ChatMemory chatMemory = MessageWindowChatMemory.builder()
|
||||
.chatMemoryRepository(new InMemoryChatMemoryRepository())
|
||||
.build();
|
||||
|
||||
// Build a ChatClient with default system text and a memory advisor
|
||||
var chatClient = ChatClient.builder(this.chatModel)
|
||||
@@ -153,8 +156,10 @@ public class ChatClientAdvisorTests {
|
||||
return state;
|
||||
}));
|
||||
|
||||
// Initialize an in-memory chat memory to store conversation history
|
||||
ChatMemory chatMemory = new InMemoryChatMemory();
|
||||
// Initialize a message window chat memory to store conversation history
|
||||
ChatMemory chatMemory = MessageWindowChatMemory.builder()
|
||||
.chatMemoryRepository(new InMemoryChatMemoryRepository())
|
||||
.build();
|
||||
|
||||
// Build a ChatClient with default system text and a memory advisor
|
||||
var chatClient = ChatClient.builder(this.chatModel)
|
||||
|
||||
@@ -534,7 +534,7 @@ IMPORTANT: Refer to the new xref:api/chat-memory.adoc[Chat Memory] documentation
|
||||
|
||||
The interface `ChatMemory` represents a storage for chat conversation history. It provides methods to add messages to a conversation, retrieve messages from a conversation, and clear the conversation history.
|
||||
|
||||
There are currently four implementations: `InMemoryChatMemory`, `CassandraChatMemory`, `Neo4jChatMemory`, and `JdbcChatMemory`, which provide storage for chat conversation history in-memory, persisted with `time-to-live` in Cassandra, and persisted without `time-to-live` in Neo4j and Jdbc, respectively.
|
||||
There are currently four implementations: `CassandraChatMemory`, `Neo4jChatMemory`, and `JdbcChatMemory`, which provide storage for chat conversation history in-memory, persisted with `time-to-live` in Cassandra, and persisted without `time-to-live` in Neo4j and Jdbc, respectively.
|
||||
|
||||
=== CassandraChatMemory
|
||||
|
||||
|
||||
@@ -26,13 +26,13 @@ import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
|
||||
import org.springframework.ai.chat.client.ChatClient;
|
||||
import org.springframework.ai.chat.client.advisor.AbstractChatMemoryAdvisor;
|
||||
import org.springframework.ai.chat.client.advisor.MessageChatMemoryAdvisor;
|
||||
import org.springframework.ai.chat.memory.InMemoryChatMemory;
|
||||
import org.springframework.ai.chat.evaluation.RelevancyEvaluator;
|
||||
import org.springframework.ai.chat.memory.MessageWindowChatMemory;
|
||||
import org.springframework.ai.chat.model.ChatResponse;
|
||||
import org.springframework.ai.document.Document;
|
||||
import org.springframework.ai.document.DocumentReader;
|
||||
import org.springframework.ai.evaluation.EvaluationRequest;
|
||||
import org.springframework.ai.evaluation.EvaluationResponse;
|
||||
import org.springframework.ai.chat.evaluation.RelevancyEvaluator;
|
||||
import org.springframework.ai.integration.tests.TestApplication;
|
||||
import org.springframework.ai.openai.OpenAiChatModel;
|
||||
import org.springframework.ai.rag.advisor.RetrievalAugmentationAdvisor;
|
||||
@@ -133,7 +133,9 @@ class RetrievalAugmentationAdvisorIT {
|
||||
|
||||
@Test
|
||||
void ragWithCompression() {
|
||||
MessageChatMemoryAdvisor memoryAdvisor = MessageChatMemoryAdvisor.builder(new InMemoryChatMemory()).build();
|
||||
MessageChatMemoryAdvisor memoryAdvisor = MessageChatMemoryAdvisor
|
||||
.builder(MessageWindowChatMemory.builder().build())
|
||||
.build();
|
||||
|
||||
RetrievalAugmentationAdvisor ragAdvisor = RetrievalAugmentationAdvisor.builder()
|
||||
.queryTransformers(CompressionQueryTransformer.builder()
|
||||
|
||||
@@ -1,48 +0,0 @@
|
||||
/*
|
||||
* Copyright 2023-2025 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.ai.chat.prompt;
|
||||
|
||||
import org.springframework.ai.template.TemplateRenderer;
|
||||
|
||||
/**
|
||||
* @deprecated in favor of {@link TemplateRenderer}.
|
||||
*/
|
||||
@Deprecated
|
||||
public enum TemplateFormat {
|
||||
|
||||
ST("ST");
|
||||
|
||||
private final String value;
|
||||
|
||||
TemplateFormat(String value) {
|
||||
this.value = value;
|
||||
}
|
||||
|
||||
public static TemplateFormat fromValue(String value) {
|
||||
for (TemplateFormat templateFormat : TemplateFormat.values()) {
|
||||
if (templateFormat.getValue().equals(value)) {
|
||||
return templateFormat;
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException("Invalid TemplateFormat value: " + value);
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return this.value;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user