Class: Retab::Parses

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

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Parses

Returns a new instance of Parses.



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

def initialize(client)
  @client = client
end

Instance Method Details

#create(document:, model: nil, table_parsing_format: nil, image_resolution_dpi: nil, instructions: nil, bust_cache: nil, request_options: {}) ⇒ Retab::Parse

Create Parse

Parameters:

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

    The document to parse

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

    The model to use for parsing

  • table_parsing_format (Retab::Types::ParseRequestTableParsingFormat, nil) (defaults to: nil)

    Format used to render tables extracted from the document

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

    DPI used when rasterizing pages for the parser

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

    Free-form instructions appended to the system prompt to steer the parse.

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

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

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

    (see Retab::Types::RequestOptions)

Returns:



78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/retab/parses.rb', line 78

def create(
  document:,
  model: nil,
  table_parsing_format: nil,
  image_resolution_dpi: nil,
  instructions: nil,
  bust_cache: nil,
  request_options: {}
)
  document = Retab::MimeData.coerce(document) unless document.nil?
  body = {
    'document' => document,
    'model' => model,
    'table_parsing_format' => table_parsing_format,
    'image_resolution_dpi' => image_resolution_dpi,
    'instructions' => instructions,
    'bust_cache' => bust_cache
  }.compact
  response = @client.request(
    method: :post,
    path: '/v1/parses',
    auth: true,
    body: body,
    request_options: request_options
  )
  result = Retab::Parse.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(parse_id:, request_options: {}) ⇒ void

This method returns an undefined value.

Delete Parse

Parameters:

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

    (see Retab::Types::RequestOptions)



131
132
133
134
135
136
137
138
139
140
141
142
# File 'lib/retab/parses.rb', line 131

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

#get(parse_id:, request_options: {}) ⇒ Retab::Parse

Get Parse

Parameters:

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

    (see Retab::Types::RequestOptions)

Returns:



112
113
114
115
116
117
118
119
120
121
122
123
124
125
# File 'lib/retab/parses.rb', line 112

def get(
  parse_id:,
  request_options: {}
)
  response = @client.request(
    method: :get,
    path: "/v1/parses/#{Retab::Util.encode_path(parse_id)}",
    auth: true,
    request_options: request_options
  )
  result = Retab::Parse.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, from_date: nil, to_date: nil, request_options: {}) ⇒ Retab::Types::ListStruct<Retab::Parse>

List Parses

Parameters:

  • before (String, nil) (defaults to: nil)
  • after (String, nil) (defaults to: nil)
  • limit (Integer, nil) (defaults to: 10)
  • order (Retab::Types::ParsesOrder, nil) (defaults to: 'desc')
  • filename (String, 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:



23
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
# File 'lib/retab/parses.rb', line 23

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