forked from HamaWhiteGG/langchain-java
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
24be2ec
commit 3f510a9
Showing
2 changed files
with
45 additions
and
1 deletion.
There are no files selected for viewing
43 changes: 43 additions & 0 deletions
43
...om/hw/langchain/memory/chat/message/histories/database/redis/RedisChatMessageHistory.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
3 changes: 2 additions & 1 deletion
3
.../database/RedisChatMessageRepository.java → ...ase/redis/RedisChatMessageRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters