-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
chat_history.ts
41 lines (31 loc) · 1.3 KB
/
chat_history.ts
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
import { Serializable } from "./load/serializable.js";
import { type BaseMessage, HumanMessage, AIMessage } from "./messages/index.js";
/**
* Base class for all chat message histories. All chat message histories
* should extend this class.
*/
export abstract class BaseChatMessageHistory extends Serializable {
public abstract getMessages(): Promise<BaseMessage[]>;
public abstract addMessage(message: BaseMessage): Promise<void>;
public abstract addUserMessage(message: string): Promise<void>;
public abstract addAIChatMessage(message: string): Promise<void>;
public abstract clear(): Promise<void>;
}
/**
* Base class for all list chat message histories. All list chat message
* histories should extend this class.
*/
export abstract class BaseListChatMessageHistory extends Serializable {
public abstract addMessage(message: BaseMessage): Promise<void>;
public addUserMessage(message: string): Promise<void> {
return this.addMessage(new HumanMessage(message));
}
/** @deprecated Use addAIMessage instead */
public addAIChatMessage(message: string): Promise<void> {
return this.addMessage(new AIMessage(message));
}
public addAIMessage(message: string): Promise<void> {
return this.addMessage(new AIMessage(message));
}
public abstract getMessages(): Promise<BaseMessage[]>;
}