This commit is contained in:
30
docs/snippets/zig/llm/structured_extraction.md
Normal file
30
docs/snippets/zig/llm/structured_extraction.md
Normal file
@@ -0,0 +1,30 @@
|
||||
<!-- snippet:syntax-only -->
|
||||
|
||||
```zig title="Zig"
|
||||
const std = @import("std");
|
||||
const kreuzberg = @import("kreuzberg");
|
||||
|
||||
// Structured extraction is configured via the JSON `structured_extraction`
|
||||
// field on `ExtractionConfig`. The schema is a JSON Schema string and
|
||||
// `llm.model` selects the provider via liter-llm.
|
||||
pub fn main() !void {
|
||||
const config_json =
|
||||
\\{
|
||||
\\ "structured_extraction": {
|
||||
\\ "schema": "{\"type\":\"object\",\"properties\":{\"title\":{\"type\":\"string\"},\"authors\":{\"type\":\"array\",\"items\":{\"type\":\"string\"}},\"date\":{\"type\":\"string\"}},\"required\":[\"title\",\"authors\",\"date\"],\"additionalProperties\":false}",
|
||||
\\ "schema_name": "Paper",
|
||||
\\ "strict": true,
|
||||
\\ "llm": {
|
||||
\\ "model": "openai/gpt-4o-mini"
|
||||
\\ }
|
||||
\\ }
|
||||
\\}
|
||||
;
|
||||
|
||||
const result_json = try kreuzberg.extract_file_sync("paper.pdf", null, config_json);
|
||||
defer std.heap.c_allocator.free(result_json);
|
||||
|
||||
const stdout = std.io.getStdOut().writer();
|
||||
try stdout.print("{s}\n", .{result_json});
|
||||
}
|
||||
```
|
||||
Reference in New Issue
Block a user