-
Notifications
You must be signed in to change notification settings - Fork 56
Expand file tree
/
Copy pathlogger.test.ts
More file actions
64 lines (60 loc) · 1.8 KB
/
logger.test.ts
File metadata and controls
64 lines (60 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import { describe, expect, setSystemTime, test } from "bun:test";
import { ChatLogger } from "./logger";
describe("LOGGER", () => {
test("should return all the logs", async () => {
const date = new Date("1999-01-01T00:00:00.000Z");
setSystemTime(date); // it's now January 1, 1999
// Example usage:
const logger = new ChatLogger({
logLevel: "DEBUG",
logOutput: "console",
});
await logger.logSendPrompt("What is the weather today?");
await logger.endRetrieveHistory(["Hello, how are you?", "I'm good, thank you!"]);
await logger.endRetrieveContext({ relevantData: "Sample context from vector DB" });
// eslint-disable-next-line @typescript-eslint/no-magic-numbers
await logger.endLLMResponse({ response: "The weather today is sunny." });
expect(logger.getLogs()).toEqual([
{
timestamp: Date.now(),
logLevel: "INFO",
eventType: "SEND_PROMPT",
details: {
prompt: "What is the weather today?",
},
latency: undefined,
},
{
timestamp: Date.now(),
logLevel: "INFO",
eventType: "RETRIEVE_HISTORY",
details: {
history: ["Hello, how are you?", "I'm good, thank you!"],
},
latency: undefined,
},
{
timestamp: Date.now(),
logLevel: "INFO",
eventType: "RETRIEVE_CONTEXT",
details: {
context: {
relevantData: "Sample context from vector DB",
},
},
latency: undefined,
},
{
timestamp: Date.now(),
logLevel: "INFO",
eventType: "LLM_RESPONSE",
details: {
response: {
response: "The weather today is sunny.",
},
},
},
]);
setSystemTime(); // reset to actual time
});
});