Class: Retab::Partitions

Inherits:
Object
  • Object
show all
Defined in:
lib/retab/partitions.rb

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Partitions

Returns a new instance of Partitions.



9
10
11
# File 'lib/retab/partitions.rb', line 9

def initialize(client)
  @client = client
end

Instance Method Details

#create(document:, key:, instructions:, model: nil, n_consensus: nil, allow_overlap: nil, bust_cache: nil, background: nil, request_options: {}) ⇒ Retab::Partition

Create Partitions

Parameters:

  • document (Retab::MimeData, Pathname, IO, String, Hash)

    The document to partition

  • key (String)

    The key to partition the document by

  • instructions (String)

    Instructions describing how the document should be partitioned

  • model (String, nil) (defaults to: nil)

    The model to use for partitioning

  • n_consensus (Integer, nil) (defaults to: nil)

    Number of partitioning runs to use for consensus voting. Uses deterministic single-pass when set to 1.

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

    If true, allow a page to appear in more than one partition chunk

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

    If true, skip the LLM cache and force a fresh completion

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

    If true, run asynchronously: returns immediately with status ‘queued’ and an empty output. Poll GET /v1/<primitive>/id until status is terminal. Mutually exclusive with stream.

  • request_options (Hash) (defaults to: {})

    (see Retab::Types::RequestOptions)

Returns:



92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
# File 'lib/retab/partitions.rb', line 92

def create(
  document:,
  key:,
  instructions:,
  model: nil,
  n_consensus: nil,
  allow_overlap: nil,
  bust_cache: nil,
  background: nil,
  request_options: {}
)
  document = Retab::MimeData.coerce(document) unless document.nil?
  body = {
    "document" => document,
    "key" => key,
    "instructions" => instructions,
    "model" => model,
    "n_consensus" => n_consensus,
    "allow_overlap" => allow_overlap,
    "bust_cache" => bust_cache,
    "background" => background
  }.compact
  response = @client.request(
    method: :post,
    path: "/v1/partitions",
    auth: true,
    body: body,
    request_options: request_options
  )
  result = Retab::Partition.new(response.body)
  result.last_response = Retab::Types::ApiResponse.new(
    http_status: response.code.to_i,
    http_headers: response.each_header.to_h,
    request_id: response["x-request-id"]
  )
  result
end

#create_partition_cancel(partition_id:, request_options: {}) ⇒ Retab::Partition

Cancel Partition

Parameters:

  • partition_id (String)
  • request_options (Hash) (defaults to: {})

    (see Retab::Types::RequestOptions)

Returns:



180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
# File 'lib/retab/partitions.rb', line 180

def create_partition_cancel(
  partition_id:,
  request_options: {}
)
  response = @client.request(
    method: :post,
    path: "/v1/partitions/#{Retab::Util.encode_path(partition_id)}/cancel",
    auth: true,
    request_options: request_options
  )
  result = Retab::Partition.new(response.body)
  result.last_response = Retab::Types::ApiResponse.new(
    http_status: response.code.to_i,
    http_headers: response.each_header.to_h,
    request_id: response["x-request-id"]
  )
  result
end

#delete(partition_id:, request_options: {}) ⇒ void

This method returns an undefined value.

Delete Partition

Parameters:

  • partition_id (String)
  • request_options (Hash) (defaults to: {})

    (see Retab::Types::RequestOptions)



163
164
165
166
167
168
169
170
171
172
173
174
# File 'lib/retab/partitions.rb', line 163

def delete(
  partition_id:,
  request_options: {}
)
  @client.request(
    method: :delete,
    path: "/v1/partitions/#{Retab::Util.encode_path(partition_id)}",
    auth: true,
    request_options: request_options
  )
  nil
end

#get(partition_id:, include_output: true, request_options: {}) ⇒ Retab::Partition

Get Partition

Parameters:

  • partition_id (String)
  • include_output (Boolean, nil) (defaults to: true)

    When false, returns a cheap status-only projection (no output), served from cache for in-flight background runs.

  • request_options (Hash) (defaults to: {})

    (see Retab::Types::RequestOptions)

Returns:



135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
# File 'lib/retab/partitions.rb', line 135

def get(
  partition_id:,
  include_output: true,
  request_options: {}
)
  params = {
    "include_output" => include_output
  }.compact
  response = @client.request(
    method: :get,
    path: "/v1/partitions/#{Retab::Util.encode_path(partition_id)}",
    auth: true,
    params: params,
    request_options: request_options
  )
  result = Retab::Partition.new(response.body)
  result.last_response = Retab::Types::ApiResponse.new(
    http_status: response.code.to_i,
    http_headers: response.each_header.to_h,
    request_id: response["x-request-id"]
  )
  result
end

#list(before: nil, after: nil, limit: 10, order: "desc", filename: nil, status: nil, from_date: nil, to_date: nil, request_options: {}) ⇒ Retab::PaginatedList<Retab::Partition>

List Partitions

Parameters:

  • before (String, nil) (defaults to: nil)
  • after (String, nil) (defaults to: nil)
  • limit (Integer, nil) (defaults to: 10)
  • order (Retab::Types::PartitionsOrder, nil) (defaults to: "desc")
  • filename (String, nil) (defaults to: nil)
  • status (Retab::Types::PartitionsStatus, nil) (defaults to: nil)
  • from_date (String, nil) (defaults to: nil)
  • to_date (String, nil) (defaults to: nil)
  • request_options (Hash) (defaults to: {})

    (see Retab::Types::RequestOptions)

Returns:



24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# File 'lib/retab/partitions.rb', line 24

def list(
  before: nil,
  after: nil,
  limit: 10,
  order: "desc",
  filename: nil,
  status: nil,
  from_date: nil,
  to_date: nil,
  request_options: {}
)
  params = {
    "before" => before,
    "after" => after,
    "limit" => limit,
    "order" => order,
    "filename" => filename,
    "status" => status,
    "from_date" => from_date,
    "to_date" => to_date
  }.compact
  response = @client.request(
    method: :get,
    path: "/v1/partitions",
    auth: true,
    params: params,
    request_options: request_options
  )
  fetch_next = -> (cursor) {
    list(
      before: before,
      after: cursor,
      limit: limit,
      order: order,
      filename: filename,
      status: status,
      from_date: from_date,
      to_date: to_date,
      request_options: request_options
    )
  }
  Retab::PaginatedList.from_response(
    response,
    model: Retab::Partition,
    filters: {
      before: before,
      limit: limit,
      order: order,
      filename: filename,
      status: status,
      from_date: from_date,
      to_date: to_date
    },
    fetch_next: fetch_next
  )
end