Class: Mindee::Input::InferenceParameters
- Inherits:
-
Object
- Object
- Mindee::Input::InferenceParameters
- Defined in:
- lib/mindee/input/inference_parameters.rb
Overview
Parameters to set when sending a file for inference.
Instance Attribute Summary collapse
-
#close_file ⇒ Boolean?
readonly
Whether to close the file after parsing.
-
#confidence ⇒ Boolean?
readonly
Boost the precision and accuracy of all extractions.
- #data_schema ⇒ DataSchemaField readonly
-
#file_alias ⇒ String?
readonly
Optional alias for the file.
-
#model_id ⇒ String
readonly
ID of the model (required).
-
#polling_options ⇒ PollingOptions
readonly
Options for polling.
-
#polygon ⇒ Boolean?
readonly
Calculate bounding box polygons for all fields, and fill their
locationsattribute. -
#rag ⇒ Boolean?
readonly
Enhance extraction accuracy with Retrieval-Augmented Generation.
-
#raw_text ⇒ Boolean?
readonly
Extract the full text content from the document as strings, and fill the raw_text` attribute.
-
#text_context ⇒ String?
readonly
Additional text context used by the model during inference.
-
#webhook_ids ⇒ Array<String>?
readonly
Optional list of Webhooks IDs to propagate the API response to.
Class Method Summary collapse
-
.from_hash(params: {}) ⇒ InferenceParameters
Loads a prediction from a Hash.
Instance Method Summary collapse
-
#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
constructor
rubocop:disable Metrics/ParameterLists.
-
#validate_async_params ⇒ Object
Validates the parameters for async auto-polling.
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
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 |
# File 'lib/mindee/input/inference_parameters.rb', line 56 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 ) raise Errors::MindeeInputError, 'Model ID is required.' if model_id.empty? || model_id.nil? @model_id = model_id @rag = rag @raw_text = raw_text @polygon = polygon @confidence = confidence @file_alias = file_alias @webhook_ids = webhook_ids || [] @text_context = text_context = () @close_file = close_file.nil? || close_file @data_schema = DataSchema.new(data_schema) unless data_schema.nil? # rubocop:enable Metrics/ParameterLists end |
Instance Attribute Details
#close_file ⇒ Boolean? (readonly)
Returns Whether to close the file after parsing.
44 45 46 |
# File 'lib/mindee/input/inference_parameters.rb', line 44 def close_file @close_file end |
#confidence ⇒ Boolean? (readonly)
Returns Boost the precision and accuracy of all extractions. Calculate confidence scores for all fields, and fill their confidence attribute.
25 26 27 |
# File 'lib/mindee/input/inference_parameters.rb', line 25 def confidence @confidence end |
#data_schema ⇒ DataSchemaField (readonly)
41 42 43 |
# File 'lib/mindee/input/inference_parameters.rb', line 41 def data_schema @data_schema end |
#file_alias ⇒ String? (readonly)
Returns Optional alias for the file.
28 29 30 |
# File 'lib/mindee/input/inference_parameters.rb', line 28 def file_alias @file_alias end |
#model_id ⇒ String (readonly)
Returns ID of the model (required).
10 11 12 |
# File 'lib/mindee/input/inference_parameters.rb', line 10 def model_id @model_id end |
#polling_options ⇒ PollingOptions (readonly)
Returns Options for polling. Set only if having timeout issues.
38 39 40 |
# File 'lib/mindee/input/inference_parameters.rb', line 38 def end |
#polygon ⇒ Boolean? (readonly)
Returns Calculate bounding box polygons for all fields,
and fill their locations attribute.
21 22 23 |
# File 'lib/mindee/input/inference_parameters.rb', line 21 def polygon @polygon end |
#rag ⇒ Boolean? (readonly)
Returns Enhance extraction accuracy with Retrieval-Augmented Generation.
13 14 15 |
# File 'lib/mindee/input/inference_parameters.rb', line 13 def rag @rag end |
#raw_text ⇒ Boolean? (readonly)
Returns Extract the full text content from the document as strings, and fill the raw_text` attribute.
17 18 19 |
# File 'lib/mindee/input/inference_parameters.rb', line 17 def raw_text @raw_text end |
#text_context ⇒ String? (readonly)
Returns Additional text context used by the model during inference. Not recommended, for specific use only.
32 33 34 |
# File 'lib/mindee/input/inference_parameters.rb', line 32 def text_context @text_context end |
#webhook_ids ⇒ Array<String>? (readonly)
Returns Optional list of Webhooks IDs to propagate the API response to.
35 36 37 |
# File 'lib/mindee/input/inference_parameters.rb', line 35 def webhook_ids @webhook_ids end |
Class Method Details
.from_hash(params: {}) ⇒ InferenceParameters
Loads a prediction from a Hash.
108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 |
# File 'lib/mindee/input/inference_parameters.rb', line 108 def self.from_hash(params: {}) params.transform_keys!(&:to_sym) if params.empty? || params[:model_id].nil? || params[:model_id].empty? raise Errors::MindeeInputError, 'Model ID is required.' end model_id = params.fetch(:model_id) rag = params.fetch(:rag, nil) raw_text = params.fetch(:raw_text, nil) polygon = params.fetch(:polygon, nil) confidence = params.fetch(:confidence, nil) file_alias = params.fetch(:file_alias, nil) webhook_ids = params.fetch(:webhook_ids, []) = params.fetch(:page_options, PollingOptions.new) if .is_a?(Hash) = .transform_keys(&:to_sym) PollingOptions.new( initial_delay_sec: .fetch(:initial_delay_sec, 2.0), delay_sec: .fetch(:delay_sec, 1.5), max_retries: .fetch(:max_retries, 80) ) end close_file = params.fetch(:close_file, true) InferenceParameters.new(model_id, rag: rag, raw_text: raw_text, polygon: polygon, confidence: confidence, file_alias: file_alias, webhook_ids: webhook_ids, close_file: close_file) end |
Instance Method Details
#validate_async_params ⇒ Object
Validates the parameters for async auto-polling
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 |
# File 'lib/mindee/input/inference_parameters.rb', line 86 def validate_async_params min_delay_sec = 1 min_initial_delay_sec = 1 min_retries = 2 if .delay_sec < min_delay_sec raise ArgumentError, "Cannot set auto-poll delay to less than #{min_delay_sec} second(s)" end if .initial_delay_sec < min_initial_delay_sec raise ArgumentError, "Cannot set initial parsing delay to less than #{min_initial_delay_sec} second(s)" end return unless .max_retries < min_retries raise ArgumentError, "Cannot set auto-poll retries to less than #{min_retries}" end |