mindee 4.8.0 → 4.10.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6bbe7fd9450d6e87f07b3b96c636ef8715200370503eb97d65db46225b6ccf8e
4
- data.tar.gz: 36b67f8ca703982d40048e4d7e9a3b20e4204c7a36386028b3bd11da79560a20
3
+ metadata.gz: a0ab40fd2712787376dff65bab0aecb06a9ecd0337aa5ffe8b0d2ed115fac2a6
4
+ data.tar.gz: 661847259c9047171d1fe198a20459afd5545b3e298b253252a8ad59f12ac3c0
5
5
  SHA512:
6
- metadata.gz: '08dd6e3e40ea73f874647ab537f2539342aca107bb1d324c04fa8b8de1fa803f5893117bcaf0e840dd6210b55e6e7c163897bb6cba6a36389b44daeab6a886e2'
7
- data.tar.gz: 6028ec9f0d38e9e7840c33c98a517d8db02aef34058b8ae517c560cdc0b88524a0e2ab4a472dfe4e1f12ef027fce5bd2153cebd628e2c66f29ac3c8733c1cec3
6
+ metadata.gz: 9d33a23521dcc763584f92f22ca11b02dbea63d016c4f39173a15fe865805f362801bdd7f205761030524e70b65ff4f73d90d742212a49f3f21b6cf8979c5556
7
+ data.tar.gz: 19dee30dd72aa0adc05f4754f8a62b7c3299bdca7de25fda9aed315c485a11aa4878d28f3f086d9a6fed81371a599fa5c9ce3b4d883e835edd9ced77dce9b4c2
data/CHANGELOG.md CHANGED
@@ -1,5 +1,15 @@
1
1
  # Mindee Ruby API Library Changelog
2
2
 
3
+ ## v4.10.0 - 2025-12-19
4
+ ### Changes
5
+ :sparkles: add support for dataschema parameter
6
+
7
+
8
+ ## v4.9.0 - 2025-12-02
9
+ ### Changes
10
+ * :sparkles: add support for text_context parameter
11
+
12
+
3
13
  ## v4.8.0 - 2025-11-18
4
14
  ### Changes
5
15
  * :sparkles: add support for better errors
@@ -111,8 +111,26 @@ module Mindee
111
111
  poll("#{@settings.base_url}/inferences/#{queue_id}")
112
112
  end
113
113
 
114
+ # Handle parameters for the enqueue form
115
+ # @param form_data [Array] Array of form fields
116
+ # @param params [Input::InferenceParameters] Inference options.
117
+ def enqueue_form_options(form_data, params)
118
+ # deal with optional features
119
+ form_data.push(['rag', params.rag.to_s]) unless params.rag.nil?
120
+ form_data.push(['raw_text', params.raw_text.to_s]) unless params.raw_text.nil?
121
+ form_data.push(['polygon', params.polygon.to_s]) unless params.polygon.nil?
122
+ form_data.push(['confidence', params.confidence.to_s]) unless params.confidence.nil?
123
+ form_data.push ['file_alias', params.file_alias] if params.file_alias
124
+ form_data.push ['text_context', params.text_context] if params.text_context
125
+ form_data.push ['data_schema', params.data_schema.to_s] if params.data_schema
126
+ unless params.webhook_ids.nil? || params.webhook_ids.empty?
127
+ form_data.push ['webhook_ids', params.webhook_ids.join(',')]
128
+ end
129
+ form_data
130
+ end
131
+
114
132
  # @param input_source [Mindee::Input::Source::LocalInputSource, Mindee::Input::Source::URLInputSource]
115
- # @param params [Input::InferenceParameters] Parse options.
133
+ # @param params [Input::InferenceParameters] Inference options.
116
134
  # @return [Net::HTTPResponse, nil]
117
135
  def enqueue(input_source, params)
118
136
  uri = URI("#{@settings.base_url}/inferences/enqueue")
@@ -125,16 +143,9 @@ module Mindee
125
143
  end
126
144
  form_data.push(['model_id', params.model_id])
127
145
 
128
- # deal with optional features
129
- form_data.push(['rag', params.rag.to_s]) unless params.rag.nil?
130
- form_data.push(['raw_text', params.raw_text.to_s]) unless params.raw_text.nil?
131
- form_data.push(['polygon', params.polygon.to_s]) unless params.polygon.nil?
132
- form_data.push(['confidence', params.confidence.to_s]) unless params.confidence.nil?
146
+ # deal with other parameters
147
+ form_data = enqueue_form_options(form_data, params)
133
148
 
134
- form_data.push ['file_alias', params.file_alias] if params.file_alias
135
- unless params.webhook_ids.nil? || params.webhook_ids.empty?
136
- form_data.push ['webhook_ids', params.webhook_ids.join(',')]
137
- end
138
149
  headers = {
139
150
  'Authorization' => @settings.api_key,
140
151
  'User-Agent' => @settings.user_agent,
@@ -0,0 +1,126 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mindee
4
+ module Input
5
+ # Data Schema Field.
6
+ class DataSchemaField
7
+ # @return [String] Display name for the field, also impacts inference results.
8
+ attr_reader :title
9
+ # @return [String] Name of the field in the data schema.
10
+ attr_reader :name
11
+ # @return [Boolean] Whether this field can contain multiple values.
12
+ attr_reader :is_array
13
+ # @return [String] Data type of the field.
14
+ attr_reader :type
15
+ # @return [Array<String>, nil] Allowed values when type is `classification`. Leave empty for other types.
16
+ attr_reader :classification_values
17
+ # @return [Boolean, nil] Whether to remove duplicate values in the array.
18
+ # Only applicable if `is_array` is True.
19
+ attr_reader :unique_values
20
+ # @return [String, nil] Detailed description of what this field represents.
21
+ attr_reader :description
22
+ # @return [String, nil] Optional extraction guidelines.
23
+ attr_reader :guidelines
24
+ # @return [Array<Hash>, nil] Nested fields.
25
+ attr_reader :nested_fields
26
+
27
+ # @param field [Hash]
28
+ def initialize(field)
29
+ field.transform_keys!(&:to_sym)
30
+ @name = field[:name]
31
+ @title = field[:title]
32
+ @is_array = field[:is_array]
33
+ @type = field[:type]
34
+ @classification_values = field[:classification_values]
35
+ @unique_values = field[:unique_values]
36
+ @description = field[:description]
37
+ @guidelines = field[:guidelines]
38
+ @nested_fields = field[:nested_fields]
39
+ end
40
+
41
+ # @return [Hash]
42
+ def to_hash
43
+ out = {
44
+ name: @name,
45
+ title: @title,
46
+ is_array: @is_array,
47
+ type: @type,
48
+ } # @type var out: Hash[Symbol, untyped]
49
+ out[:classification_values] = @classification_values unless @classification_values.nil?
50
+ out[:unique_values] = @unique_values unless @unique_values.nil?
51
+ out[:description] = @description unless @description.nil?
52
+ out[:guidelines] = @guidelines unless @guidelines.nil?
53
+ out[:nested_fields] = @nested_fields unless @nested_fields.nil?
54
+ out
55
+ end
56
+
57
+ # @return [String]
58
+ def to_s
59
+ to_hash.to_json
60
+ end
61
+ end
62
+
63
+ # The structure to completely replace the data schema of the model.
64
+ class DataSchemaReplace
65
+ # @return [Array<DataSchemaField>] Subfields when type is `nested_object`. Leave empty for other types.
66
+ attr_reader :fields
67
+
68
+ # @param data_schema_replace [Hash]
69
+ def initialize(data_schema_replace)
70
+ data_schema_replace.transform_keys!(&:to_sym)
71
+ fields_list = data_schema_replace[:fields]
72
+ raise Mindee::Errors::MindeeError, 'Invalid Data Schema provided.' if fields_list.nil?
73
+ raise TypeError, 'Data Schema replacement fields cannot be empty.' if fields_list.empty?
74
+
75
+ @fields = fields_list.map { |field| DataSchemaField.new(field) }
76
+ end
77
+
78
+ # @return [Hash]
79
+ def to_hash
80
+ { fields: @fields.map(&:to_hash) }
81
+ end
82
+
83
+ # @return [String]
84
+ def to_s
85
+ to_hash.to_json
86
+ end
87
+ end
88
+
89
+ # Modify the Data Schema.
90
+ class DataSchema
91
+ # @return [Mindee::Input::DataSchemaReplace]
92
+ attr_reader :replace
93
+
94
+ # @param data_schema [Hash, String]
95
+ def initialize(data_schema)
96
+ case data_schema
97
+ when String
98
+ parsed = JSON.parse(data_schema.to_s, object_class: Hash)
99
+ parsed.transform_keys!(&:to_sym)
100
+ @replace = DataSchemaReplace.new(parsed[:replace])
101
+ when Hash
102
+ data_schema.transform_keys!(&:to_sym)
103
+ @replace = if data_schema[:replace].is_a?(DataSchemaReplace)
104
+ data_schema[:replace]
105
+ else
106
+ DataSchemaReplace.new(data_schema[:replace])
107
+ end
108
+ when DataSchema
109
+ @replace = data_schema.replace
110
+ else
111
+ raise TypeError, 'Invalid Data Schema provided.'
112
+ end
113
+ end
114
+
115
+ # @return [Hash]
116
+ def to_hash
117
+ { replace: @replace.to_hash }
118
+ end
119
+
120
+ # @return [String]
121
+ def to_s
122
+ to_hash.to_json
123
+ end
124
+ end
125
+ end
126
+ end
@@ -1,5 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative 'data_schema'
4
+
3
5
  module Mindee
4
6
  module Input
5
7
  # Parameters to set when sending a file for inference.
@@ -25,12 +27,19 @@ module Mindee
25
27
  # @return [String, nil] Optional alias for the file.
26
28
  attr_reader :file_alias
27
29
 
30
+ # @return [String, nil] Additional text context used by the model during inference.
31
+ # Not recommended, for specific use only.
32
+ attr_reader :text_context
33
+
28
34
  # @return [Array<String>, nil] Optional list of Webhooks IDs to propagate the API response to.
29
35
  attr_reader :webhook_ids
30
36
 
31
37
  # @return [PollingOptions] Options for polling. Set only if having timeout issues.
32
38
  attr_reader :polling_options
33
39
 
40
+ # @return [DataSchemaField]
41
+ attr_reader :data_schema
42
+
34
43
  # @return [Boolean, nil] Whether to close the file after parsing.
35
44
  attr_reader :close_file
36
45
 
@@ -52,8 +61,10 @@ module Mindee
52
61
  confidence: nil,
53
62
  file_alias: nil,
54
63
  webhook_ids: nil,
64
+ text_context: nil,
55
65
  polling_options: nil,
56
- close_file: true
66
+ close_file: true,
67
+ data_schema: nil
57
68
  )
