mindee-lite 5.3.1 → 5.4.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 +4 -4
- data/CHANGELOG.md +6 -0
- data/lib/mindee/http/cancellation_token.rb +24 -0
- data/lib/mindee/http.rb +1 -0
- data/lib/mindee/v1/client.rb +16 -1
- data/lib/mindee/v2/client.rb +9 -1
- data/lib/mindee/v2/parsing/field/field_confidence.rb +37 -2
- data/lib/mindee/version.rb +1 -1
- data/sig/mindee/http/cancellation_token.rbs +15 -0
- data/sig/mindee/v2/parsing/field/field_confidence.rbs +9 -0
- metadata +4 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 5847f9a9f62853290ae96d8a311c66af32cbf5e1f74da6f0e7d0b455a76ae931
|
|
4
|
+
data.tar.gz: 5fbbd21a967ff60ddc059fa9ed9d5f3fd7422890e3f3675d38347f82a5463da8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: a238ed199069908c8fe5488de1af41436650f77288685297f5da4d5b1cec5c617dfa76c843b6b02efd63fa617b8dc7f80872593d63f1f7b854fce886aa6bd327
|
|
7
|
+
data.tar.gz: c2845fc9b049a1b123b15678e4effdfb55f382650cb9eecc90244ec553a78679dd1523226e8826a5e3abfbcc95bff85c790aeabcde10d36696cffa977594e3c4
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# Mindee Ruby API Library Changelog
|
|
2
2
|
|
|
3
|
+
## v5.4.0 - 2026-07-21
|
|
4
|
+
### Changes
|
|
5
|
+
* :sparkles: add field confidence comparators
|
|
6
|
+
* :sparkles: add support for cancellation token
|
|
7
|
+
|
|
8
|
+
|
|
3
9
|
## v5.3.1 - 2026-07-15
|
|
4
10
|
### Fixes
|
|
5
11
|
* :bug: fix file alias being sent as an invalid parameter
|
|
@@ -0,0 +1,24 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module Mindee
|
|
4
|
+
module HTTP
|
|
5
|
+
# Custom cancellation token class for polling.
|
|
6
|
+
class CancellationToken
|
|
7
|
+
private attr_reader :is_canceled
|
|
8
|
+
|
|
9
|
+
def initialize
|
|
10
|
+
@is_cancelled = false
|
|
11
|
+
end
|
|
12
|
+
|
|
13
|
+
# Cancel the token.
|
|
14
|
+
def cancel
|
|
15
|
+
@is_cancelled = true
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# Check if the token is canceled.
|
|
19
|
+
def canceled?
|
|
20
|
+
@is_cancelled
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
end
|
|
24
|
+
end
|
data/lib/mindee/http.rb
CHANGED
data/lib/mindee/v1/client.rb
CHANGED
|
@@ -219,6 +219,7 @@ module Mindee
|
|
|
219
219
|
Mindee::V1::Parsing::Common::ApiResponse.new(product_class, prediction, raw_http)
|
|
220
220
|
end
|
|
221
221
|
|
|
222
|
+
# rubocop:disable Metrics/CyclomaticComplexity
|
|
222
223
|
# Enqueue a document for async parsing and automatically try to retrieve it
|
|
223
224
|
#
|
|
224
225
|
# @param input_source [Mindee::Input::Source::LocalInputSource, Mindee::Input::Source::URLInputSource]
|
|
@@ -247,13 +248,23 @@ module Mindee
|
|
|
247
248
|
# * `:delay_sec` [Numeric] Delay between polling attempts. Defaults to 1.5.
|
|
248
249
|
# * `:max_retries` [Integer] Maximum number of retries. Defaults to 80.
|
|
249
250
|
# @param endpoint [Mindee::V1::HTTP::Endpoint] Endpoint of the API.
|
|
251
|
+
# @param cancellation_token [Mindee::HTTP::CancellationToken, nil] Token for cancellation.
|
|
250
252
|
# @return [Mindee::V1::Parsing::Common::ApiResponse]
|
|
251
|
-
|
|
253
|
+
# rubocop:disable Metrics/PerceivedComplexity
|
|
254
|
+
def enqueue_and_parse(
|
|
255
|
+
input_source,
|
|
256
|
+
product_class,
|
|
257
|
+
endpoint,
|
|
258
|
+
options,
|
|
259
|
+
cancellation_token = nil
|
|
260
|
+
)
|
|
252
261
|
validate_async_params(options.initial_delay_sec, options.delay_sec, options.max_retries)
|
|
253
262
|
enqueue_res = enqueue(input_source, product_class, endpoint: endpoint, options: options)
|
|
254
263
|
job = enqueue_res.job or raise Error::MindeeAPIError, 'Expected job to be present'
|
|
255
264
|
job_id = job.id
|
|
256
265
|
|
|
266
|
+
raise Mindee::Error::MindeeError, 'Enqueueing of the document was canceled.' if cancellation_token&.canceled?
|
|
267
|
+
|
|
257
268
|
sleep(options.initial_delay_sec)
|
|
258
269
|
polling_attempts = 1
|
|
259
270
|
logger.debug("Successfully enqueued document with job id: '#{job_id}'")
|
|
@@ -266,6 +277,8 @@ module Mindee
|
|
|
266
277
|
# @type var valid_statuses: Array[(:waiting | :processing | :completed | :failed)]
|
|
267
278
|
while valid_statuses.include?(queue_res_job.status) && polling_attempts < options.max_retries
|
|
268
279
|
logger.debug("Polling server for parsing result with job id: '#{job_id}'. Attempt #{polling_attempts}")
|
|
280
|
+
raise Mindee::Error::MindeeError, 'Enqueueing of the document was canceled.' if cancellation_token&.canceled?
|
|
281
|
+
|
|
269
282
|
sleep(options.delay_sec)
|
|
270
283
|
queue_res = parse_queued(job_id, product_class, endpoint: endpoint)
|
|
271
284
|
queue_res_job = queue_res.job or raise Error::MindeeAPIError, 'Expected job to be present'
|
|
@@ -280,7 +293,9 @@ module Mindee
|
|
|
280
293
|
|
|
281
294
|
queue_res
|
|
282
295
|
end
|
|
296
|
+
# rubocop:enable Metrics/PerceivedComplexity
|
|
283
297
|
|
|
298
|
+
# rubocop:enable Metrics/CyclomaticComplexity
|
|
284
299
|
# Sends a document to a workflow.
|
|
285
300
|
#
|
|
286
301
|
# Accepts options either as a Hash or as a WorkflowOptions struct.
|
data/lib/mindee/v2/client.rb
CHANGED
|
@@ -58,12 +58,15 @@ module Mindee
|
|
|
58
58
|
# The source of the input document (local file or URL).
|
|
59
59
|
# @param params [Hash, Input::BaseParameters] Parameters for the inference.
|
|
60
60
|
# @param polling_options [Hash, PollingOptions, nil] Parameters for polling.
|
|
61
|
+
# @param cancellation_token [Mindee::HTTP::CancellationToken, nil] Token for cancellation.
|
|
61
62
|
# @return [Parsing::BaseResponse]
|
|
63
|
+
# rubocop:disable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
|
62
64
|
def enqueue_and_get_result(
|
|
63
65
|
product,
|
|
64
66
|
input_source,
|
|
65
67
|
params,
|
|
66
|
-
polling_options = nil
|
|
68
|
+
polling_options = nil,
|
|
69
|
+
cancellation_token = nil
|
|
67
70
|
)
|
|
68
71
|
enqueue_response = enqueue(product, input_source, params)
|
|
69
72
|
normalized_params = normalize_parameters(product.params_type, params, polling_options: polling_options)
|
|
@@ -77,6 +80,8 @@ module Mindee
|
|
|
77
80
|
job_id = enqueue_response.job.id
|
|
78
81
|
logger.debug("Successfully enqueued document with job id: #{job_id}.")
|
|
79
82
|
|
|
83
|
+
raise Mindee::Error::MindeeError, 'Enqueueing of the document was canceled.' if cancellation_token&.canceled?
|
|
84
|
+
|
|
80
85
|
sleep(normalized_params.polling_options.initial_delay_sec)
|
|
81
86
|
retry_counter = 1
|
|
82
87
|
poll_results = get_job(job_id)
|
|
@@ -94,6 +99,8 @@ module Mindee
|
|
|
94
99
|
"Job status: #{poll_results.job.status}."
|
|
95
100
|
)
|
|
96
101
|
|
|
102
|
+
raise Mindee::Error::MindeeError, 'Enqueueing of the document was canceled.' if cancellation_token&.canceled?
|
|
103
|
+
|
|
97
104
|
sleep(normalized_params.polling_options.delay_sec)
|
|
98
105
|
poll_results = get_job(job_id)
|
|
99
106
|
retry_counter += 1
|
|
@@ -110,6 +117,7 @@ module Mindee
|
|
|
110
117
|
raise Mindee::Error::MindeeError,
|
|
111
118
|
"Asynchronous parsing request timed out after #{sec_count} seconds"
|
|
112
119
|
end
|
|
120
|
+
# rubocop:enable Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
|
113
121
|
|
|
114
122
|
# Searches for a list of available models for the given API key.
|
|
115
123
|
# @param model_name [String]
|
|
@@ -87,8 +87,8 @@ module Mindee
|
|
|
87
87
|
end
|
|
88
88
|
end
|
|
89
89
|
|
|
90
|
-
#
|
|
91
|
-
#
|
|
90
|
+
# Less than or equality of two FieldConfidence instances.
|
|
91
|
+
# @param other [String, Integer, FieldConfidence] The other confidence to compare.
|
|
92
92
|
def <=(other)
|
|
93
93
|
if other.is_a?(FieldConfidence)
|
|
94
94
|
to_i <= val_to_i(other.value)
|
|
@@ -101,12 +101,47 @@ module Mindee
|
|
|
101
101
|
end
|
|
102
102
|
end
|
|
103
103
|
|
|
104
|
+
# Greater than comparison of two FieldConfidence instances.
|
|
105
|
+
# @param other [String, Integer, FieldConfidence] The other confidence to compare.
|
|
106
|
+
def >(other)
|
|
107
|
+
if other.is_a?(FieldConfidence)
|
|
108
|
+
to_i > val_to_i(other.value)
|
|
109
|
+
elsif other.is_a?(String)
|
|
110
|
+
to_i > val_to_i(other)
|
|
111
|
+
elsif other.is_a?(Integer)
|
|
112
|
+
to_i > other
|
|
113
|
+
else
|
|
114
|
+
raise ArgumentError, "Invalid type: #{other.class}"
|
|
115
|
+
end
|
|
116
|
+
end
|
|
117
|
+
|
|
118
|
+
# Less than comparison of two FieldConfidence instances.
|
|
119
|
+
# @param other [String, Integer, FieldConfidence] The other confidence to compare.
|
|
120
|
+
def <(other)
|
|
121
|
+
if other.is_a?(FieldConfidence)
|
|
122
|
+
to_i < val_to_i(other.value)
|
|
123
|
+
elsif other.is_a?(String)
|
|
124
|
+
to_i < val_to_i(other)
|
|
125
|
+
elsif other.is_a?(Integer)
|
|
126
|
+
to_i < other
|
|
127
|
+
else
|
|
128
|
+
raise ArgumentError, "Invalid type: #{other.class}"
|
|
129
|
+
end
|
|
130
|
+
end
|
|
131
|
+
|
|
104
132
|
# rubocop:enable Style/CaseLikeIf
|
|
105
133
|
|
|
106
134
|
# Aliases for the comparison operators.
|
|
107
135
|
alias eql? ==
|
|
136
|
+
alias equal? ==
|
|
108
137
|
alias gteql? >=
|
|
138
|
+
alias greater_than_or_equal? >=
|
|
109
139
|
alias lteql? <=
|
|
140
|
+
alias less_than_or_equal? <=
|
|
141
|
+
alias gt? >
|
|
142
|
+
alias greater_than? >
|
|
143
|
+
alias lt? <
|
|
144
|
+
alias less_than? <
|
|
110
145
|
|
|
111
146
|
protected
|
|
112
147
|
|
data/lib/mindee/version.rb
CHANGED
|
@@ -20,6 +20,15 @@ module Mindee
|
|
|
20
20
|
def lteql? : (String | Integer | FieldConfidence) -> bool
|
|
21
21
|
def >=: (String | Integer | FieldConfidence) -> bool
|
|
22
22
|
def gteql?: (String | Integer | FieldConfidence) -> bool
|
|
23
|
+
def greater_than_or_equal?: (String | Integer | FieldConfidence) -> bool
|
|
24
|
+
def >: (String | Integer | FieldConfidence) -> bool
|
|
25
|
+
def gt?: (String | Integer | FieldConfidence) -> bool
|
|
26
|
+
def greater_than?: (String | Integer | FieldConfidence) -> bool
|
|
27
|
+
def <: (String | Integer | FieldConfidence) -> bool
|
|
28
|
+
def lt?: (String | Integer | FieldConfidence) -> bool
|
|
29
|
+
def less_than?: (String | Integer | FieldConfidence) -> bool
|
|
30
|
+
def less_than_or_equal?: (String | Integer | FieldConfidence) -> bool
|
|
31
|
+
def equal?: (String | Integer | FieldConfidence) -> bool
|
|
23
32
|
def inspect: -> String
|
|
24
33
|
|
|
25
34
|
def val_to_i: (String) -> Integer
|
metadata
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: mindee-lite
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 5.
|
|
4
|
+
version: 5.4.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: 2026-07-
|
|
11
|
+
date: 2026-07-21 00:00:00.000000000 Z
|
|
12
12
|
dependencies:
|
|
13
13
|
- !ruby/object:Gem::Dependency
|
|
14
14
|
name: base64
|
|
@@ -130,6 +130,7 @@ files:
|
|
|
130
130
|
- lib/mindee/geometry/utils.rb
|
|
131
131
|
- lib/mindee/http.rb
|
|
132
132
|
- lib/mindee/http/.rubocop.yml
|
|
133
|
+
- lib/mindee/http/cancellation_token.rb
|
|
133
134
|
- lib/mindee/http/http_error_handler.rb
|
|
134
135
|
- lib/mindee/http/response_validation.rb
|
|
135
136
|
- lib/mindee/image.rb
|
|
@@ -374,6 +375,7 @@ files:
|
|
|
374
375
|
- sig/mindee/geometry/polygon.rbs
|
|
375
376
|
- sig/mindee/geometry/quadrilateral.rbs
|
|
376
377
|
- sig/mindee/geometry/utils.rbs
|
|
378
|
+
- sig/mindee/http/cancellation_token.rbs
|
|
377
379
|
- sig/mindee/http/http_error_handler.rbs
|
|
378
380
|
- sig/mindee/http/response_validation.rbs
|
|
379
381
|
- sig/mindee/image/extracted_image.rbs
|