Class: Mindee::Input::InferenceParameters

Inherits:
BaseParameters show all
Defined in:
lib/mindee/input/inference_parameters.rb

Overview

Parameters to set when sending a file for inference.

Instance Attribute Summary collapse

Attributes inherited from BaseParameters

#close_file, #file_alias, #model_id, #polling_options, #webhook_ids

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseParameters

load_from_hash, #slug, #validate_async_params

Constructor Details

#initialize(model_id, rag: nil, raw_text: nil, polygon: nil, confidence: nil, file_alias: nil, webhook_ids: nil, text_context: nil, polling_options: nil, close_file: true, data_schema: nil) ⇒ InferenceParameters

rubocop:disable Metrics/ParameterLists

Parameters:

  • model_id (String)

    ID of the model

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

    Whether to enable RAG.

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

    Whether to enable rax text.

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

    Whether to enable polygons.

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

    Whether to enable confidence scores.

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

    File alias, if applicable.

  • webhook_ids (Array<String>, nil) (defaults to: nil)
  • text_context (String, nil) (defaults to: nil)
  • polling_options (Hash, nil) (defaults to: nil)
  • close_file (Boolean, nil) (defaults to: true)
  • data_schema (DataSchemaField, String, Hash nil) (defaults to: nil)


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
# File 'lib/mindee/input/inference_parameters.rb', line 49

def initialize(
  model_id,
  rag: nil,
  raw_text: nil,
  polygon: nil,
  confidence: nil,
  file_alias: nil,
  webhook_ids: nil,
  text_context: nil,
  polling_options: nil,
  close_file: true,
  data_schema: nil
)
  super(
    model_id,
    file_alias: file_alias,
    webhook_ids: webhook_ids,
    polling_options: polling_options,
    close_file: close_file
  )

  @rag = rag
  @raw_text = raw_text
  @polygon = polygon
  @confidence = confidence
  @text_context = text_context
  @data_schema = DataSchema.new(data_schema) unless data_schema.nil?
  # rubocop:enable Metrics/ParameterLists
end

Instance Attribute Details

#confidenceBoolean? (readonly)

Returns Boost the precision and accuracy of all extractions. Calculate confidence scores for all fields, and fill their confidence attribute.

Returns:

  • (Boolean, nil)

    Boost the precision and accuracy of all extractions. Calculate confidence scores for all fields, and fill their confidence attribute.



23
24
25
# File 'lib/mindee/input/inference_parameters.rb', line 23

def confidence
  @confidence
end

#data_schemaDataSchemaField (readonly)

Returns:



30
31
32
# File 'lib/mindee/input/inference_parameters.rb', line 30

def data_schema
  @data_schema
end

#polygonBoolean? (readonly)

Returns Calculate bounding box polygons for all fields, and fill their locations attribute.

Returns:

  • (Boolean, nil)

    Calculate bounding box polygons for all fields, and fill their locations attribute.



19
20
21
# File 'lib/mindee/input/inference_parameters.rb', line 19

def polygon
  @polygon
end

#ragBoolean? (readonly)

Returns Enhance extraction accuracy with Retrieval-Augmented Generation.

Returns:

  • (Boolean, nil)

    Enhance extraction accuracy with Retrieval-Augmented Generation.



11
12
13
# File 'lib/mindee/input/inference_parameters.rb', line 11

def rag
  @rag
end

#raw_textBoolean? (readonly)

Returns Extract the full text content from the document as strings, and fill the raw_text` attribute.

Returns:

  • (Boolean, nil)

    Extract the full text content from the document as strings, and fill the raw_text` attribute.



15
16
17
# File 'lib/mindee/input/inference_parameters.rb', line 15

def raw_text
  @raw_text
end

#text_contextString? (readonly)

Returns Additional text context used by the model during inference. Not recommended, for specific use only.

Returns:

  • (String, nil)

    Additional text context used by the model during inference. Not recommended, for specific use only.



27
28
29
# File 'lib/mindee/input/inference_parameters.rb', line 27

def text_context
  @text_context
end

Class Method Details

.from_hash(params: {}) ⇒ InferenceParameters

Loads a prediction from a Hash.

Parameters:

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

    Parameters to provide as a hash.

Returns:



98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# File 'lib/mindee/input/inference_parameters.rb', line 98

def self.from_hash(params: {})
  rag = params.fetch(:rag, nil)
  raw_text = params.fetch(:raw_text, nil)
  polygon = params.fetch(:polygon, nil)
  confidence = params.fetch(:confidence, nil)
  base_params = load_from_hash(params: params)
  new_params = base_params.merge(rag: rag, raw_text: raw_text, polygon: polygon, confidence: confidence)
  model_id = new_params.fetch(:model_id)

  InferenceParameters.new(
    model_id, rag: rag,
              raw_text: raw_text,
              polygon: polygon,
              confidence: confidence,
              file_alias: params.fetch(:file_alias, nil),
              webhook_ids: params.fetch(:webhook_ids, nil),
              close_file: params.fetch(:close_file, true)
  )
end

.slugString

Returns Slug for the endpoint.

Returns:

  • (String)

    Slug for the endpoint.



33
34
35
# File 'lib/mindee/input/inference_parameters.rb', line 33

def self.slug
  'extraction'
end

Instance Method Details

#append_form_data(form_data) ⇒ Array

Appends inference-specific form data to the provided array.

Parameters:

  • form_data (Array)

    Array of form fields

Returns:

  • (Array)


82
83
84
85
86
87
88
89
90
91
92
93
# File 'lib/mindee/input/inference_parameters.rb', line 82

def append_form_data(form_data)
  new_form_data = super

  new_form_data.push(['rag', @rag.to_s]) unless @rag.nil?
  new_form_data.push(['raw_text', @raw_text.to_s]) unless @raw_text.nil?
  new_form_data.push(['polygon', @polygon.to_s]) unless @polygon.nil?
  new_form_data.push(['confidence', @confidence.to_s]) unless @confidence.nil?
  new_form_data.push(['text_context', @text_context]) if @text_context
  new_form_data.push(['data_schema', @data_schema.to_s]) if @data_schema

  new_form_data
end