58
69
  raise Errors::MindeeInputError, 'Model ID is required.' if model_id.empty? || model_id.nil?
59
70
 
@@ -64,8 +75,10 @@ module Mindee
64
75
  @confidence = confidence
65
76
  @file_alias = file_alias
66
77
  @webhook_ids = webhook_ids || []
78
+ @text_context = text_context
67
79
  @polling_options = get_clean_polling_options(polling_options)
68
80
  @close_file = close_file.nil? || close_file
81
+ @data_schema = DataSchema.new(data_schema) unless data_schema.nil?
69
82
  # rubocop:enable Metrics/ParameterLists
70
83
  end
71
84
 
data/lib/mindee/input.rb CHANGED
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ require_relative 'input/data_schema'
3
4
  require_relative 'input/inference_parameters'
4
5
  require_relative 'input/polling_options'
5
6
  require_relative 'input/sources'
@@ -3,6 +3,23 @@
3
3
  module Mindee
4
4
  module Parsing
5
5
  module V2
6
+ # Data schema options activated during the inference.
7
+ class DataSchemaActiveOption
8
+ # @return [Boolean]
9
+ attr_reader :replace
10
+
11
+ # @param server_response [Hash]
12
+ def initialize(server_response)
13
+ @replace = server_response[:replace] || server_response['replace']
14
+ end
15
+
16
+ # String representation.
17
+ # @return [String]
18
+ def to_s
19
+ "Data Schema\n-----------\n:Replace: #{@replace ? 'True' : 'False'}"
20
+ end
21
+ end
22
+
6
23
  # Options which were activated during the inference.
