This commit is contained in:
33
docs/snippets/swift/llm/structured_extraction.md
Normal file
33
docs/snippets/swift/llm/structured_extraction.md
Normal file
@@ -0,0 +1,33 @@
|
||||
```swift title="Swift"
|
||||
import Foundation
|
||||
import Kreuzberg
|
||||
import RustBridge
|
||||
|
||||
let configJson = """
|
||||
{
|
||||
"structured_extraction": {
|
||||
"schema": {
|
||||
"type": "object",
|
||||
"properties": {
|
||||
"title": { "type": "string" },
|
||||
"authors": { "type": "array", "items": { "type": "string" } },
|
||||
"date": { "type": "string" }
|
||||
},
|
||||
"required": ["title", "authors", "date"],
|
||||
"additionalProperties": false
|
||||
},
|
||||
"llm": {
|
||||
"model": "openai/gpt-4o-mini"
|
||||
},
|
||||
"strict": true
|
||||
}
|
||||
}
|
||||
"""
|
||||
|
||||
let config = try extractionConfigFromJson(configJson)
|
||||
let result = try extractFileSync("paper.pdf", nil, config)
|
||||
|
||||
if let structured = result.structured_output() {
|
||||
print(structured.toString())
|
||||
}
|
||||
```
|
||||
Reference in New Issue
Block a user