-
Notifications
You must be signed in to change notification settings - Fork 2k
/
human.ts
48 lines (43 loc) 路 976 Bytes
/
human.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
import {
BaseMessage,
BaseMessageChunk,
mergeContent,
_mergeDicts,
type MessageType,
} from "./base.js";
/**
* Represents a human message in a conversation.
*/
export class HumanMessage extends BaseMessage {
static lc_name() {
return "HumanMessage";
}
_getType(): MessageType {
return "human";
}
}
/**
* Represents a chunk of a human message, which can be concatenated with
* other human message chunks.
*/
export class HumanMessageChunk extends BaseMessageChunk {
static lc_name() {
return "HumanMessageChunk";
}
_getType(): MessageType {
return "human";
}
concat(chunk: HumanMessageChunk) {
return new HumanMessageChunk({
content: mergeContent(this.content, chunk.content),
additional_kwargs: _mergeDicts(
this.additional_kwargs,
chunk.additional_kwargs
),
response_metadata: _mergeDicts(
this.response_metadata,
chunk.response_metadata
),
});
}
}