mindee 4.9.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: b3307b74c76a019147939c9d201adcf2d4b2557a9b773475f6b92407ee18f9bf
4
- data.tar.gz: 4d5f9204fc983bf1e108d1feb04bb3abded3f2d4dad62eba86d714a608af4d48
3
+ metadata.gz: a0ab40fd2712787376dff65bab0aecb06a9ecd0337aa5ffe8b0d2ed115fac2a6
4
+ data.tar.gz: 661847259c9047171d1fe198a20459afd5545b3e298b253252a8ad59f12ac3c0
5
5
  SHA512:
6
- metadata.gz: 8e712d0f2cdf6926c50513c0bd499beca98de1774067d637a0aeb915071b18d5004ba214d07f6ebb861eb8ac76e56ad5c13e960f209363bcd6ff31459cfdcacb
7
- data.tar.gz: f9b117e1087b5b89cc3d957fb150c243b2409a0fb40483df6f4279761a4cf1384905c375a973cb3d3c9d95ca7abdca49d6cc8613738ae5ae6a5374464b26e00f
6
+ metadata.gz: 9d33a23521dcc763584f92f22ca11b02dbea63d016c4f39173a15fe865805f362801bdd7f205761030524e70b65ff4f73d90d742212a49f3f21b6cf8979c5556
7
+ data.tar.gz: 19dee30dd72aa0adc05f4754f8a62b7c3299bdca7de25fda9aed315c485a11aa4878d28f3f086d9a6fed81371a599fa5c9ce3b4d883e835edd9ced77dce9b4c2
data/CHANGELOG.md CHANGED
@@ -1,5 +1,10 @@
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
+
3
8
  ## v4.9.0 - 2025-12-02
4
9
  ### Changes
5
10
  * :sparkles: add support for text_context parameter
@@ -122,6 +122,7 @@ module Mindee
122
122
  form_data.push(['confidence', params.confidence.to_s]) unless params.confidence.nil?
123
123
  form_data.push ['file_alias', params.file_alias] if params.file_alias
124
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
125
126
  unless params.webhook_ids.nil? || params.webhook_ids.empty?
126
127
  form_data.push ['webhook_ids', params.webhook_ids.join(',')]
127
128
  end
@@ -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.
@@ -35,6 +37,9 @@ module Mindee
35
37
  # @return [PollingOptions] Options for polling. Set only if having timeout issues.
36
38
  attr_reader :polling_options
37
39
 
40
+ # @return [DataSchemaField]
41
+ attr_reader :data_schema
42
+
38
43
  # @return [Boolean, nil] Whether to close the file after parsing.
39
44
  attr_reader :close_file
40
45
 
@@ -58,7 +63,8 @@ module Mindee
58
63
  webhook_ids: nil,
59
64
  text_context: nil,
60
65
  polling_options: nil,
61
- close_file: true
66
+ close_file: true,
67
+ data_schema: nil
62
68
  )
63
69
  raise Errors::MindeeInputError, 'Model ID is required.' if model_id.empty? || model_id.nil?
64
70
 
@@ -72,6 +78,7 @@ module Mindee
72
78
  @text_context = text_context
73
79
  @polling_options = get_clean_polling_options(polling_options)
74
80
  @close_file = close_file.nil? || close_file
81
+ @data_schema = DataSchema.new(data_schema) unless data_schema.nil?
75
82
  # rubocop:enable Metrics/ParameterLists
76
83
  end
77
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.
@@ -15,6 +32,8 @@ module Mindee
15
32
  attr_reader :rag
16
33
  # @return [Boolean] Whether the text context feature was activated.
17
34
  attr_reader :text_context
35
+ # @return [DataSchemaActiveOption]
36
+ attr_reader :data_schema
18
37
 
19
38
  # @param server_response [Hash] Raw JSON parsed into a Hash.
20
39
  def initialize(server_response)
@@ -23,6 +42,7 @@ module Mindee
23
42
  @confidence = server_response['confidence']
24
43
  @rag = server_response['rag']
25
44
  @text_context = server_response['text_context']
45
+ @data_schema = DataSchemaActiveOption.new(server_response['data_schema'])
26
46
  end
27
47
 
28
48
  # String representation.
@@ -35,6 +55,8 @@ module Mindee
35
55
  ":Polygon: #{@polygon ? 'True' : 'False'}",
36
56
  ":Confidence: #{@confidence ? 'True' : 'False'}",
37
57
  ":RAG: #{@rag ? 'True' : 'False'}",
58
+ ":Text Context: #{@text_context ? 'True' : 'False'}\n",
59
+ @data_schema.to_s,
38
60
  '',
39
61
  ]
40
62
  parts.join("\n")
@@ -3,7 +3,7 @@
3
3
  # Mindee
4
4
  module Mindee
5
5
  # Current version.
6
- VERSION = '4.9.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?]
@@ -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
@@ -12,6 +12,7 @@ module Mindee
12
12
  attr_reader raw_text: bool?
13
13
  attr_reader text_context: String?
14
14
  attr_reader webhook_ids: Array[String]?
15
+ attr_reader data_schema: DataSchema?
15
16
 
16
17
  def initialize: (
17
18
  String,
@@ -23,7 +24,8 @@ module Mindee
23
24
  ?text_context: String?,
24
25
  ?webhook_ids: Array[String]?,
25
26
  ?polling_options: Hash[Symbol | String, untyped] | PollingOptions?,
26
- ?close_file: bool?
27
+ ?close_file: bool?,
28
+ ?data_schema: DataSchema|String|Hash[Symbol | String, untyped]?
27
29
  ) -> void
28
30
 
29
31
  def self.from_hash: (params: Hash[String | Symbol, untyped]) -> InferenceParameters
@@ -1,14 +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
9
15
  attr_reader text_context: bool
16
+ attr_reader data_schema: DataSchemaActiveOption
10
17
 
11
18
  def initialize: (Hash[String | Symbol, untyped]) -> void
19
+ def to_s: () -> String
12
20
  end
13
21
  end
14
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.9.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-12-02 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