-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from upstash/DX-1003
feat: allow offsetting chat history
- Loading branch information
Showing
7 changed files
with
103 additions
and
13 deletions.
There are no files selected for viewing
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
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
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
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,30 @@ | ||
import { Redis } from "@upstash/redis"; | ||
import { afterAll, describe, expect, test } from "bun:test"; | ||
import { CustomUpstashRedisChatMessageHistory } from "./redis-custom-history"; | ||
|
||
describe("Redis chat-history", () => { | ||
const redis = Redis.fromEnv(); | ||
afterAll(async () => { | ||
await redis.flushdb(); | ||
}); | ||
|
||
test("should give last 3 messages from redis", async () => { | ||
const history = new CustomUpstashRedisChatMessageHistory({ | ||
client: redis, | ||
metadata: { helloWorld: "hey" }, | ||
sessionId: "testing-features", | ||
}); | ||
await history.addUserMessage("Hello!"); | ||
await history.addAIMessage("Hello, human."); | ||
await history.addUserMessage("Whats your name?"); | ||
await history.addAIMessage("Upstash"); | ||
await history.addUserMessage("Good. How are you?"); | ||
await history.addAIMessage("I'm good. Thanks."); | ||
|
||
// eslint-disable-next-line unicorn/no-await-expression-member | ||
const final = (await history.getMessages({ offset: 0, length: 2 })).map( | ||
(message) => message.content as string | ||
); | ||
expect(["Upstash", "Good. How are you?", "I'm good. Thanks."]).toEqual(final); | ||
}); | ||
}); |
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
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
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