-
Notifications
You must be signed in to change notification settings - Fork 2.2k
/
document.ts
37 lines (31 loc) · 943 Bytes
/
document.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
export interface DocumentInput<
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Metadata extends Record<string, any> = Record<string, any>
> {
pageContent: string;
metadata?: Metadata;
}
export interface DocumentInterface<
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Metadata extends Record<string, any> = Record<string, any>
> {
pageContent: string;
metadata: Metadata;
}
/**
* Interface for interacting with a document.
*/
export class Document<
// eslint-disable-next-line @typescript-eslint/no-explicit-any
Metadata extends Record<string, any> = Record<string, any>
> implements DocumentInput, DocumentInterface
{
pageContent: string;
metadata: Metadata;
constructor(fields: DocumentInput<Metadata>) {
this.pageContent = fields.pageContent
? fields.pageContent.toString()
: this.pageContent;
this.metadata = fields.metadata ?? ({} as Metadata);
}
}