This commit is contained in:
30
docs/snippets/r/plugins/plugin_logging.md
Normal file
30
docs/snippets/r/plugins/plugin_logging.md
Normal file
@@ -0,0 +1,30 @@
|
||||
<!-- snippet:syntax-only -->
|
||||
|
||||
```r title="R"
|
||||
library(kreuzberg)
|
||||
|
||||
logging_processor <- function(result) {
|
||||
message(sprintf(
|
||||
"[plugin] processing mime=%s content_chars=%d",
|
||||
result$mime_type %||% "unknown", nchar(result$content)
|
||||
))
|
||||
return(result)
|
||||
}
|
||||
|
||||
logging_validator <- function(result) {
|
||||
message(sprintf(
|
||||
"[plugin] validating mime=%s",
|
||||
result$mime_type %||% "unknown"
|
||||
))
|
||||
return(list(valid = TRUE, message = "ok"))
|
||||
}
|
||||
|
||||
register_post_processor("logging_processor", logging_processor)
|
||||
register_validator("logging_validator", logging_validator)
|
||||
|
||||
config <- list(postprocessor = list(enabled = TRUE))
|
||||
json <- extract_file_sync("document.pdf", "application/pdf", config)
|
||||
result <- jsonlite::fromJSON(json, simplifyVector = FALSE)
|
||||
|
||||
cat(sprintf("Done: %d characters\n", nchar(result$content)))
|
||||
```
|
||||
Reference in New Issue
Block a user