mindee 4.12.0 → 4.13.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/.gitignore +2 -0
- data/.rubocop.yml +1 -1
- data/CHANGELOG.md +13 -0
- data/docs/code_samples/v2_classification.txt +30 -0
- data/docs/code_samples/v2_crop.txt +30 -0
- data/docs/code_samples/{default_v2.txt → v2_extraction.txt} +7 -5
- data/docs/code_samples/v2_extraction_webhook.txt +45 -0
- data/docs/code_samples/v2_ocr.txt +30 -0
- data/docs/code_samples/v2_split.txt +30 -0
- data/lib/mindee/client_v2.rb +69 -17
- data/lib/mindee/errors/mindee_http_error_v2.rb +2 -2
- data/lib/mindee/geometry/point.rb +5 -0
- data/lib/mindee/geometry/polygon.rb +5 -0
- data/lib/mindee/http/mindee_api_v2.rb +62 -12
- data/lib/mindee/input/base_parameters.rb +146 -0
- data/lib/mindee/input/inference_parameters.rb +48 -91
- data/lib/mindee/input/local_response.rb +5 -4
- data/lib/mindee/parsing/v2/field/field_location.rb +1 -1
- data/lib/mindee/parsing/v2/inference.rb +8 -21
- data/lib/mindee/parsing/v2/inference_response.rb +5 -2
- data/lib/mindee/v2/parsing/base_inference.rb +44 -0
- data/lib/mindee/v2/parsing/base_response.rb +13 -0
- data/lib/mindee/v2/product/base_product.rb +27 -0
- data/lib/mindee/v2/product/classification/classification.rb +19 -0
- data/lib/mindee/v2/product/classification/classification_classifier.rb +25 -0
- data/lib/mindee/v2/product/classification/classification_inference.rb +34 -0
- data/lib/mindee/v2/product/classification/classification_response.rb +32 -0
- data/lib/mindee/v2/product/classification/classification_result.rb +27 -0
- data/lib/mindee/v2/product/classification/params/classification_parameters.rb +46 -0
- data/lib/mindee/v2/product/crop/crop.rb +19 -0
- data/lib/mindee/v2/product/crop/crop_inference.rb +34 -0
- data/lib/mindee/v2/product/crop/crop_item.rb +29 -0
- data/lib/mindee/v2/product/crop/crop_response.rb +32 -0
- data/lib/mindee/v2/product/crop/crop_result.rb +34 -0
- data/lib/mindee/v2/product/crop/params/crop_parameters.rb +46 -0
- data/lib/mindee/v2/product/extraction/extraction.rb +19 -0
- data/lib/mindee/v2/product/extraction/extraction_inference.rb +25 -0
- data/lib/mindee/v2/product/extraction/extraction_response.rb +23 -0
- data/lib/mindee/v2/product/extraction/extraction_result.rb +15 -0
- data/lib/mindee/v2/product/extraction/params/extraction_parameters.rb +18 -0
- data/lib/mindee/v2/product/ocr/ocr.rb +19 -0
- data/lib/mindee/v2/product/ocr/ocr_inference.rb +34 -0
- data/lib/mindee/v2/product/ocr/ocr_page.rb +33 -0
- data/lib/mindee/v2/product/ocr/ocr_response.rb +32 -0
- data/lib/mindee/v2/product/ocr/ocr_result.rb +34 -0
- data/lib/mindee/v2/product/ocr/ocr_word.rb +29 -0
- data/lib/mindee/v2/product/ocr/params/ocr_parameters.rb +46 -0
- data/lib/mindee/v2/product/split/params/split_parameters.rb +46 -0
- data/lib/mindee/v2/product/split/split.rb +19 -0
- data/lib/mindee/v2/product/split/split_inference.rb +34 -0
- data/lib/mindee/v2/product/split/split_range.rb +30 -0
- data/lib/mindee/v2/product/split/split_response.rb +32 -0
- data/lib/mindee/v2/product/split/split_result.rb +34 -0
- data/lib/mindee/v2/product.rb +7 -0
- data/lib/mindee/v2.rb +4 -0
- data/lib/mindee/version.rb +1 -1
- data/lib/mindee.rb +7 -0
- data/sig/mindee/client_v2.rbs +11 -7
- data/sig/mindee/errors/mindee_http_error_v2.rbs +1 -1
- data/sig/mindee/geometry/point.rbs +2 -0
- data/sig/mindee/geometry/polygon.rbs +2 -0
- data/sig/mindee/http/mindee_api_v2.rbs +20 -4
- data/sig/mindee/input/base_parameters.rbs +35 -0
- data/sig/mindee/input/inference_parameters.rbs +4 -12
- data/sig/mindee/input/local_response.rbs +2 -2
- data/sig/mindee/parsing/v2/inference.rbs +4 -5
- data/sig/mindee/parsing/v2/inference_response.rbs +11 -2
- data/sig/mindee/v2/parsing/base_inference.rbs +18 -0
- data/sig/mindee/v2/parsing/base_response.rbs +11 -0
- data/sig/mindee/v2/product/base_product.rbs +19 -0
- data/sig/mindee/v2/product/classification/classification.rbs +10 -0
- data/sig/mindee/v2/product/classification/classification_classifier.rbs +15 -0
- data/sig/mindee/v2/product/classification/classification_inference.rbs +15 -0
- data/sig/mindee/v2/product/classification/classification_response.rbs +23 -0
- data/sig/mindee/v2/product/classification/classification_result.rbs +15 -0
- data/sig/mindee/v2/product/classification/params/classification_parameters/classification_parameters.rbs +23 -0
- data/sig/mindee/v2/product/crop/crop.rbs +10 -0
- data/sig/mindee/v2/product/crop/crop_inference.rbs +14 -0
- data/sig/mindee/v2/product/crop/crop_item.rbs +15 -0
- data/sig/mindee/v2/product/crop/crop_response.rbs +23 -0
- data/sig/mindee/v2/product/crop/crop_result.rbs +14 -0
- data/sig/mindee/v2/product/crop/params/crop_parameters/crop_parameters.rbs +23 -0
- data/sig/mindee/v2/product/extraction/extraction.rbs +12 -0
- data/sig/mindee/v2/product/extraction/extraction_inference.rbs +14 -0
- data/sig/mindee/v2/product/extraction/extraction_response.rbs +18 -0
- data/sig/mindee/v2/product/extraction/extraction_result.rbs +10 -0
- data/sig/mindee/v2/product/extraction/params/extraction_parameters.rbs +12 -0
- data/sig/mindee/v2/product/ocr/ocr.rbs +10 -0
- data/sig/mindee/v2/product/ocr/ocr_inference.rbs +14 -0
- data/sig/mindee/v2/product/ocr/ocr_page.rbs +15 -0
- data/sig/mindee/v2/product/ocr/ocr_response.rbs +23 -0
- data/sig/mindee/v2/product/ocr/ocr_result.rbs +14 -0
- data/sig/mindee/v2/product/ocr/ocr_word.rbs +15 -0
- data/sig/mindee/v2/product/ocr/params/ocr_parameters/ocr_parameters.rbs +24 -0
- data/sig/mindee/v2/product/split/params/split_parameters/split_parameters.rbs +23 -0
- data/sig/mindee/v2/product/split/split.rbs +10 -0
- data/sig/mindee/v2/product/split/split_inference.rbs +14 -0
- data/sig/mindee/v2/product/split/split_range.rbs +15 -0
- data/sig/mindee/v2/product/split/split_response.rbs +23 -0
- data/sig/mindee/v2/product/split/split_result.rbs +14 -0
- metadata +78 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 8e4f8318f4cd6905b0b6b0085cbf9408bee1fe3445cab4b131415d21b7e4edad
|
|
4
|
+
data.tar.gz: 013a22e77863832af297cb477fac58225372d88e5eae7ea07761e310f3d0bfb0
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 0cae355f24d35edf36b1decb45131efeb7655a3e0a5d92938007086f1ec3d5f93dbc6e5ef96018fc20fb079ad42f91e8659848f7cf40e57add8e2547436ea662
|
|
7
|
+
data.tar.gz: f2e4b632ec7ded0cd42b8ff3d66ca066034d201d398fd46833a123c17e4b342c55fb533379234bff325b5a6bb2e24a64252b2988aaae2eafc79a2a03f1136811
|
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,18 @@
|
|
|
1
1
|
# Mindee Ruby API Library Changelog
|
|
2
2
|
|
|
3
|
+
## v4.13.0 - 2026-03-03
|
|
4
|
+
### Changes
|
|
5
|
+
* :sparkles: add support for V2 Classification product
|
|
6
|
+
* :sparkles: add support for V2 Crop product
|
|
7
|
+
* :sparkles: add support for V2 Ocr product
|
|
8
|
+
* :sparkles: add support for V2 Split product
|
|
9
|
+
* :recycle: make polling follow API urls instead of re-constructing them
|
|
10
|
+
* :sparkles: add support for generic product accessors in V2
|
|
11
|
+
* :recycle: add proper tests for ruby 4
|
|
12
|
+
### Fixes
|
|
13
|
+
* :recycle: fix tests file paths
|
|
14
|
+
|
|
15
|
+
|
|
3
16
|
## v4.12.0 - 2026-02-25
|
|
4
17
|
### Changes
|
|
5
18
|
* :sparkles: add job information to inference
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'mindee'
|
|
4
|
+
require 'mindee/v2/product'
|
|
5
|
+
|
|
6
|
+
input_path = '/path/to/the/file.ext'
|
|
7
|
+
api_key = 'MY_API_KEY'
|
|
8
|
+
model_id = 'MY_MODEL_ID'
|
|
9
|
+
|
|
10
|
+
# Init a new client
|
|
11
|
+
mindee_client = Mindee::ClientV2.new(api_key: api_key)
|
|
12
|
+
|
|
13
|
+
# Set inference parameters
|
|
14
|
+
classification_params = {
|
|
15
|
+
# ID of the model, required.
|
|
16
|
+
model_id: model_id,
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
# Load a file from disk
|
|
20
|
+
input_source = Mindee::Input::Source::PathInputSource.new(input_path)
|
|
21
|
+
|
|
22
|
+
# Send for processing
|
|
23
|
+
response = mindee_client.enqueue_and_get_result(
|
|
24
|
+
Mindee::V2::Product::Classification::Classification,
|
|
25
|
+
input_source,
|
|
26
|
+
classification_params
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
# Access the classification result
|
|
30
|
+
puts response.inference.result.classification
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'mindee'
|
|
4
|
+
require 'mindee/v2/product'
|
|
5
|
+
|
|
6
|
+
input_path = '/path/to/the/file.ext'
|
|
7
|
+
api_key = 'MY_API_KEY'
|
|
8
|
+
model_id = 'MY_MODEL_ID'
|
|
9
|
+
|
|
10
|
+
# Init a new client
|
|
11
|
+
mindee_client = Mindee::ClientV2.new(api_key: api_key)
|
|
12
|
+
|
|
13
|
+
# Set inference parameters
|
|
14
|
+
crop_params = {
|
|
15
|
+
# ID of the model, required.
|
|
16
|
+
model_id: model_id,
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
# Load a file from disk
|
|
20
|
+
input_source = Mindee::Input::Source::PathInputSource.new(input_path)
|
|
21
|
+
|
|
22
|
+
# Send for processing
|
|
23
|
+
response = mindee_client.enqueue_and_get_result(
|
|
24
|
+
Mindee::V2::Product::Crop::Crop,
|
|
25
|
+
input_source,
|
|
26
|
+
crop_params
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
# Access the result crops
|
|
30
|
+
puts response.inference.result.crops
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
require 'mindee'
|
|
4
|
+
require 'mindee/v2/product'
|
|
4
5
|
|
|
5
6
|
input_path = '/path/to/the/file.ext'
|
|
6
7
|
api_key = 'MY_API_KEY'
|
|
@@ -10,9 +11,9 @@ model_id = 'MY_MODEL_ID'
|
|
|
10
11
|
mindee_client = Mindee::ClientV2.new(api_key: api_key)
|
|
11
12
|
|
|
12
13
|
# Set inference parameters
|
|
13
|
-
inference_params =
|
|
14
|
+
inference_params = {
|
|
14
15
|
# ID of the model, required.
|
|
15
|
-
model_id,
|
|
16
|
+
model_id: model_id,
|
|
16
17
|
|
|
17
18
|
# Options: set to `true` or `false` to override defaults
|
|
18
19
|
|
|
@@ -25,15 +26,16 @@ inference_params = Mindee::Input::InferenceParameters.new(
|
|
|
25
26
|
# Boost the precision and accuracy of all extractions.
|
|
26
27
|
# Calculate confidence scores for all fields.
|
|
27
28
|
confidence: nil
|
|
28
|
-
|
|
29
|
+
}
|
|
29
30
|
|
|
30
31
|
# Load a file from disk
|
|
31
32
|
input_source = Mindee::Input::Source::PathInputSource.new(input_path)
|
|
32
33
|
|
|
33
34
|
# Send for processing
|
|
34
|
-
response = mindee_client.
|
|
35
|
+
response = mindee_client.enqueue_and_get_result(
|
|
36
|
+
Mindee::V2::Product::Extraction::Extraction,
|
|
35
37
|
input_source,
|
|
36
|
-
inference_params
|
|
38
|
+
inference_params
|
|
37
39
|
)
|
|
38
40
|
|
|
39
41
|
# Print a brief summary of the parsed data
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'mindee'
|
|
4
|
+
require 'mindee/v2/product'
|
|
5
|
+
|
|
6
|
+
input_path = '/path/to/the/file.ext'
|
|
7
|
+
api_key = 'MY_API_KEY'
|
|
8
|
+
model_id = 'MY_MODEL_ID'
|
|
9
|
+
|
|
10
|
+
# Init a new client
|
|
11
|
+
mindee_client = Mindee::ClientV2.new(api_key: api_key)
|
|
12
|
+
|
|
13
|
+
inference_params = {
|
|
14
|
+
# ID of the model, required.
|
|
15
|
+
model_id: model_id,
|
|
16
|
+
# Add any number of webhook IDs here.
|
|
17
|
+
webhook_ids: ['MY_WEBHOOK_ID'],
|
|
18
|
+
|
|
19
|
+
# Options: set to `true` or `false` to override defaults
|
|
20
|
+
|
|
21
|
+
# Enhance extraction accuracy with Retrieval-Augmented Generation.
|
|
22
|
+
rag: nil,
|
|
23
|
+
# Extract the full text content from the document as strings.
|
|
24
|
+
raw_text: nil,
|
|
25
|
+
# Calculate bounding box polygons for all fields.
|
|
26
|
+
polygon: nil,
|
|
27
|
+
# Boost the precision and accuracy of all extractions.
|
|
28
|
+
# Calculate confidence scores for all fields.
|
|
29
|
+
confidence: nil
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
# Load a file from disk
|
|
33
|
+
input_source = Mindee::Input::Source::PathInputSource.new(input_path)
|
|
34
|
+
|
|
35
|
+
# Send for processing
|
|
36
|
+
response = mindee_client.enqueue(
|
|
37
|
+
Mindee::V2::Product::Extraction::Extraction,
|
|
38
|
+
input_source,
|
|
39
|
+
inference_params
|
|
40
|
+
)
|
|
41
|
+
|
|
42
|
+
# Print the job ID
|
|
43
|
+
job_id = response.job.id
|
|
44
|
+
|
|
45
|
+
puts job_id
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'mindee'
|
|
4
|
+
require 'mindee/v2/product'
|
|
5
|
+
|
|
6
|
+
input_path = '/path/to/the/file.ext'
|
|
7
|
+
api_key = 'MY_API_KEY'
|
|
8
|
+
model_id = 'MY_MODEL_ID'
|
|
9
|
+
|
|
10
|
+
# Init a new client
|
|
11
|
+
mindee_client = Mindee::ClientV2.new(api_key: api_key)
|
|
12
|
+
|
|
13
|
+
# Set inference parameters
|
|
14
|
+
ocr_params = {
|
|
15
|
+
# ID of the model, required.
|
|
16
|
+
model_id: model_id,
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
# Load a file from disk
|
|
20
|
+
input_source = Mindee::Input::Source::PathInputSource.new(input_path)
|
|
21
|
+
|
|
22
|
+
# Send for processing
|
|
23
|
+
response = mindee_client.enqueue_and_get_result(
|
|
24
|
+
Mindee::V2::Product::Ocr::Ocr,
|
|
25
|
+
input_source,
|
|
26
|
+
ocr_params
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
# Access the result OCR pages
|
|
30
|
+
puts response.inference.result.pages
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'mindee'
|
|
4
|
+
require 'mindee/v2/product'
|
|
5
|
+
|
|
6
|
+
input_path = '/path/to/the/file.ext'
|
|
7
|
+
api_key = 'MY_API_KEY'
|
|
8
|
+
model_id = 'MY_MODEL_ID'
|
|
9
|
+
|
|
10
|
+
# Init a new client
|
|
11
|
+
mindee_client = Mindee::ClientV2.new(api_key: api_key)
|
|
12
|
+
|
|
13
|
+
# Set inference parameters
|
|
14
|
+
split_params = {
|
|
15
|
+
# ID of the model, required.
|
|
16
|
+
model_id: model_id,
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
# Load a file from disk
|
|
20
|
+
input_source = Mindee::Input::Source::PathInputSource.new(input_path)
|
|
21
|
+
|
|
22
|
+
# Send for processing
|
|
23
|
+
response = mindee_client.enqueue_and_get_result(
|
|
24
|
+
Mindee::V2::Product::Split::Split,
|
|
25
|
+
input_source,
|
|
26
|
+
split_params
|
|
27
|
+
)
|
|
28
|
+
|
|
29
|
+
# Access the result splits
|
|
30
|
+
puts response.inference.result.splits
|
data/lib/mindee/client_v2.rb
CHANGED
|
@@ -26,8 +26,16 @@ module Mindee
|
|
|
26
26
|
@mindee_api.req_get_inference(inference_id)
|
|
27
27
|
end
|
|
28
28
|
|
|
29
|
-
# Retrieves
|
|
30
|
-
# @param
|
|
29
|
+
# Retrieves a result from a given queue or URL to the result.
|
|
30
|
+
# @param product [Class<Mindee::V2::Product::BaseProduct>] The return class.
|
|
31
|
+
# @param resource [String] ID of the inference or URL to the result.
|
|
32
|
+
# @return [Mindee::Parsing::V2::BaseResponse]
|
|
33
|
+
def get_result(product, resource)
|
|
34
|
+
@mindee_api.req_get_result(product, resource)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# Retrieves an inference from a given queue or URL to the job.
|
|
38
|
+
# @param job_id [String] ID of the job.
|
|
31
39
|
# @return [Mindee::Parsing::V2::JobResponse]
|
|
32
40
|
def get_job(job_id)
|
|
33
41
|
@mindee_api.req_get_job(job_id)
|
|
@@ -38,22 +46,47 @@ module Mindee
|
|
|
38
46
|
# The source of the input document (local file or URL).
|
|
39
47
|
# @param params [Hash, InferenceParameters]
|
|
40
48
|
# @return [Mindee::Parsing::V2::JobResponse]
|
|
41
|
-
def enqueue_inference(input_source, params)
|
|
42
|
-
|
|
49
|
+
def enqueue_inference(input_source, params, disable_redundant_warnings: false)
|
|
50
|
+
unless disable_redundant_warnings
|
|
51
|
+
warn '[DEPRECATION] `enqueue_inference` is deprecated; use `enqueue` instead.', uplevel: 1
|
|
52
|
+
end
|
|
53
|
+
normalized_params = normalize_parameters(Input::InferenceParameters, params)
|
|
54
|
+
enqueue(Mindee::Parsing::V2::Inference, input_source, normalized_params)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# Enqueue a document for async parsing.
|
|
58
|
+
# @param product [Class<Mindee::V2::Product::BaseProduct>] The return class.
|
|
59
|
+
# @param input_source [Mindee::Input::Source::LocalInputSource, Mindee::Input::Source::URLInputSource]
|
|
60
|
+
# The source of the input document (local file or URL).
|
|
61
|
+
# @param params [Hash, InferenceParameters] Parameters for the inference.
|
|
62
|
+
# @return [Mindee::Parsing::V2::JobResponse]
|
|
63
|
+
def enqueue(
|
|
64
|
+
product,
|
|
65
|
+
input_source,
|
|
66
|
+
params
|
|
67
|
+
)
|
|
68
|
+
normalized_params = normalize_parameters(product.params_type, params)
|
|
69
|
+
normalized_params.validate_async_params
|
|
43
70
|
logger.debug("Enqueueing document to model '#{normalized_params.model_id}'.")
|
|
44
71
|
|
|
45
|
-
@mindee_api.
|
|
72
|
+
@mindee_api.req_post_enqueue(input_source, normalized_params)
|
|
46
73
|
end
|
|
47
74
|
|
|
48
|
-
#
|
|
75
|
+
# Enqueues to an asynchronous endpoint and automatically polls for a response.
|
|
76
|
+
#
|
|
77
|
+
# @param product [Class<Mindee::V2::Product::BaseProduct>] The return class.
|
|
49
78
|
# @param input_source [Mindee::Input::Source::LocalInputSource, Mindee::Input::Source::URLInputSource]
|
|
50
79
|
# The source of the input document (local file or URL).
|
|
51
80
|
# @param params [Hash, InferenceParameters] Parameters for the inference.
|
|
52
|
-
# @return [Mindee::Parsing::
|
|
53
|
-
def
|
|
54
|
-
|
|
81
|
+
# @return [Mindee::Parsing::Common::ApiResponse]
|
|
82
|
+
def enqueue_and_get_result(
|
|
83
|
+
product,
|
|
84
|
+
input_source,
|
|
85
|
+
params
|
|
86
|
+
)
|
|
87
|
+
enqueue_response = enqueue(product, input_source, params)
|
|
88
|
+
normalized_params = normalize_parameters(product.params_type, params)
|
|
55
89
|
normalized_params.validate_async_params
|
|
56
|
-
enqueue_response = enqueue_inference(input_source, normalized_params)
|
|
57
90
|
|
|
58
91
|
if enqueue_response.job.id.nil? || enqueue_response.job.id.empty?
|
|
59
92
|
logger.error("Failed enqueueing:\n#{enqueue_response.raw_http}")
|
|
@@ -70,8 +103,8 @@ module Mindee
|
|
|
70
103
|
while retry_counter < normalized_params.polling_options.max_retries
|
|
71
104
|
if poll_results.job.status == 'Failed'
|
|
72
105
|
break
|
|
73
|
-
elsif poll_results.job.
|
|
74
|
-
return
|
|
106
|
+
elsif !poll_results.job.result_url.nil?
|
|
107
|
+
return get_result(product, poll_results.job.result_url)
|
|
75
108
|
end
|
|
76
109
|
|
|
77
110
|
logger.debug(
|
|
@@ -97,13 +130,32 @@ module Mindee
|
|
|
97
130
|
"Asynchronous parsing request timed out after #{sec_count} seconds"
|
|
98
131
|
end
|
|
99
132
|
|
|
133
|
+
# Enqueue a document for async parsing and automatically try to retrieve it.
|
|
134
|
+
# @param input_source [Mindee::Input::Source::LocalInputSource, Mindee::Input::Source::URLInputSource]
|
|
135
|
+
# The source of the input document (local file or URL).
|
|
136
|
+
# @param params [Hash, InferenceParameters] Parameters for the inference.
|
|
137
|
+
# @return [Mindee::Parsing::V2::InferenceResponse]
|
|
138
|
+
def enqueue_and_get_inference(input_source, params, disable_redundant_warnings: false)
|
|
139
|
+
unless disable_redundant_warnings
|
|
140
|
+
warn '[DEPRECATION] `enqueue_and_get_inference` is deprecated; use `enqueue_and_get_result` instead.',
|
|
141
|
+
uplevel: 1
|
|
142
|
+
end
|
|
143
|
+
|
|
144
|
+
response = enqueue_and_get_result(Mindee::Parsing::V2::Inference, input_source, params)
|
|
145
|
+
unless response.is_a?(Mindee::Parsing::V2::InferenceResponse)
|
|
146
|
+
raise TypeError, "Invalid response type \"#{response.class}\""
|
|
147
|
+
end
|
|
148
|
+
|
|
149
|
+
response
|
|
150
|
+
end
|
|
151
|
+
|
|
100
152
|
# If needed, converts the parsing options provided as a hash into a proper InferenceParameters object.
|
|
101
|
-
# @param params [Hash,
|
|
102
|
-
# @return [
|
|
103
|
-
def
|
|
104
|
-
return params if params.is_a?(
|
|
153
|
+
# @param params [Hash, Class<BaseParameters>] Params.
|
|
154
|
+
# @return [BaseParameters]
|
|
155
|
+
def normalize_parameters(param_class, params)
|
|
156
|
+
return param_class.from_hash(params: params) if params.is_a?(Hash)
|
|
105
157
|
|
|
106
|
-
|
|
158
|
+
params
|
|
107
159
|
end
|
|
108
160
|
end
|
|
109
161
|
end
|
|
@@ -18,7 +18,7 @@ module Mindee
|
|
|
18
18
|
# @return [Array<ErrorItem>] A list of explicit error details.
|
|
19
19
|
attr_reader :errors
|
|
20
20
|
|
|
21
|
-
# @param http_error [Hash, Parsing::V2::ErrorResponse]
|
|
21
|
+
# @param http_error [Hash, Mindee::Parsing::V2::ErrorResponse]
|
|
22
22
|
def initialize(http_error)
|
|
23
23
|
if http_error.is_a?(Parsing::V2::ErrorResponse)
|
|
24
24
|
http_error = { 'detail' => http_error.detail,
|
|
@@ -33,7 +33,7 @@ module Mindee
|
|
|
33
33
|
@code = http_error['code']
|
|
34
34
|
@errors = if http_error.key?('errors')
|
|
35
35
|
http_error['errors'].map do |error|
|
|
36
|
-
Parsing::V2::ErrorItem.new(error)
|
|
36
|
+
Mindee::Parsing::V2::ErrorItem.new(error)
|
|
37
37
|
end
|
|
38
38
|
else
|
|
39
39
|
[]
|
|
@@ -20,16 +20,16 @@ module Mindee
|
|
|
20
20
|
# Sends a file to the inference queue.
|
|
21
21
|
#
|
|
22
22
|
# @param input_source [Input::Source::LocalInputSource, Input::Source::URLInputSource]
|
|
23
|
-
# @param params [Input::
|
|
23
|
+
# @param params [Input::BaseParameters]
|
|
24
24
|
# @return [Mindee::Parsing::V2::JobResponse]
|
|
25
25
|
# @raise [Mindee::Errors::MindeeHttpErrorV2]
|
|
26
|
-
def
|
|
26
|
+
def req_post_enqueue(input_source, params)
|
|
27
27
|
@settings.check_api_key
|
|
28
28
|
response = enqueue(
|
|
29
29
|
input_source,
|
|
30
30
|
params
|
|
31
31
|
)
|
|
32
|
-
Parsing::V2::JobResponse.new(process_response(response))
|
|
32
|
+
Mindee::Parsing::V2::JobResponse.new(process_response(response))
|
|
33
33
|
end
|
|
34
34
|
|
|
35
35
|
# Retrieves a queued inference.
|
|
@@ -37,27 +37,69 @@ module Mindee
|
|
|
37
37
|
# @param inference_id [String]
|
|
38
38
|
# @return [Mindee::Parsing::V2::InferenceResponse]
|
|
39
39
|
def req_get_inference(inference_id)
|
|
40
|
+
req_get_result(Parsing::V2::Inference, inference_id)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# Retrieves a result from a given queue.
|
|
44
|
+
# @param product [Class<Mindee::V2::Product::BaseProduct>] The return class.
|
|
45
|
+
# @param resource [String] ID of the inference or URL to the result.
|
|
46
|
+
# @return [Mindee::Parsing::V2::BaseResponse]
|
|
47
|
+
def req_get_result(product, resource)
|
|
48
|
+
return req_get_result_url(product.response_type, resource) if uri?(resource)
|
|
49
|
+
|
|
40
50
|
@settings.check_api_key
|
|
41
|
-
response =
|
|
42
|
-
|
|
51
|
+
response = result_req_get(
|
|
52
|
+
resource,
|
|
53
|
+
product
|
|
43
54
|
)
|
|
44
|
-
|
|
55
|
+
product.response_type.new(process_response(response))
|
|
45
56
|
end
|
|
46
57
|
|
|
47
58
|
# Retrieves a queued job.
|
|
48
59
|
#
|
|
49
|
-
# @param job_id [String]
|
|
60
|
+
# @param job_id [String] ID of the job or URL to the job.
|
|
50
61
|
# @return [Mindee::Parsing::V2::JobResponse]
|
|
51
62
|
def req_get_job(job_id)
|
|
52
63
|
@settings.check_api_key
|
|
53
64
|
response = inference_job_req_get(
|
|
54
65
|
job_id
|
|
55
66
|
)
|
|
56
|
-
Parsing::V2::JobResponse.new(process_response(response))
|
|
67
|
+
Mindee::Parsing::V2::JobResponse.new(process_response(response))
|
|
57
68
|
end
|
|
58
69
|
|
|
59
70
|
private
|
|
60
71
|
|
|
72
|
+
# Retrieves a queued job.
|
|
73
|
+
#
|
|
74
|
+
# @param url [String]
|
|
75
|
+
# @return [Mindee::Parsing::V2::JobResponse]
|
|
76
|
+
def req_get_job_url(url)
|
|
77
|
+
@settings.check_api_key
|
|
78
|
+
response = poll(url)
|
|
79
|
+
Mindee::Parsing::V2::JobResponse.new(process_response(response))
|
|
80
|
+
end
|
|
81
|
+
|
|
82
|
+
# Retrieves a queued job.
|
|
83
|
+
#
|
|
84
|
+
# @param result_class [Mindee::V2::Parsing::BaseResponse]
|
|
85
|
+
# @param url [String]
|
|
86
|
+
# @return [Mindee::Parsing::V2::JobResponse]
|
|
87
|
+
def req_get_result_url(result_class, url)
|
|
88
|
+
@settings.check_api_key
|
|
89
|
+
response = poll(url)
|
|
90
|
+
result_class.new(process_response(response))
|
|
91
|
+
end
|
|
92
|
+
|
|
93
|
+
# @param resource [String] Resource to check.
|
|
94
|
+
# @return [Boolean]
|
|
95
|
+
def uri?(resource)
|
|
96
|
+
uri = URI.parse(resource)
|
|
97
|
+
throw Mindee::Errors::MindeeError, 'HTTP is not supported.' if uri.scheme == 'http'
|
|
98
|
+
uri.scheme == 'https'
|
|
99
|
+
rescue URI::BadURIError, URI::InvalidURIError
|
|
100
|
+
false
|
|
101
|
+
end
|
|
102
|
+
|
|
61
103
|
# Converts an HTTP response to a parsed response object.
|
|
62
104
|
#
|
|
63
105
|
# @param response [Net::HTTPResponse, nil]
|
|
@@ -111,6 +153,15 @@ module Mindee
|
|
|
111
153
|
poll("#{@settings.base_url}/inferences/#{queue_id}")
|
|
112
154
|
end
|
|
113
155
|
|
|
156
|
+
# Polls the API for the result of an inference.
|
|
157
|
+
#
|
|
158
|
+
# @param queue_id [String] ID of the queue.
|
|
159
|
+
# @param product [Class<Mindee::V2::Product::BaseProduct>] The return class.
|
|
160
|
+
# @return [Net::HTTPResponse]
|
|
161
|
+
def result_req_get(queue_id, product)
|
|
162
|
+
poll("#{@settings.base_url}/products/#{product.slug}/results/#{queue_id}")
|
|
163
|
+
end
|
|
164
|
+
|
|
114
165
|
# Handle parameters for the enqueue form
|
|
115
166
|
# @param form_data [Array] Array of form fields
|
|
116
167
|
# @param params [Input::InferenceParameters] Inference options.
|
|
@@ -130,10 +181,10 @@ module Mindee
|
|
|
130
181
|
end
|
|
131
182
|
|
|
132
183
|
# @param input_source [Mindee::Input::Source::LocalInputSource, Mindee::Input::Source::URLInputSource]
|
|
133
|
-
# @param params [Input::
|
|
184
|
+
# @param params [Input::BaseParameters] Inference options.
|
|
134
185
|
# @return [Net::HTTPResponse, nil]
|
|
135
186
|
def enqueue(input_source, params)
|
|
136
|
-
uri = URI("#{@settings.base_url}/
|
|
187
|
+
uri = URI("#{@settings.base_url}/products/#{params.slug}/enqueue")
|
|
137
188
|
|
|
138
189
|
form_data = if input_source.is_a?(Mindee::Input::Source::URLInputSource)
|
|
139
190
|
[['url', input_source.url]] # : Array[untyped]
|
|
@@ -143,8 +194,7 @@ module Mindee
|
|
|
143
194
|
end
|
|
144
195
|
form_data.push(['model_id', params.model_id])
|
|
145
196
|
|
|
146
|
-
|
|
147
|
-
form_data = enqueue_form_options(form_data, params)
|
|
197
|
+
form_data = params.append_form_data(form_data)
|
|
148
198
|
|
|
149
199
|
headers = {
|
|
150
200
|
'Authorization' => @settings.api_key,
|