mindee 5.5.0 → 5.6.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/.betterleaks.toml +15 -0
- data/.editorconfig +1 -1
- data/CHANGELOG.md +6 -0
- data/CONTRIBUTING.md +11 -51
- data/bin/v1/products.rb +0 -6
- data/lib/mindee/v1/client.rb +1 -74
- data/lib/mindee/v1/http.rb +0 -1
- data/lib/mindee/v1/product.rb +0 -3
- data/lib/mindee/v2/client.rb +45 -26
- data/lib/mindee/v2/http/mindee_api_v2.rb +34 -49
- data/lib/mindee/v2/product/classification/classification_classifier.rb +5 -4
- data/lib/mindee/v2/product/crop/crop_item.rb +5 -4
- data/lib/mindee/v2/product/split/split_range.rb +5 -4
- data/lib/mindee/v2/search/models/model_search_parameters.rb +8 -5
- data/lib/mindee/version.rb +1 -1
- data/mindee.gemspec +1 -2
- data/prek.toml +45 -0
- data/sig/mindee/v1/client.rbs +1 -15
- data/sig/mindee/v2/client.rbs +4 -0
- data/sig/mindee/v2/http/mindee_api_v2.rbs +7 -9
- data/sig/mindee/v2/product/classification/classification_classifier.rbs +1 -1
- data/sig/mindee/v2/product/crop/crop_item.rbs +1 -1
- data/sig/mindee/v2/product/split/split_range.rbs +1 -1
- metadata +7 -45
- data/.git-hooks/pre_commit/gitleaks.rb +0 -19
- data/.overcommit.yml +0 -46
- data/docs/code_samples/bank_account_details_v1.txt +0 -24
- data/docs/code_samples/barcode_reader_v1.txt +0 -24
- data/docs/code_samples/idcard_fr_v1.txt +0 -24
- data/docs/code_samples/workflow_execution.txt +0 -28
- data/lib/mindee/v1/http/workflow_endpoint.rb +0 -93
- data/lib/mindee/v1/product/barcode_reader/barcode_reader_v1.rb +0 -47
- data/lib/mindee/v1/product/barcode_reader/barcode_reader_v1_document.rb +0 -47
- data/lib/mindee/v1/product/barcode_reader/barcode_reader_v1_page.rb +0 -38
- data/lib/mindee/v1/product/fr/bank_account_details/bank_account_details_v1.rb +0 -49
- data/lib/mindee/v1/product/fr/bank_account_details/bank_account_details_v1_document.rb +0 -49
- data/lib/mindee/v1/product/fr/bank_account_details/bank_account_details_v1_page.rb +0 -40
- data/lib/mindee/v1/product/fr/id_card/id_card_v1.rb +0 -49
- data/lib/mindee/v1/product/fr/id_card/id_card_v1_document.rb +0 -106
- data/lib/mindee/v1/product/fr/id_card/id_card_v1_page.rb +0 -57
- data/sig/mindee/v1/http/workflow_endpoint.rbs +0 -22
- data/sig/mindee/v1/product/barcode_reader/barcode_reader_v1.rbs +0 -13
- data/sig/mindee/v1/product/barcode_reader/barcode_reader_v1_document.rbs +0 -16
- data/sig/mindee/v1/product/barcode_reader/barcode_reader_v1_page.rbs +0 -17
- data/sig/mindee/v1/product/fr/bank_account_details/bank_account_details_v1.rbs +0 -15
- data/sig/mindee/v1/product/fr/bank_account_details/bank_account_details_v1_document.rbs +0 -19
- data/sig/mindee/v1/product/fr/bank_account_details/bank_account_details_v1_page.rbs +0 -19
- data/sig/mindee/v1/product/fr/id_card/id_card_v1.rbs +0 -15
- data/sig/mindee/v1/product/fr/id_card/id_card_v1_document.rbs +0 -26
- data/sig/mindee/v1/product/fr/id_card/id_card_v1_page.rbs +0 -20
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: f836bb72cfae4c43ad226be7bcbfc3e39606b4df6dae6ef9fece37ec0a957d4c
|
|
4
|
+
data.tar.gz: 155f5b82fe3e3fcecb17400040ad3543304b6dc6dbd94a9870ebc6b8b0dcf3bb
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 87625c60d12034c9914e18acf6cf93e226cce1a3fac810849fb73d009964e825d933e9ea370e54c89a2d43e2fb5457c50dad7aab2183ad6ccc2645806749554f
|
|
7
|
+
data.tar.gz: c5a21cefe733fadb998c5ed051754f1e8193ea9682c0cf52fa32a8c7345cd45d89e27f1b02a9b062a1713197a6f2735ca7cfa462f3cd5d131a2b25a1de610939
|
data/.betterleaks.toml
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
[extend]
|
|
2
|
+
useDefault = true
|
|
3
|
+
|
|
4
|
+
[[allowlists]]
|
|
5
|
+
description = "RBS type signatures are not secrets"
|
|
6
|
+
condition = "AND"
|
|
7
|
+
regexTarget = "match"
|
|
8
|
+
paths = ['''^sig/.*\.rbs$''']
|
|
9
|
+
regexes = ['''password:\s*String\??''']
|
|
10
|
+
|
|
11
|
+
[[allowlists]]
|
|
12
|
+
description = "Dummy HMAC secret used in LocalResponse unit tests"
|
|
13
|
+
condition = "AND"
|
|
14
|
+
paths = ['''^spec/.*\.rb$''']
|
|
15
|
+
regexes = ['''ogNjY44MhvKPGTtVsI8zG82JqWQa68woYQH''']
|
data/.editorconfig
CHANGED
data/CHANGELOG.md
CHANGED
data/CONTRIBUTING.md
CHANGED
|
@@ -123,77 +123,37 @@ bundle exec rake spec
|
|
|
123
123
|
|
|
124
124
|
## Local Quality Checks
|
|
125
125
|
|
|
126
|
-
We use [`
|
|
127
|
-
changes are committed and pushed. It is a development dependency of the gem, so `bundle install`
|
|
128
|
-
already installed it. The hooks are configured in [`.overcommit.yml`](.overcommit.yml), and
|
|
129
|
-
repository-local custom hooks live in [`.git-hooks`](.git-hooks).
|
|
126
|
+
We use [`prek`](https://prek.j178.dev/) to run quality and security checks before changes are committed and pushed.
|
|
130
127
|
|
|
131
128
|
The same checks run in CI, see
|
|
132
129
|
[`.github/workflows/_static-analysis.yml`](.github/workflows/_static-analysis.yml).
|
|
133
130
|
|
|
134
|
-
### Install `gitleaks`
|
|
135
|
-
|
|
136
|
-
The `Gitleaks` pre-commit hook shells out to the
|
|
137
|
-
[`gitleaks`](https://github.com/gitleaks/gitleaks) binary, which is not a gem and must be installed
|
|
138
|
-
separately:
|
|
139
|
-
|
|
140
|
-
```shell
|
|
141
|
-
brew install gitleaks
|
|
142
|
-
```
|
|
143
|
-
|
|
144
|
-
Otherwise, grab a binary from the
|
|
145
|
-
[releases page](https://github.com/gitleaks/gitleaks/releases) and put it on your `PATH`.
|
|
146
|
-
|
|
147
131
|
### Install the hooks
|
|
148
132
|
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
```shell
|
|
152
|
-
bundle exec overcommit --install
|
|
153
|
-
bundle exec overcommit --sign
|
|
154
|
-
bundle exec overcommit --sign pre-commit
|
|
155
|
-
```
|
|
156
|
-
|
|
157
|
-
`--install` writes the git hook stubs into `.git/hooks`, and the `--sign` calls tell overcommit you
|
|
158
|
-
trust the current contents of `.overcommit.yml` and of the custom hooks in `.git-hooks`.
|
|
133
|
+
https://prek.j178.dev/installation/
|
|
159
134
|
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
* **pre-commit:** merge conflict markers, YAML syntax, trailing whitespace, file size, `rubocop`,
|
|
163
|
-
`steep check` (type checking) and `gitleaks` (secret scanning).
|
|
164
|
-
* **pre-push:** `bundle-audit` (dependency vulnerability check).
|
|
165
|
-
|
|
166
|
-
### Run the hooks manually
|
|
135
|
+
Then install the hooks:
|
|
167
136
|
|
|
168
137
|
```shell
|
|
169
|
-
|
|
170
|
-
bundle exec overcommit --run # run the pre-commit hooks on all tracked files
|
|
171
|
-
bundle exec overcommit --run pre_push # run the pre-push hooks
|
|
172
|
-
bundle exec overcommit --diff main # run the pre-commit hooks on the diff against main
|
|
138
|
+
prek install
|
|
173
139
|
```
|
|
174
140
|
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
Skip one or more hooks for a single run, by name:
|
|
141
|
+
Now, when you run `git commit`, `prek` will automatically run the quality and security checks.
|
|
178
142
|
|
|
179
|
-
|
|
180
|
-
SKIP=Gitleaks,Steep git commit
|
|
181
|
-
```
|
|
143
|
+
### Run the hooks manually
|
|
182
144
|
|
|
183
|
-
|
|
145
|
+
If you need to run the hooks manually, use the following command:
|
|
184
146
|
|
|
185
147
|
```shell
|
|
186
|
-
|
|
148
|
+
prek run --all-files
|
|
187
149
|
```
|
|
188
150
|
|
|
189
|
-
###
|
|
151
|
+
### Skipping hooks
|
|
190
152
|
|
|
191
|
-
|
|
192
|
-
diff and then re-sign:
|
|
153
|
+
Skip one or more hooks for a single run, by ID:
|
|
193
154
|
|
|
194
155
|
```shell
|
|
195
|
-
|
|
196
|
-
bundle exec overcommit --sign pre-commit
|
|
156
|
+
PREK_SKIP=rubocop
|
|
197
157
|
```
|
|
198
158
|
|
|
199
159
|
## Styleguides
|
data/bin/v1/products.rb
CHANGED
|
@@ -7,12 +7,6 @@ V1_PRODUCTS = {
|
|
|
7
7
|
sync: true,
|
|
8
8
|
async: true,
|
|
9
9
|
},
|
|
10
|
-
'barcode-reader' => {
|
|
11
|
-
description: 'Barcode Reader',
|
|
12
|
-
doc_class: Mindee::V1::Product::BarcodeReader::BarcodeReaderV1,
|
|
13
|
-
sync: true,
|
|
14
|
-
async: false,
|
|
15
|
-
},
|
|
16
10
|
'cropper' => {
|
|
17
11
|
description: 'Cropper',
|
|
18
12
|
doc_class: Mindee::V1::Product::Cropper::CropperV1,
|
data/lib/mindee/v1/client.rb
CHANGED
|
@@ -54,39 +54,6 @@ module Mindee
|
|
|
54
54
|
end
|
|
55
55
|
end
|
|
56
56
|
|
|
57
|
-
# Class for configuration options in workflow executions.
|
|
58
|
-
#
|
|
59
|
-
# @!attribute document_alias [String, nil] Alias to give to the document.
|
|
60
|
-
# @!attribute priority [Symbol, nil] Priority to give to the document.
|
|
61
|
-
# @!attribute full_text [bool] Whether to include the full OCR text response in compatible APIs.
|
|
62
|
-
# This performs a full OCR operation on the server and may increase response time.
|
|
63
|
-
# @!attribute public_url [String, nil] A unique, encrypted URL for accessing the document validation interface
|
|
64
|
-
# without requiring authentication.
|
|
65
|
-
# @!attribute rag [bool, nil] Whether to enable Retrieval-Augmented Generation.
|
|
66
|
-
# @!attribute page_options [PageOptions, Hash, nil] Page cutting/merge options:
|
|
67
|
-
# * `:page_indexes` Zero-based list of page indexes.
|
|
68
|
-
# * `:operation` Operation to apply on the document, given the specified page indexes:
|
|
69
|
-
# * `:KEEP_ONLY` - keep only the specified pages, and remove all others.
|
|
70
|
-
# * `:REMOVE` - remove the specified pages, and keep all others.
|
|
71
|
-
# * `:on_min_pages` Apply the operation only if the document has at least this many pages.
|
|
72
|
-
# @!attribute close_file [bool, nil] Whether to close the file after sending it. Defaults to true.
|
|
73
|
-
class WorkflowOptions
|
|
74
|
-
attr_accessor :document_alias, :priority, :full_text, :public_url, :page_options, :rag, :close_file
|
|
75
|
-
|
|
76
|
-
def initialize(params: {})
|
|
77
|
-
params = params.transform_keys(&:to_sym)
|
|
78
|
-
@document_alias = params.fetch(:document_alias, nil)
|
|
79
|
-
@priority = params.fetch(:priority, nil)
|
|
80
|
-
@full_text = params.fetch(:full_text, false)
|
|
81
|
-
@public_url = params.fetch(:public_url, nil)
|
|
82
|
-
@rag = params.fetch(:rag, nil)
|
|
83
|
-
raw_page_options = params.fetch(:page_options, nil)
|
|
84
|
-
raw_page_options = PageOptions.new(params: raw_page_options) unless raw_page_options.is_a?(PageOptions)
|
|
85
|
-
@page_options = raw_page_options
|
|
86
|
-
@close_file = params.fetch(:close_file, true)
|
|
87
|
-
end
|
|
88
|
-
end
|
|
89
|
-
|
|
90
57
|
# Mindee API Client.
|
|
91
58
|
# See: https://developers.mindee.com/docs
|
|
92
59
|
class Client
|
|
@@ -219,7 +186,6 @@ module Mindee
|
|
|
219
186
|
Mindee::V1::Parsing::Common::ApiResponse.new(product_class, prediction, raw_http)
|
|
220
187
|
end
|
|
221
188
|
|
|
222
|
-
# rubocop:disable Metrics/CyclomaticComplexity
|
|
223
189
|
# Enqueue a document for async parsing and automatically try to retrieve it
|
|
224
190
|
#
|
|
225
191
|
# @param input_source [Mindee::Input::Source::LocalInputSource, Mindee::Input::Source::URLInputSource]
|
|
@@ -250,7 +216,7 @@ module Mindee
|
|
|
250
216
|
# @param endpoint [Mindee::V1::HTTP::Endpoint] Endpoint of the API.
|
|
251
217
|
# @param cancellation_token [Mindee::HTTP::CancellationToken, nil] Token for cancellation.
|
|
252
218
|
# @return [Mindee::V1::Parsing::Common::ApiResponse]
|
|
253
|
-
# rubocop:disable-next Metrics/PerceivedComplexity
|
|
219
|
+
# rubocop:disable-next Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity
|
|
254
220
|
def enqueue_and_parse(
|
|
255
221
|
input_source,
|
|
256
222
|
product_class,
|
|
@@ -294,45 +260,6 @@ module Mindee
|
|
|
294
260
|
queue_res
|
|
295
261
|
end
|
|
296
262
|
|
|
297
|
-
# rubocop:enable Metrics/CyclomaticComplexity
|
|
298
|
-
# Sends a document to a workflow.
|
|
299
|
-
#
|
|
300
|
-
# Accepts options either as a Hash or as a WorkflowOptions struct.
|
|
301
|
-
#
|
|
302
|
-
# @param input_source [Mindee::Input::Source::LocalInputSource, Mindee::Input::Source::URLInputSource]
|
|
303
|
-
# @param workflow_id [String]
|
|
304
|
-
# @param options [Hash, WorkflowOptions] Options to configure workflow behavior. Possible keys:
|
|
305
|
-
# * `document_alias` [String, nil] Alias to give to the document.
|
|
306
|
-
# * `priority` [Symbol, nil] Priority to give to the document.
|
|
307
|
-
# * `full_text` [bool] Whether to include the full OCR text response in compatible APIs.
|
|
308
|
-
# * `rag` [bool, nil] Whether to enable Retrieval-Augmented Generation.
|
|
309
|
-
#
|
|
310
|
-
# * `public_url` [String, nil] A unique, encrypted URL for accessing the document validation interface without
|
|
311
|
-
# requiring authentication.
|
|
312
|
-
# * `page_options` [Hash, nil] Page cutting/merge options:
|
|
313
|
-
# * `:page_indexes` Zero-based list of page indexes.
|
|
314
|
-
# * `:operation` Operation to apply on the document, given the `page_indexes specified:
|
|
315
|
-
# * `:KEEP_ONLY` - keep only the specified pages, and remove all others.
|
|
316
|
-
# * `:REMOVE` - remove the specified pages, and keep all others.
|
|
317
|
-
# * `:on_min_pages` Apply the operation only if document has at least this many pages.
|
|
318
|
-
# @return [Mindee::V1::Parsing::Common::WorkflowResponse]
|
|
319
|
-
def execute_workflow(input_source, workflow_id, options: {})
|
|
320
|
-
opts = options.is_a?(WorkflowOptions) ? options : WorkflowOptions.new(params: options)
|
|
321
|
-
if opts.respond_to?(:page_options) && input_source.is_a?(Input::Source::LocalInputSource)
|
|
322
|
-
process_pdf_if_required(input_source, opts)
|
|
323
|
-
end
|
|
324
|
-
|
|
325
|
-
workflow_endpoint = V1::HTTP::WorkflowEndpoint.new(workflow_id, api_key: @api_key.to_s)
|
|
326
|
-
logger.debug("Sending document to workflow '#{workflow_id}'")
|
|
327
|
-
|
|
328
|
-
prediction, raw_http = workflow_endpoint.execute_workflow(
|
|
329
|
-
input_source,
|
|
330
|
-
opts
|
|
331
|
-
)
|
|
332
|
-
|
|
333
|
-
Mindee::V1::Parsing::Common::WorkflowResponse.new(V1::Product::Universal::Universal, prediction, raw_http)
|
|
334
|
-
end
|
|
335
|
-
|
|
336
263
|
# Load a prediction.
|
|
337
264
|
#
|
|
338
265
|
# @param product_class [Mindee::Inference] class of the product
|
data/lib/mindee/v1/http.rb
CHANGED
data/lib/mindee/v1/product.rb
CHANGED
|
@@ -1,12 +1,9 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require_relative 'product/barcode_reader/barcode_reader_v1'
|
|
4
3
|
require_relative 'product/cropper/cropper_v1'
|
|
5
4
|
require_relative 'product/financial_document/financial_document_v1'
|
|
6
|
-
require_relative 'product/fr/bank_account_details/bank_account_details_v1'
|
|
7
5
|
require_relative 'product/fr/bank_account_details/bank_account_details_v2'
|
|
8
6
|
require_relative 'product/fr/bank_statement/bank_statement_v2'
|
|
9
|
-
require_relative 'product/fr/id_card/id_card_v1'
|
|
10
7
|
require_relative 'product/fr/id_card/id_card_v2'
|
|
11
8
|
require_relative 'product/international_id/international_id_v2'
|
|
12
9
|
require_relative 'product/invoice/invoice_v4'
|
data/lib/mindee/v2/client.rb
CHANGED
|
@@ -18,22 +18,7 @@ module Mindee
|
|
|
18
18
|
@mindee_api = Mindee::V2::HTTP::MindeeApiV2.new(api_key: api_key)
|
|
19
19
|
end
|
|
20
20
|
|
|
21
|
-
#
|
|
22
|
-
# @param product [Class<Mindee::V2::Product::BaseProduct>] The return class.
|
|
23
|
-
# @param resource [String] ID of the inference or URL to the result.
|
|
24
|
-
# @return [Mindee::V2::Parsing::BaseResponse]
|
|
25
|
-
def get_result(product, resource)
|
|
26
|
-
@mindee_api.req_get_result(product, resource)
|
|
27
|
-
end
|
|
28
|
-
|
|
29
|
-
# Retrieves an inference from a given queue or URL to the job.
|
|
30
|
-
# @param job_id [String] ID of the job.
|
|
31
|
-
# @return [Mindee::V2::Parsing::JobResponse]
|
|
32
|
-
def get_job(job_id)
|
|
33
|
-
@mindee_api.req_get_job(job_id)
|
|
34
|
-
end
|
|
35
|
-
|
|
36
|
-
# Enqueue a document for async parsing.
|
|
21
|
+
# Send a file to the asynchronous processing queue for inference.
|
|
37
22
|
# @param product [Class<Mindee::V2::Product::BaseProduct>] The return class.
|
|
38
23
|
# @param input_source [Mindee::Input::Source::LocalInputSource, Mindee::Input::Source::URLInputSource]
|
|
39
24
|
# The source of the input document (local file or URL).
|
|
@@ -51,8 +36,40 @@ module Mindee
|
|
|
51
36
|
@mindee_api.req_post_product_enqueue(input_source, normalized_params)
|
|
52
37
|
end
|
|
53
38
|
|
|
54
|
-
#
|
|
55
|
-
#
|
|
39
|
+
# Get the status of an inference that was previously enqueued.
|
|
40
|
+
# Can be used for polling.
|
|
41
|
+
# @param url [String] HTTPS URL to the job.
|
|
42
|
+
# @return [Mindee::V2::Parsing::JobResponse]
|
|
43
|
+
def get_job_by_url(url)
|
|
44
|
+
@mindee_api.req_get_job_by_url(url)
|
|
45
|
+
end
|
|
46
|
+
|
|
47
|
+
# Get the result of an inference that was previously enqueued.
|
|
48
|
+
# @param product [Class<Mindee::V2::Product::BaseProduct>] The return class.
|
|
49
|
+
# @param url [String] HTTPS URL to the result.
|
|
50
|
+
# @return [Mindee::V2::Parsing::BaseResponse]
|
|
51
|
+
def get_result_by_url(product, url)
|
|
52
|
+
@mindee_api.req_get_result_by_url(product, url)
|
|
53
|
+
end
|
|
54
|
+
|
|
55
|
+
# Get the result of an inference that was previously enqueued.
|
|
56
|
+
# Prefer using `get_result_by_url` using the result URL returned by the Job.
|
|
57
|
+
# @param product [Class<Mindee::V2::Product::BaseProduct>] The return class.
|
|
58
|
+
# @param resource [String] ID of the inference or URL to the result.
|
|
59
|
+
# @return [Mindee::V2::Parsing::BaseResponse]
|
|
60
|
+
def get_result(product, resource)
|
|
61
|
+
@mindee_api.req_get_result_by_id(product, resource)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# Get the status of an inference that was previously enqueued.
|
|
65
|
+
# Prefer using `get_job_by_url` with the polling URL returned by enqueue.
|
|
66
|
+
# @param job_id [String] ID of the job.
|
|
67
|
+
# @return [Mindee::V2::Parsing::JobResponse]
|
|
68
|
+
def get_job(job_id)
|
|
69
|
+
@mindee_api.req_get_job_by_id(job_id)
|
|
70
|
+
end
|
|
71
|
+
|
|
72
|
+
# Send a file to the inference queue and return the results when complete.
|
|
56
73
|
# @param product [Class<Mindee::V2::Product::BaseProduct>] The return class.
|
|
57
74
|
# @param input_source [Mindee::Input::Source::LocalInputSource, Mindee::Input::Source::URLInputSource]
|
|
58
75
|
# The source of the input document (local file or URL).
|
|
@@ -60,7 +77,7 @@ module Mindee
|
|
|
60
77
|
# @param polling_options [Hash, PollingOptions, nil] Parameters for polling.
|
|
61
78
|
# @param cancellation_token [Mindee::HTTP::CancellationToken, nil] Token for cancellation.
|
|
62
79
|
# @return [Parsing::BaseResponse]
|
|
63
|
-
# rubocop:disable-next Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
|
|
80
|
+
# rubocop:disable-next Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity, Metrics/AbcSize
|
|
64
81
|
def enqueue_and_get_result(
|
|
65
82
|
product,
|
|
66
83
|
input_source,
|
|
@@ -84,29 +101,31 @@ module Mindee
|
|
|
84
101
|
|
|
85
102
|
sleep(normalized_params.polling_options.initial_delay_sec)
|
|
86
103
|
retry_counter = 1
|
|
87
|
-
|
|
104
|
+
polling_url = enqueue_response.job.polling_url
|
|
105
|
+
|
|
106
|
+
job_response = get_job_by_url(polling_url)
|
|
88
107
|
|
|
89
108
|
while retry_counter < normalized_params.polling_options.max_retries
|
|
90
|
-
if
|
|
109
|
+
if job_response.job.status == 'Failed'
|
|
91
110
|
break
|
|
92
|
-
elsif !
|
|
93
|
-
return
|
|
111
|
+
elsif !job_response.job.result_url.nil?
|
|
112
|
+
return get_result_by_url(product, job_response.job.result_url)
|
|
94
113
|
end
|
|
95
114
|
|
|
96
115
|
logger.debug(
|
|
97
116
|
"Successfully enqueued inference with job id: #{job_id}.\n" \
|
|
98
117
|
"Attempt n°#{retry_counter}/#{normalized_params.polling_options.max_retries}.\n" \
|
|
99
|
-
"Job status: #{
|
|
118
|
+
"Job status: #{job_response.job.status}."
|
|
100
119
|
)
|
|
101
120
|
|
|
102
121
|
raise Mindee::Error::MindeeError, 'Enqueueing of the document was canceled.' if cancellation_token&.canceled?
|
|
103
122
|
|
|
104
123
|
sleep(normalized_params.polling_options.delay_sec)
|
|
105
|
-
|
|
124
|
+
job_response = get_job_by_url(polling_url)
|
|
106
125
|
retry_counter += 1
|
|
107
126
|
end
|
|
108
127
|
|
|
109
|
-
error =
|
|
128
|
+
error = job_response.job.error
|
|
110
129
|
unless error.nil?
|
|
111
130
|
err_to_raise = Mindee::Error::MindeeHTTPErrorV2.new(error)
|
|
112
131
|
# NOTE: purposefully decoupled from the line above, otherwise rubocop thinks `error` is a `message` param.
|
|
@@ -33,30 +33,44 @@ module Mindee
|
|
|
33
33
|
end
|
|
34
34
|
|
|
35
35
|
# Retrieves a result from a given queue.
|
|
36
|
-
# @param product [Class<Mindee::V2::Product::BaseProduct>]
|
|
37
|
-
# @param
|
|
36
|
+
# @param product [Class<Mindee::V2::Product::BaseProduct>]
|
|
37
|
+
# @param inference_id [String] ID of the inference or URL to the result.
|
|
38
38
|
# @return [Mindee::V2::Parsing::BaseResponse]
|
|
39
|
-
def
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
@settings.check_api_key
|
|
43
|
-
response = result_req_get(
|
|
44
|
-
resource,
|
|
45
|
-
product
|
|
46
|
-
)
|
|
47
|
-
product.response_type.new(process_response(response))
|
|
39
|
+
def req_get_result_by_id(product, inference_id)
|
|
40
|
+
req_get_result_by_url(product, "#{@settings.base_url}/v2/products/#{product.slug}/results/#{inference_id}")
|
|
48
41
|
end
|
|
49
42
|
|
|
50
43
|
# Retrieves a queued job.
|
|
51
44
|
#
|
|
52
45
|
# @param job_id [String] ID of the job or URL to the job.
|
|
53
46
|
# @return [Mindee::V2::Parsing::JobResponse]
|
|
54
|
-
def
|
|
47
|
+
def req_get_job_by_id(job_id)
|
|
48
|
+
req_get_job_by_url("#{@settings.base_url}/v2/jobs/#{job_id}")
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# Retrieves a queued job from its polling URL.
|
|
52
|
+
#
|
|
53
|
+
# @param url [String] HTTPS URL to the job.
|
|
54
|
+
# @return [Mindee::V2::Parsing::JobResponse]
|
|
55
|
+
def req_get_job_by_url(url)
|
|
56
|
+
validate_https_url!(url)
|
|
55
57
|
@settings.check_api_key
|
|
56
|
-
response = poll(
|
|
58
|
+
response = poll(url)
|
|
57
59
|
Mindee::V2::Parsing::JobResponse.new(process_response(response))
|
|
58
60
|
end
|
|
59
61
|
|
|
62
|
+
# Retrieves a result from its URL.
|
|
63
|
+
#
|
|
64
|
+
# @param product [Class<Mindee::V2::Product::BaseProduct>]
|
|
65
|
+
# @param url [String] HTTPS URL to the result.
|
|
66
|
+
# @return [Mindee::V2::Parsing::BaseResponse]
|
|
67
|
+
def req_get_result_by_url(product, url)
|
|
68
|
+
validate_https_url!(url)
|
|
69
|
+
@settings.check_api_key
|
|
70
|
+
response = poll(url)
|
|
71
|
+
product.response_type.new(process_response(response))
|
|
72
|
+
end
|
|
73
|
+
|
|
60
74
|
# Retrieves a list of resources with the given criteria.
|
|
61
75
|
# @param params [ClientOptions::BaseSearchParameters] Search parameters.
|
|
62
76
|
# @return [Mindee::V2::Parsing::Search::BaseSearchResponse] A search response containing the matching
|
|
@@ -85,35 +99,15 @@ module Mindee
|
|
|
85
99
|
|
|
86
100
|
private
|
|
87
101
|
|
|
88
|
-
#
|
|
89
|
-
# @return [Boolean]
|
|
90
|
-
def uri?(resource)
|
|
91
|
-
uri = URI.parse(resource)
|
|
92
|
-
throw Mindee::Error::MindeeError, 'HTTP is not supported.' if uri.scheme == 'http'
|
|
93
|
-
uri.scheme == 'https'
|
|
94
|
-
rescue URI::BadURIError, URI::InvalidURIError
|
|
95
|
-
false
|
|
96
|
-
end
|
|
97
|
-
|
|
98
|
-
# Retrieves a queued job.
|
|
99
|
-
#
|
|
100
|
-
# @param url [String]
|
|
101
|
-
# @return [Mindee::V2::Parsing::JobResponse]
|
|
102
|
-
def req_get_job_url(url)
|
|
103
|
-
@settings.check_api_key
|
|
104
|
-
response = poll(url)
|
|
105
|
-
Mindee::V2::Parsing::JobResponse.new(process_response(response))
|
|
106
|
-
end
|
|
107
|
-
|
|
108
|
-
# Retrieves a queued job.
|
|
102
|
+
# Validates that a URL uses HTTPS and includes a host.
|
|
109
103
|
#
|
|
110
|
-
# @param result_class [Class<Mindee::V2::Parsing::BaseResponse>]
|
|
111
104
|
# @param url [String]
|
|
112
|
-
# @return [
|
|
113
|
-
def
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
105
|
+
# @return [void]
|
|
106
|
+
def validate_https_url!(url)
|
|
107
|
+
uri = URI.parse(url)
|
|
108
|
+
raise Mindee::Error::MindeeError, "Invalid URL: #{url}" unless uri.scheme == 'https' && !uri.host.to_s.empty?
|
|
109
|
+
rescue URI::BadURIError, URI::InvalidURIError
|
|
110
|
+
raise Mindee::Error::MindeeError, "Invalid URL: #{url}"
|
|
117
111
|
end
|
|
118
112
|
|
|
119
113
|
# Converts an HTTP response to a parsed response object.
|
|
@@ -156,15 +150,6 @@ module Mindee
|
|
|
156
150
|
raise Mindee::Error::MindeeError, 'Could not resolve server response.'
|
|
157
151
|
end
|
|
158
152
|
|
|
159
|
-
# Polls the API for the result of an inference.
|
|
160
|
-
#
|
|
161
|
-
# @param queue_id [String] ID of the queue.
|
|
162
|
-
# @param product [Class<Mindee::V2::Product::BaseProduct>] The return class.
|
|
163
|
-
# @return [Net::HTTPResponse]
|
|
164
|
-
def result_req_get(queue_id, product)
|
|
165
|
-
poll("#{@settings.base_url}/v2/products/#{product.slug}/results/#{queue_id}")
|
|
166
|
-
end
|
|
167
|
-
|
|
168
153
|
# Handle parameters for the enqueue form
|
|
169
154
|
# @param form_data [Array] Array of form fields
|
|
170
155
|
# @param params [V2::Product::Extraction::Params::ExtractionParameters] Inference options.
|
|
@@ -13,10 +13,11 @@ module Mindee
|
|
|
13
13
|
# @param server_response [Hash] Hash representation of the JSON returned by the service.
|
|
14
14
|
def initialize(server_response)
|
|
15
15
|
@document_type = server_response['document_type']
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
@extraction_response = if server_response['extraction_response'].nil?
|
|
17
|
+
nil
|
|
18
|
+
else
|
|
19
|
+
V2::Product::Extraction::ExtractionResponse.new(server_response['extraction_response'])
|
|
20
|
+
end
|
|
20
21
|
end
|
|
21
22
|
|
|
22
23
|
# @return [String] String representation.
|
|
@@ -16,10 +16,11 @@ module Mindee
|
|
|
16
16
|
def initialize(server_response)
|
|
17
17
|
@object_type = server_response['object_type']
|
|
18
18
|
@location = Mindee::V2::Parsing::Field::FieldLocation.new(server_response['location'])
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
19
|
+
@extraction_response = if server_response['extraction_response'].nil?
|
|
20
|
+
nil
|
|
21
|
+
else
|
|
22
|
+
V2::Product::Extraction::ExtractionResponse.new(server_response['extraction_response'])
|
|
23
|
+
end
|
|
23
24
|
end
|
|
24
25
|
|
|
25
26
|
# String representation.
|
|
@@ -17,10 +17,11 @@ module Mindee
|
|
|
17
17
|
def initialize(server_response)
|
|
18
18
|
@page_range = server_response['page_range']
|
|
19
19
|
@document_type = server_response['document_type']
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
20
|
+
@extraction_response = if server_response['extraction_response'].nil?
|
|
21
|
+
nil
|
|
22
|
+
else
|
|
23
|
+
V2::Product::Extraction::ExtractionResponse.new(server_response['extraction_response'])
|
|
24
|
+
end
|
|
24
25
|
end
|
|
25
26
|
|
|
26
27
|
# String representation.
|
|
@@ -4,16 +4,19 @@ module Mindee
|
|
|
4
4
|
module V2
|
|
5
5
|
module Search
|
|
6
6
|
module Models
|
|
7
|
-
# Search
|
|
7
|
+
# Search for models within the organization linked to the API key.
|
|
8
|
+
# All search filters are optional.
|
|
9
|
+
# If no search filters are given, all models belonging to the organization are returned.
|
|
10
|
+
# Results are paginated.
|
|
8
11
|
class ModelSearchParameters < Mindee::V2::ClientOptions::BaseSearchParameters
|
|
9
|
-
# @return [String, nil]
|
|
12
|
+
# @return [String, nil] Filter models by partial name match, case-insensitive.
|
|
10
13
|
attr_reader :name
|
|
11
14
|
|
|
12
|
-
# @return [String, nil]
|
|
15
|
+
# @return [String, nil] Filter by an exact model type.
|
|
13
16
|
attr_reader :model_type
|
|
14
17
|
|
|
15
|
-
# @param name [String, nil]
|
|
16
|
-
# @param model_type [String, nil]
|
|
18
|
+
# @param name [String, nil] Filter models by partial name match, case-insensitive.
|
|
19
|
+
# @param model_type [String, nil] Filter by an exact model type.
|
|
17
20
|
# @param page [Integer, nil] 1-based page index.
|
|
18
21
|
# @param per_page [Integer, nil] Number of items per page.
|
|
19
22
|
def initialize(name: nil, model_type: nil, page: nil, per_page: nil)
|
data/lib/mindee/version.rb
CHANGED
data/mindee.gemspec
CHANGED
|
@@ -37,9 +37,8 @@ Gem::Specification.new do |spec|
|
|
|
37
37
|
spec.add_dependency 'pdf-reader', '~> 2.15'
|
|
38
38
|
|
|
39
39
|
spec.add_development_dependency 'bundle-audit', '~> 0.2.0'
|
|
40
|
-
spec.add_development_dependency 'overcommit', '~> 0.71'
|
|
41
40
|
spec.add_development_dependency 'rbs', '~> 3.10'
|
|
42
|
-
spec.add_development_dependency 'rubocop', '~> 1.
|
|
41
|
+
spec.add_development_dependency 'rubocop', '~> 1.91.0'
|
|
43
42
|
spec.add_development_dependency 'steep', '~> 1.10'
|
|
44
43
|
spec.add_development_dependency 'yard', '~> 0.9'
|
|
45
44
|
end
|
data/prek.toml
ADDED
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# Configuration file for `prek`, a git hook framework written in Rust.
|
|
2
|
+
# See https://prek.j178.dev for more information.
|
|
3
|
+
#:schema https://www.schemastore.org/prek.json
|
|
4
|
+
|
|
5
|
+
[[repos]]
|
|
6
|
+
repo = "builtin"
|
|
7
|
+
hooks = [
|
|
8
|
+
{ id = "trailing-whitespace" },
|
|
9
|
+
{ id = "check-yaml" },
|
|
10
|
+
{ id = "check-merge-conflict" },
|
|
11
|
+
{ id = "check-added-large-files", args = ["--maxkb=1024"] },
|
|
12
|
+
]
|
|
13
|
+
|
|
14
|
+
[[repos]]
|
|
15
|
+
repo = "https://github.com/betterleaks/betterleaks"
|
|
16
|
+
rev = "v1.9.0"
|
|
17
|
+
hooks = [
|
|
18
|
+
{ id = "betterleaks" },
|
|
19
|
+
]
|
|
20
|
+
|
|
21
|
+
[[repos]]
|
|
22
|
+
repo = "local"
|
|
23
|
+
hooks = [
|
|
24
|
+
{
|
|
25
|
+
id = "rubocop",
|
|
26
|
+
name = "RuboCop",
|
|
27
|
+
entry = "bundle exec rubocop --force-exclusion --no-server",
|
|
28
|
+
language = "system",
|
|
29
|
+
types = ["ruby"]
|
|
30
|
+
},
|
|
31
|
+
{
|
|
32
|
+
id = "steep-check",
|
|
33
|
+
name = "Run Steep type checking",
|
|
34
|
+
entry = "bundle exec steep check",
|
|
35
|
+
language = "system",
|
|
36
|
+
pass_filenames = false
|
|
37
|
+
},
|
|
38
|
+
{
|
|
39
|
+
id = "bundle-audit",
|
|
40
|
+
name = "bundle-audit",
|
|
41
|
+
entry = "bundle exec bundle-audit check",
|
|
42
|
+
language = "system",
|
|
43
|
+
pass_filenames = false
|
|
44
|
+
},
|
|
45
|
+
]
|