Skip to content

Commit

Permalink
feat(redis): dont add chat messages
Browse files Browse the repository at this point in the history
  • Loading branch information
glauberbrack committed Dec 5, 2024
1 parent ba8a462 commit d54fe31
Showing 1 changed file with 19 additions and 19 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -158,25 +158,25 @@ class BufferMemoryExtended extends FlowiseMemory implements MemoryMethods {
}

async addChatMessages(msgArray: { text: string; type: MessageType }[], overrideSessionId = ''): Promise<void> {
await this.withRedisClient(async (client) => {
const id = overrideSessionId ? overrideSessionId : this.sessionId
const input = msgArray.find((msg) => msg.type === 'userMessage')
const output = msgArray.find((msg) => msg.type === 'apiMessage')

if (input) {
const newInputMessage = new HumanMessage(input.text)
const messageToAdd = [newInputMessage].map((msg) => msg.toDict())
await client.lpush(id, JSON.stringify(messageToAdd[0]))
if (this.sessionTTL) await client.expire(id, this.sessionTTL)
}

if (output) {
const newOutputMessage = new AIMessage(output.text)
const messageToAdd = [newOutputMessage].map((msg) => msg.toDict())
await client.lpush(id, JSON.stringify(messageToAdd[0]))
if (this.sessionTTL) await client.expire(id, this.sessionTTL)
}
})
// await this.withRedisClient(async (client) => {
// const id = overrideSessionId ? overrideSessionId : this.sessionId
// const input = msgArray.find((msg) => msg.type === 'userMessage')
// const output = msgArray.find((msg) => msg.type === 'apiMessage')

// if (input) {
// const newInputMessage = new HumanMessage(input.text)
// const messageToAdd = [newInputMessage].map((msg) => msg.toDict())
// await client.lpush(id, JSON.stringify(messageToAdd[0]))
// if (this.sessionTTL) await client.expire(id, this.sessionTTL)
// }

// if (output) {
// const newOutputMessage = new AIMessage(output.text)
// const messageToAdd = [newOutputMessage].map((msg) => msg.toDict())
// await client.lpush(id, JSON.stringify(messageToAdd[0]))
// if (this.sessionTTL) await client.expire(id, this.sessionTTL)
// }
// })
}

async clearChatMessages(overrideSessionId = ''): Promise<void> {
Expand Down

0 comments on commit d54fe31

Please sign in to comment.