7
24
  class InferenceActiveOptions
8
25
  # @return [Boolean] Whether the Raw Text feature was activated.
@@ -13,6 +30,10 @@ module Mindee
13
30
  attr_reader :confidence
14
31
  # @return [Boolean] Whether the Retrieval-Augmented Generation feature was activated.
15
32
  attr_reader :rag
33
+ # @return [Boolean] Whether the text context feature was activated.
34
+ attr_reader :text_context
35
+ # @return [DataSchemaActiveOption]
36
+ attr_reader :data_schema
16
37
 
17
38
  # @param server_response [Hash] Raw JSON parsed into a Hash.
18
39
  def initialize(server_response)
@@ -20,6 +41,8 @@ module Mindee
20
41
  @polygon = server_response['polygon']
21
42
  @confidence = server_response['confidence']
22
43
  @rag = server_response['rag']
44
+ @text_context = server_response['text_context']
45
+ @data_schema = DataSchemaActiveOption.new(server_response['data_schema'])
23
46
  end
24
47
 
25
48
  # String representation.
@@ -32,6 +55,8 @@ module Mindee
32
55
  ":Polygon: #{@polygon ? 'True' : 'False'}",
33
56
  ":Confidence: #{@confidence ? 'True' : 'False'}",
34
57
  ":RAG: #{@rag ? 'True' : 'False'}",
58
+ ":Text Context: #{@text_context ? 'True' : 'False'}\n",
59
+ @data_schema.to_s,
35
60
  '',
36
61
  ]
37
62
  parts.join("\n")
@@ -3,7 +3,7 @@
3
3
  # Mindee
4
4
  module Mindee
5
5
  # Current version.
6
- VERSION = '4.8.0'
6
+ VERSION = '4.10.0'
7
7
 
8
8
  # Finds and return the current platform.
9
9
  # @return [Symbol, Hash[String | Symbol, Regexp], Nil?]
@@ -13,6 +13,10 @@ module Mindee
13
13
  def inference_job_req_get: (String) -> Net::HTTPResponse
14
14
  def inference_result_req_get: (String) -> Net::HTTPResponse
15
15
  def enqueue: (Input::Source::LocalInputSource | Input::Source::URLInputSource, Input::InferenceParameters) -> Net::HTTPResponse?
16
+
17
+ private
18
+
19
+ def enqueue_form_options: (Array[untyped], Input::InferenceParameters) -> Array[untyped]
16
20
  end
17
21
  end
18
22
  end
@@ -0,0 +1,34 @@
1
+ module Mindee
2
+ module Input
3
+ class DataSchemaField
4
+ attr_reader title: String
5
+ attr_reader name: String
6
+ attr_reader is_array: bool
7
+ attr_reader type: String
8
+ attr_reader classification_values: String|nil
9
+ attr_reader unique_values: bool|nil
10
+ attr_reader description: String|nil
11
+ attr_reader guidelines: String|nil
12
+ attr_reader nested_fields: Array[Hash[String|Symbol, untyped]]|nil
13
+
14
+ def initialize: (Hash[Symbol, untyped]) -> void
15
+ def to_hash: () -> Hash[Symbol, untyped]
16
+ def to_string: () -> String
17
+ end
18
+
19
+ class DataSchemaReplace
20
+ attr_reader fields: Array[DataSchemaField]
21
+ def initialize: (Hash[Symbol, untyped]) -> void
22
+ def to_hash: () -> Hash[Symbol, untyped]
23
+ def to_string: () -> String
24
+ end
25
+
26
+ class DataSchema
27
+ attr_reader replace: DataSchemaReplace
28
+
29
+ def initialize: (Hash[String|Symbol, untyped]|String|DataSchema) -> void
30
+ def to_hash: () -> Hash[Symbol, untyped]
31
+ def to_s: -> String
32
+ end
33
+ end
34
+ end
@@ -10,7 +10,9 @@ module Mindee
10
10
  attr_reader polygon: bool?
