Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
* Memory is retrieved added as a collection of messages to the prompt
*
* @author Christian Tzolov
* @author Hyunsang Han
* @since 1.0.0
*/
public class MessageChatMemoryAdvisor extends AbstractChatMemoryAdvisor<ChatMemory> {
Expand Down Expand Up @@ -79,10 +80,8 @@ public Flux<ChatClientResponse> adviseStream(ChatClientRequest chatClientRequest
private ChatClientRequest before(ChatClientRequest chatClientRequest) {
String conversationId = this.doGetConversationId(chatClientRequest.context());

int chatMemoryRetrieveSize = this.doGetChatMemoryRetrieveSize(chatClientRequest.context());

// 1. Retrieve the chat memory for the current conversation.
List<Message> memoryMessages = this.getChatMemoryStore().get(conversationId, chatMemoryRetrieveSize);
List<Message> memoryMessages = this.getChatMemoryStore().get(conversationId);

// 2. Advise the request messages list.
List<Message> processedMessages = new ArrayList<>(memoryMessages);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@
* @author Christian Tzolov
* @author Miloš Havránek
* @author Thomas Vitale
* @author Hyunsang Han
* @since 1.0.0
*/
public class PromptChatMemoryAdvisor extends AbstractChatMemoryAdvisor<ChatMemory> {
Expand Down Expand Up @@ -112,10 +113,9 @@ public Flux<ChatClientResponse> adviseStream(ChatClientRequest chatClientRequest

private ChatClientRequest before(ChatClientRequest chatClientRequest) {
String conversationId = this.doGetConversationId(chatClientRequest.context());
int chatMemoryRetrieveSize = this.doGetChatMemoryRetrieveSize(chatClientRequest.context());

// 1. Retrieve the chat memory for the current conversation.
List<Message> memoryMessages = this.getChatMemoryStore().get(conversationId, chatMemoryRetrieveSize);
List<Message> memoryMessages = this.getChatMemoryStore().get(conversationId);

// 2. Processed memory messages as a string.
String memory = memoryMessages.stream()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
*
* @author Christian Tzolov
* @author Thomas Vitale
* @author Hyunsang Han
* @since 1.0.0
*/
public interface ChatMemory {
Expand All @@ -49,16 +50,7 @@ default void add(String conversationId, Message message) {
/**
* Get the messages in the chat memory for the specified conversation.
*/
default List<Message> get(String conversationId) {
Assert.hasText(conversationId, "conversationId cannot be null or empty");
return get(conversationId, Integer.MAX_VALUE);
}

/**
* @deprecated in favor of using {@link MessageWindowChatMemory}.
*/
@Deprecated
List<Message> get(String conversationId, int lastN);
List<Message> get(String conversationId);

/**
* Clear the chat memory for the specified conversation.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@
*
* @author Thomas Vitale
* @author Ilayaperumal Gopinathan
* @author Hyunsang Han
* @since 1.0.0
*/
public final class MessageWindowChatMemory implements ChatMemory {
Expand Down Expand Up @@ -71,12 +72,6 @@ public List<Message> get(String conversationId) {
return this.chatMemoryRepository.findByConversationId(conversationId);
}

@Override
@Deprecated // in favor of get(conversationId)
public List<Message> get(String conversationId, int lastN) {
return get(conversationId);
}

@Override
public void clear(String conversationId) {
Assert.hasText(conversationId, "conversationId cannot be null or empty");
Expand Down