Skip to content

Commit

Permalink
add redisChatMessageHistory
Browse files Browse the repository at this point in the history
  • Loading branch information
zhangxiaojiawow committed Jul 21, 2023
1 parent 24be2ec commit 3f510a9
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package com.hw.langchain.memory.chat.message.histories.database.redis;

import com.hw.langchain.memory.chat.message.histories.database.DataBaseChatMessageHistory;
import com.hw.langchain.schema.BaseChatMessageHistory;
import com.hw.langchain.schema.BaseMessage;
import java.util.List;
import org.redisson.api.RedissonClient;

/**
* a simple wrapper for DataBaseChatMessageHistory with redisChatMessageRepository;
*
* @author zhangxiaojia002
* @date 2023/7/21 10:49 上午
**/
public class RedisChatMessageHistory extends BaseChatMessageHistory {

private DataBaseChatMessageHistory dataBaseChatMessageHistory;

public RedisChatMessageHistory(String sessionId, RedissonClient redissonClient, int ttl) {
RedisChatMessageRepository redisChatMessageRepository = new RedisChatMessageRepository(redissonClient, ttl);
dataBaseChatMessageHistory = new DataBaseChatMessageHistory(sessionId, redisChatMessageRepository);
}

public RedisChatMessageHistory(String sessionId, RedissonClient redissonClient) {
RedisChatMessageRepository redisChatMessageRepository = new RedisChatMessageRepository(redissonClient);
dataBaseChatMessageHistory = new DataBaseChatMessageHistory(sessionId, redisChatMessageRepository);
}

@Override
public void addMessage(BaseMessage message) {
dataBaseChatMessageHistory.addMessage(message);
}

@Override
public void clear() {
dataBaseChatMessageHistory.clear();
}

@Override
public List<BaseMessage> getMessages() {
return dataBaseChatMessageHistory.getMessages();
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package com.hw.langchain.memory.chat.message.histories.database;
package com.hw.langchain.memory.chat.message.histories.database.redis;

import com.fasterxml.jackson.core.type.TypeReference;
import com.hw.langchain.chains.query.constructor.JsonUtils;
import com.hw.langchain.memory.chat.message.histories.database.ChatMessageRepository;
import com.hw.langchain.schema.BaseMessage;
import java.time.Duration;
import java.time.temporal.ChronoUnit;
Expand Down

0 comments on commit 3f510a9

Please sign in to comment.