sema-unstructured 0.1.0

Extract structured document elements from PDFs, images, and Office files via the Unstructured.io API

API reference 4 exports

Exported declarations from this release. Parameter names and descriptions come directly from its source.

unstructured/client

Source :48
(unstructured/client . opts)
Build an Unstructured client map. Options: :api-key (default: UNSTRUCTURED_API_KEY env var), :base-url (default "https://api.unstructuredapp.io"), :timeout in ms (default 120000). Errors if no API key is found.
View source definition
(define (unstructured/client . opts)
  "Build an Unstructured client map. Options: :api-key (default: UNSTRUCTURED_API_KEY env var), :base-url (default \"https://api.unstructuredapp.io\"), :timeout in ms (default 120000). Errors if no API key is found."
  (let* ((o (if (null? opts) {} (first opts)))
         (api-key (or (get o :api-key) (env "UNSTRUCTURED_API_KEY"))))
    (when (nil? api-key)
      (error "unstructured: no API key — pass {:api-key \"...\"} or set the UNSTRUCTURED_API_KEY environment variable"))
    {:api-key api-key
     :base-url (string/chop-end (get o :base-url "https://api.unstructuredapp.io") "/")
     :timeout (get o :timeout 120000)}))

unstructured/partition

Source :138
(unstructured/partition client source . opts)
Partition a document into element maps via POST /general/v0/general. source is either a file path string or a {:bytes <bytevector> :filename "name.ext"} map (bytes are uploaded verbatim). Options map: :strategy (e.g. "auto", "hi_res", "fast", "ocr_only", "vlm"; omitted → API default), :chunking-strategy (e.g. "by_title", "basic"; omitted → no chunking), :params (map of any other form fields, keyword or string keys, e.g. {:languages "eng" :coordinates #t}). Returns a list of element maps ({:type .. :element_id .. :text .. :metadata ..}).
View source definition
(define (unstructured/partition client source . opts)
  "Partition a document into element maps via POST /general/v0/general. source is either a file path string or a {:bytes <bytevector> :filename \"name.ext\"} map (bytes are uploaded verbatim). Options map: :strategy (e.g. \"auto\", \"hi_res\", \"fast\", \"ocr_only\", \"vlm\"; omitted → API default), :chunking-strategy (e.g. \"by_title\", \"basic\"; omitted → no chunking), :params (map of any other form fields, keyword or string keys, e.g. {:languages \"eng\" :coordinates #t}). Returns a list of element maps ({:type .. :element_id .. :text .. :metadata ..})."
  (let* ((o (if (null? opts) {} (first opts)))
         (resolved (resolve-source source))
         (parts (partition-parts resolved o)))
    (unstructured/request client "POST" "/general/v0/general" {:multipart parts})))

unstructured/request

Source :88
(unstructured/request client method path opts)
Make a raw Unstructured API request; the escape hatch every wrapper uses. method is "GET"/"POST"/..., path an API path ("/general/v0/general") or full URL. opts is a map: :multipart (list of {:name .. :content <string|bytevector> :filename ..?} parts) for form uploads, :body (map → JSON body) otherwise. Returns the decoded JSON body (nil when empty); raises on non-2xx with method, path, status, and the API message.
View source definition
(define (unstructured/request client method path opts)
  "Make a raw Unstructured API request; the escape hatch every wrapper uses. method is \"GET\"/\"POST\"/..., path an API path (\"/general/v0/general\") or full URL. opts is a map: :multipart (list of {:name .. :content <string|bytevector> :filename ..?} parts) for form uploads, :body (map → JSON body) otherwise. Returns the decoded JSON body (nil when empty); raises on non-2xx with method, path, status, and the API message."
  (let* ((url (build-url client path))
         (multipart (get opts :multipart))
         (base-opts {:headers (client-headers client) :timeout (:timeout client)})
         (req-opts (if (nil? multipart) base-opts (assoc base-opts :multipart multipart)))
         (body (get opts :body))
         (resp (if (nil? body)
                 (http/request method url req-opts)
                 (http/request method url req-opts body)))
         (status (:status resp)))
    (if (and (>= status 200) (< status 300))
      (decode-body (:body resp))
      (error (format "unstructured: ~a ~a → ~a: ~a"
                     method path status (api-error-message (:body resp)))))))

unstructured/text-of

Source :149
(unstructured/text-of elements)
Join the :text of a partition element list into a single newline-separated string. Elements missing :text contribute nothing. Accepts nil or an empty list (→ "").
View source definition
(define (unstructured/text-of elements)
  "Join the :text of a partition element list into a single newline-separated string. Elements missing :text contribute nothing. Accepts nil or an empty list (→ \"\")."
  (if (or (nil? elements) (empty? elements))
    ""
    (string/join
      (filter (fn (s) (not (string/empty? s)))
              (map (fn (el) (or (and (map? el) (get el :text)) "")) elements))
      "\n"))))
About this reference

Generated with sema-reader 1.37.0 without executing package code. These are source declarations; dynamic exports, aliases, and runtime changes are not inferred.

Archive SHA-256 edec2c43759bb1ad13f5622f727d05740387850cf5a99b5bf4151397793e30b7