From d917f94767aeb675d90ac5d51d2d283cf9c8d251 Mon Sep 17 00:00:00 2001 From: ogzhanolguncu Date: Thu, 23 May 2024 15:25:28 +0300 Subject: [PATCH] test: add test for in-memory db --- src/rag-chat.test.ts | 48 ++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 48 insertions(+) diff --git a/src/rag-chat.test.ts b/src/rag-chat.test.ts index 5459068..c127a46 100644 --- a/src/rag-chat.test.ts +++ b/src/rag-chat.test.ts @@ -204,3 +204,51 @@ describe("RAG Chat addContext using PDF", () => { { timeout: 30_000 } ); }); + +describe("RAG Chat without Redis, but In-memory chat history", () => { + const vector = new Index({ + token: process.env.UPSTASH_VECTOR_REST_TOKEN!, + url: process.env.UPSTASH_VECTOR_REST_URL!, + }); + + const ragChat = new RAGChat({ + model: new ChatOpenAI({ + modelName: "gpt-3.5-turbo", + streaming: false, + verbose: false, + temperature: 0, + apiKey: process.env.OPENAI_API_KEY, + }), + vector, + }); + + afterAll(async () => { + await vector.reset(); + }); + + test( + "should reply back using in-memory db", + async () => { + await ragChat.addContext({ data: "Ankara is the capital of Turkiye.", dataType: "text" }); + await awaitUntilIndexed(vector); + + await ragChat.chat("Hello, my name is Oz!", { + stream: false, + sessionId: "find-name", + historyLength: 5, + }); + await ragChat.chat("How are you?", { + stream: false, + sessionId: "find-name", + historyLength: 5, + }); + const result = await ragChat.chat("Do you remember my name?", { + stream: false, + sessionId: "find-name", + historyLength: 5, + }); + expect((result as AIMessage).content).toInclude("Oz"); + }, + { timeout: 10_000 } + ); +});