Class: ReductoAI::Resources::Extract
- Inherits:
-
Object
- Object
- ReductoAI::Resources::Extract
- Defined in:
- lib/reducto_ai/resources/extract.rb
Overview
Extraction operations consume credits based on document complexity and schema size.
Extract resource for structured data extraction.
Extracts specific information from documents based on a schema or instructions. Returns structured JSON data matching the provided schema.
Instance Method Summary collapse
-
#async(input:, instructions:, async: nil, **options) ⇒ Hash
Extracts structured data from a document asynchronously.
-
#initialize(client) ⇒ Extract
constructor
private
A new instance of Extract.
-
#sync(input:, instructions:, **options) ⇒ Hash
Extracts structured data from a document synchronously.
Constructor Details
#initialize(client) ⇒ Extract
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Returns a new instance of Extract.
29 30 31 |
# File 'lib/reducto_ai/resources/extract.rb', line 29 def initialize(client) @client = client end |
Instance Method Details
#async(input:, instructions:, async: nil, **options) ⇒ Hash
Extracts structured data from a document asynchronously.
Returns immediately with a job_id. Poll with Jobs#retrieve to get results.
95 96 97 98 99 100 101 102 103 104 105 |
# File 'lib/reducto_ai/resources/extract.rb', line 95 def async(input:, instructions:, async: nil, **) raise ArgumentError, "input is required" if input.nil? if instructions.nil? || (instructions.respond_to?(:empty?) && instructions.empty?) raise ArgumentError, "instructions are required" end payload = build_payload(input, instructions, ) payload[:async] = async unless async.nil? @client.post("/extract_async", payload) end |
#sync(input:, instructions:, **options) ⇒ Hash
Extracts structured data from a document synchronously.
61 62 63 64 65 66 67 68 69 |
# File 'lib/reducto_ai/resources/extract.rb', line 61 def sync(input:, instructions:, **) raise ArgumentError, "input is required" if input.nil? if instructions.nil? || (instructions.respond_to?(:empty?) && instructions.empty?) raise ArgumentError, "instructions are required" end payload = build_payload(input, instructions, ) @client.post("/extract", payload) end |