11
11
  attr_reader rag: bool?
12
12
  attr_reader raw_text: bool?
13
+ attr_reader text_context: String?
13
14
  attr_reader webhook_ids: Array[String]?
15
+ attr_reader data_schema: DataSchema?
14
16
 
15
17
  def initialize: (
16
18
  String,
@@ -19,9 +21,11 @@ module Mindee
19
21
  ?polygon: bool?,
20
22
  ?confidence: bool?,
21
23
  ?file_alias: String?,
24
+ ?text_context: String?,
22
25
  ?webhook_ids: Array[String]?,
23
26
  ?polling_options: Hash[Symbol | String, untyped] | PollingOptions?,
24
- ?close_file: bool?
27
+ ?close_file: bool?,
28
+ ?data_schema: DataSchema|String|Hash[Symbol | String, untyped]?
25
29
  ) -> void
26
30
 
27
31
  def self.from_hash: (params: Hash[String | Symbol, untyped]) -> InferenceParameters
@@ -3,7 +3,7 @@ module Mindee
3
3
  module Input
4
4
  class LocalResponse
5
5
  def file: -> StringIO
6
- def initialize: (File | IO | StringIO | String | Pathname) -> void
6
+ def initialize: (File | IO | StringIO | String | Pathname | Tempfile) -> void
7
7
  def as_hash: -> Hash[String | Symbol, untyped]
8
8
  def self.process_secret_key: (String) -> String
9
9
  def get_hmac_signature: (String) -> String
@@ -1,13 +1,22 @@
1
1
  module Mindee
2
2
  module Parsing
3
3
  module V2
4
+ class DataSchemaActiveOption
5
+ attr_reader replace: bool
6
+
7
+ def initialize: (Hash[Symbol |string, untyped]) -> void
8
+ def to_s: () -> String
9
+ end
4
10
  class InferenceActiveOptions
5
11
  attr_reader confidence: bool
6
12
  attr_reader polygon: bool
7
13
  attr_reader rag: bool
8
14
  attr_reader raw_text: bool
15
+ attr_reader text_context: bool
16
+ attr_reader data_schema: DataSchemaActiveOption
9
17
 
10
18
  def initialize: (Hash[String | Symbol, untyped]) -> void
19
+ def to_s: () -> String
11
20
  end
12
21
  end
13
22
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: mindee
3
3
  version: !ruby/object:Gem::Version
4
- version: 4.8.0
4
+ version: 4.10.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mindee, SA
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2025-11-18 00:00:00.000000000 Z
11
+ date: 2025-12-22 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: base64
@@ -293,6 +293,7 @@ files:
293
293
  - lib/mindee/image/image_extractor.rb
294
294
  - lib/mindee/image/image_utils.rb
295
295
  - lib/mindee/input.rb
296
+ - lib/mindee/input/data_schema.rb
296
297
  - lib/mindee/input/inference_parameters.rb
297
298
  - lib/mindee/input/local_response.rb
298
299
  - lib/mindee/input/polling_options.rb
@@ -574,6 +575,7 @@ files:
574
575
  - sig/mindee/image/image_compressor.rbs
575
576
  - sig/mindee/image/image_extractor.rbs
576
577
  - sig/mindee/image/image_utils.rbs
578
+ - sig/mindee/input/data_schema.rbs
577
579
  - sig/mindee/input/inference_parameters.rbs
578
580
  - sig/mindee/input/local_response.rbs
579
581
  - sig/mindee/input/polling_options.rbs