Skip to content

Commit 4860fc8

Browse files
committed
Add a method to access typed metadata keys
1 parent b0605ba commit 4860fc8

1 file changed

Lines changed: 5 additions & 0 deletions

File tree

Tool/Sources/LangChain/DocumentLoader/DocumentLoader.swift

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,11 @@ public struct Document: Codable {
99
self.pageContent = pageContent
1010
self.metadata = metadata
1111
}
12+
13+
public func metadata<Key>(_ keyPath: KeyPath<Key.Type, String>) -> JSONValue? {
14+
let key = Key.self[keyPath: keyPath]
15+
return metadata[key]
16+
}
1217
}
1318

1419
public protocol DocumentLoader {

0 commit comments

Comments
 (0)