-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
system.ts
49 lines (44 loc) · 1018 Bytes
/
system.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
42
43
44
45
46
47
48
49
import {
BaseMessage,
BaseMessageChunk,
mergeContent,
_mergeDicts,
type MessageType,
} from "./base.js";
/**
* Represents a system message in a conversation.
*/
export class SystemMessage extends BaseMessage {
static lc_name() {
return "SystemMessage";
}
_getType(): MessageType {
return "system";
}
}
/**
* Represents a chunk of a system message, which can be concatenated with
* other system message chunks.
*/
export class SystemMessageChunk extends BaseMessageChunk {
static lc_name() {
return "SystemMessageChunk";
}
_getType(): MessageType {
return "system";
}
concat(chunk: SystemMessageChunk) {
return new SystemMessageChunk({
content: mergeContent(this.content, chunk.content),
additional_kwargs: _mergeDicts(
this.additional_kwargs,
chunk.additional_kwargs
),
response_metadata: _mergeDicts(
this.response_metadata,
chunk.response_metadata
),
id: this.id ?? chunk.id,
});
}
}