Class: Retab::Schemas

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

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Schemas

Returns a new instance of Schemas.



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

def initialize(client)
  @client = client
end

Instance Method Details

#generate(documents:, model: nil, reasoning_effort: nil, instructions: nil, image_resolution_dpi: nil, stream: nil, request_options: {}) ⇒ Retab::PartialSchema

Generate Schema From Examples

Parameters:

  • documents (Array<Retab::MimeData, Pathname, IO, String, Hash>)
  • model (String, nil) (defaults to: nil)
  • reasoning_effort (Retab::Types::GenerateSchemaRequestReasoningEffort, nil) (defaults to: nil)
  • instructions (String, nil) (defaults to: nil)
  • image_resolution_dpi (Integer, nil) (defaults to: nil)

    Resolution of the image sent to the LLM

  • stream (Boolean, nil) (defaults to: nil)
  • request_options (Hash) (defaults to: {})

    (see Retab::Types::RequestOptions)

Returns:



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

def generate(
  documents:,
  model: nil,
  reasoning_effort: nil,
  instructions: nil,
  image_resolution_dpi: nil,
  stream: nil,
  request_options: {}
)
  documents = documents.map { |d| Retab::MimeData.coerce(d) } unless documents.nil?
  body = {
    'documents' => documents,
    'model' => model,
    'reasoning_effort' => reasoning_effort,
    'instructions' => instructions,
    'image_resolution_dpi' => image_resolution_dpi,
    'stream' => stream
  }.compact
  response = @client.request(
    method: :post,
    path: '/v1/schemas/generate',
    auth: true,
    body: body,
    request_options: request_options
  )
  result = Retab::PartialSchema.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