Class: ReductoAI::Resources::Split

Inherits:
Object
  • Object
show all
Defined in:
lib/reducto_ai/resources/split.rb

Overview

Note:

Split operations consume credits based on document size.

Split resource for document splitting operations.

Divides documents into logical sections based on content structure, returning page ranges and metadata for each section.

Examples:

Split document into sections

client = ReductoAI::Client.new
result = client.split.sync(
  input: "https://example.com/report.pdf"
)
result["result"]["sections"].each do |section|
  puts "#{section['title']}: pages #{section['start_page']}-#{section['end_page']}"
end

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Split

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 Split.

Parameters:

  • client (Client)

    the Reducto API client



23
24
25
# File 'lib/reducto_ai/resources/split.rb', line 23

def initialize(client)
  @client = client
end

Instance Method Details

#async(input:, async: nil, **options) ⇒ Hash

Splits a document into sections asynchronously.

Returns immediately with a job_id. Poll with Jobs#retrieve to get results.

Examples:

job = client.split.async(
  input: "https://example.com/book.pdf"
)
job_id = job["job_id"]

Parameters:

  • input (String, Hash)

    Document URL or hash with :url key

  • async (Boolean, nil) (defaults to: nil)

    Async mode flag

  • options (Hash)

    Additional splitting options

Returns:

  • (Hash)

    Job status with keys:

    • "job_id" [String] - Job identifier for polling
    • "status" [String] - Initial status ("processing")

Raises:

  • (ArgumentError)

    if input is nil

See Also:



78
79
80
81
82
83
84
85
86
87
# File 'lib/reducto_ai/resources/split.rb', line 78

def async(input:, async: nil, **options)
  raise ArgumentError, "input is required" if input.nil?

  normalized_input = normalize_input(input)
  payload = { input: normalized_input }
  payload[:async] = async unless async.nil?
  payload.merge!(options.compact)

  @client.post("/split_async", payload)
end

#sync(input:, **options) ⇒ Hash

Splits a document into sections synchronously.

Examples:

result = client.split.sync(
  input: "https://example.com/document.pdf"
)

Parameters:

  • input (String, Hash)

    Document URL or hash with :url key

  • options (Hash)

    Additional splitting options

Returns:

  • (Hash)

    Split results with keys:

    • "job_id" [String] - Job identifier
    • "status" [String] - Job status ("succeeded")
    • "result" [Hash] - Sections with page ranges
    • "usage" [Hash] - Credit usage details

Raises:

  • (ArgumentError)

    if input is nil

  • (ClientError)

    if document URL is invalid

  • (ServerError)

    if splitting fails

See Also:



48
49
50
51
52
53
54
# File 'lib/reducto_ai/resources/split.rb', line 48

def sync(input:, **options)
  raise ArgumentError, "input is required" if input.nil?

  normalized_input = normalize_input(input)
  payload = { input: normalized_input, **options }.compact
  @client.post("/split", payload)
end