mindee 5.4.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 +14 -0
- data/CONTRIBUTING.md +88 -0
- data/bin/mindee.rb +4 -1
- data/bin/v1/products.rb +0 -6
- data/bin/v2/parser.rb +40 -45
- data/bin/v2/search_commands.rb +100 -0
- data/lib/mindee/v1/client.rb +1 -75
- data/lib/mindee/v1/http.rb +0 -1
- data/lib/mindee/v1/product.rb +0 -3
- data/lib/mindee/v2/client.rb +62 -36
- data/lib/mindee/v2/client_options/base_product_parameters.rb +162 -0
- data/lib/mindee/v2/client_options/base_search_parameters.rb +51 -0
- data/lib/mindee/v2/client_options.rb +4 -0
- data/lib/mindee/v2/http/mindee_api_v2.rb +59 -78
- data/lib/mindee/v2/parsing/search/base_search_response.rb +47 -0
- data/lib/mindee/v2/parsing/search/model_webhook.rb +3 -3
- data/lib/mindee/v2/parsing/search/pagination_metadata.rb +1 -1
- data/lib/mindee/v2/parsing/search/search_models.rb +2 -1
- data/lib/mindee/v2/parsing/search/search_rag_document.rb +60 -0
- data/lib/mindee/v2/parsing/search/search_rag_documents.rb +39 -0
- data/lib/mindee/v2/parsing/search/search_response.rb +2 -29
- data/lib/mindee/v2/parsing/search.rb +5 -1
- data/lib/mindee/v2/product/base_product.rb +2 -2
- data/lib/mindee/v2/product/classification/classification_classifier.rb +5 -5
- data/lib/mindee/v2/product/classification/params/classification_parameters.rb +1 -1
- data/lib/mindee/v2/product/crop/crop_item.rb +5 -5
- data/lib/mindee/v2/product/crop/params/crop_parameters.rb +1 -1
- data/lib/mindee/v2/product/extraction/params/extraction_parameters.rb +2 -2
- data/lib/mindee/v2/product/ocr/params/ocr_parameters.rb +1 -1
- data/lib/mindee/v2/product/split/params/split_parameters.rb +1 -1
- data/lib/mindee/v2/product/split/split_range.rb +5 -5
- data/lib/mindee/v2/search/models/model_search_parameters.rb +54 -0
- data/lib/mindee/v2/search/models/model_search_response.rb +28 -0
- data/lib/mindee/v2/search/rag_documents/rag_document_search_parameters.rb +52 -0
- data/lib/mindee/v2/search/rag_documents/rag_document_search_response.rb +28 -0
- data/lib/mindee/v2/search.rb +6 -0
- data/lib/mindee/v2.rb +2 -0
- data/lib/mindee/version.rb +1 -1
- data/mindee.gemspec +1 -1
- data/prek.toml +45 -0
- data/sig/custom/net_http.rbs +1 -1
- data/sig/mindee/v1/client.rbs +1 -15
- data/sig/mindee/v2/client.rbs +11 -4
- data/sig/mindee/v2/client_options/base_product_parameters.rbs +41 -0
- data/sig/mindee/v2/client_options/base_search_parameters.rbs +19 -0
- data/sig/mindee/v2/http/mindee_api_v2.rbs +19 -15
- data/sig/mindee/v2/parsing/search/base_search_response.rbs +19 -0
- data/sig/mindee/v2/parsing/search/search_rag_document.rbs +23 -0
- data/sig/mindee/v2/parsing/search/search_rag_documents.rbs +16 -0
- data/sig/mindee/v2/parsing/search/search_response.rbs +4 -9
- data/sig/mindee/v2/product/base_product.rbs +3 -3
- data/sig/mindee/v2/product/classification/classification_classifier.rbs +1 -1
- data/sig/mindee/v2/product/classification/params/classification_parameters/classification_parameters.rbs +1 -1
- data/sig/mindee/v2/product/crop/crop_item.rbs +1 -1
- data/sig/mindee/v2/product/crop/params/crop_parameters/crop_parameters.rbs +1 -1
- data/sig/mindee/v2/product/extraction/params/extraction_parameters.rbs +1 -1
- data/sig/mindee/v2/product/ocr/params/ocr_parameters/ocr_parameters.rbs +1 -1
- data/sig/mindee/v2/product/split/params/split_parameters/split_parameters.rbs +1 -1
- data/sig/mindee/v2/product/split/split_range.rbs +1 -1
- data/sig/mindee/v2/search/models/model_search_parameters.rbs +22 -0
- data/sig/mindee/v2/search/models/model_search_response.rbs +17 -0
- data/sig/mindee/v2/search/rag_documents/rag_document_search_parameters.rbs +22 -0
- data/sig/mindee/v2/search/rag_documents/rag_document_search_response.rbs +17 -0
- metadata +28 -32
- data/.pre-commit-config.yaml +0 -36
- 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/input/base_parameters.rb +0 -156
- 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/input/base_parameters.rbs +0 -36
- 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
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
# Mindee Ruby API Library Changelog
|
|
2
2
|
|
|
3
|
+
## v5.6.0 - 2026-11-04
|
|
4
|
+
### Changes
|
|
5
|
+
* coffin: remove dead v1 products and workflow methods
|
|
6
|
+
* :sparkles: add get by URL methods
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
## v5.5.0 - 2026-09-30
|
|
10
|
+
### Changes
|
|
11
|
+
* :sparkles: add support for RAG search
|
|
12
|
+
* :wrench: switching over from pre-commit to ruby-only solution
|
|
13
|
+
### Fixes
|
|
14
|
+
* :bug: fix V2 hangs on GET
|
|
15
|
+
|
|
16
|
+
|
|
3
17
|
## v5.4.0 - 2026-07-21
|
|
4
18
|
### Changes
|
|
5
19
|
* :sparkles: add field confidence comparators
|
data/CONTRIBUTING.md
CHANGED
|
@@ -68,6 +68,94 @@ Please follow these steps to have your contribution considered by the maintainer
|
|
|
68
68
|
|
|
69
69
|
While the prerequisites above must be satisfied prior to having your pull request reviewed, the reviewer(s) may ask you to complete additional design work, tests, or other changes before your pull request can be ultimately accepted.
|
|
70
70
|
|
|
71
|
+
## Development Setup
|
|
72
|
+
|
|
73
|
+
### 1. Ruby
|
|
74
|
+
|
|
75
|
+
[`rbenv`](https://github.com/rbenv/rbenv) is the recommended way to manage Ruby versions:
|
|
76
|
+
|
|
77
|
+
```shell
|
|
78
|
+
# Finalize the rbenv install (should work with both bash & zsh)
|
|
79
|
+
~/.rbenv/bin/rbenv init
|
|
80
|
+
# And then run
|
|
81
|
+
eval "$(~/.rbenv/bin/rbenv init - bash)"
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
### 2. Clone the repository
|
|
85
|
+
|
|
86
|
+
Test data lives in a submodule, so make sure to clone recursively:
|
|
87
|
+
|
|
88
|
+
```shell
|
|
89
|
+
git clone --recurse-submodules git@github.com:mindee/mindee-api-ruby.git ~/work/mindee/mindee-api-ruby
|
|
90
|
+
cd ~/work/mindee/mindee-api-ruby
|
|
91
|
+
```
|
|
92
|
+
|
|
93
|
+
If you already cloned without `--recurse-submodules`, run `git submodule update --init --recursive`.
|
|
94
|
+
|
|
95
|
+
### 3. Install dependencies
|
|
96
|
+
|
|
97
|
+
On Debian/Ubuntu:
|
|
98
|
+
|
|
99
|
+
```shell
|
|
100
|
+
sudo apt install zlib1g-dev libssl-dev libreadline-dev libedit-dev libyaml-dev imagemagick
|
|
101
|
+
```
|
|
102
|
+
|
|
103
|
+
`imagemagick` is required at runtime by `mini_magick`, the rest are needed to build Ruby itself.
|
|
104
|
+
|
|
105
|
+
```shell
|
|
106
|
+
# Ruby 3.3.0 is the minimum version supported by the SDK
|
|
107
|
+
rbenv install 3.3.0
|
|
108
|
+
rbenv global 3.3.0
|
|
109
|
+
```
|
|
110
|
+
|
|
111
|
+
### 4. Install code dependencies
|
|
112
|
+
|
|
113
|
+
```shell
|
|
114
|
+
bundle config set --local path vendor
|
|
115
|
+
bundle install
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
### 5. Validate the install works by running unit tests
|
|
119
|
+
|
|
120
|
+
```shell
|
|
121
|
+
bundle exec rake spec
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
## Local Quality Checks
|
|
125
|
+
|
|
126
|
+
We use [`prek`](https://prek.j178.dev/) to run quality and security checks before changes are committed and pushed.
|
|
127
|
+
|
|
128
|
+
The same checks run in CI, see
|
|
129
|
+
[`.github/workflows/_static-analysis.yml`](.github/workflows/_static-analysis.yml).
|
|
130
|
+
|
|
131
|
+
### Install the hooks
|
|
132
|
+
|
|
133
|
+
https://prek.j178.dev/installation/
|
|
134
|
+
|
|
135
|
+
Then install the hooks:
|
|
136
|
+
|
|
137
|
+
```shell
|
|
138
|
+
prek install
|
|
139
|
+
```
|
|
140
|
+
|
|
141
|
+
Now, when you run `git commit`, `prek` will automatically run the quality and security checks.
|
|
142
|
+
|
|
143
|
+
### Run the hooks manually
|
|
144
|
+
|
|
145
|
+
If you need to run the hooks manually, use the following command:
|
|
146
|
+
|
|
147
|
+
```shell
|
|
148
|
+
prek run --all-files
|
|
149
|
+
```
|
|
150
|
+
|
|
151
|
+
### Skipping hooks
|
|
152
|
+
|
|
153
|
+
Skip one or more hooks for a single run, by ID:
|
|
154
|
+
|
|
155
|
+
```shell
|
|
156
|
+
PREK_SKIP=rubocop
|
|
157
|
+
```
|
|
158
|
+
|
|
71
159
|
## Styleguides
|
|
72
160
|
|
|
73
161
|
### Git Commit Messages
|
data/bin/mindee.rb
CHANGED
|
@@ -9,7 +9,10 @@ require_relative 'v2/parser'
|
|
|
9
9
|
def root_help
|
|
10
10
|
help = "Usage: mindee command [options]\n\nAvailable commands:\n"
|
|
11
11
|
help += " #{'v1'.ljust(50)}Use Version 1 of the Mindee API\n"
|
|
12
|
-
|
|
12
|
+
|
|
13
|
+
MindeeCLI::V2SearchCommands::V2_SEARCH_COMMANDS.each do |search_command, search_values|
|
|
14
|
+
help += " #{search_command.ljust(50)}#{search_values[:description]}\n"
|
|
15
|
+
end
|
|
13
16
|
|
|
14
17
|
V2_PRODUCTS.each do |product_key, product_values|
|
|
15
18
|
help += " #{product_key.ljust(50)}#{product_values[:description]}\n"
|
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/bin/v2/parser.rb
CHANGED
|
@@ -2,11 +2,14 @@
|
|
|
2
2
|
|
|
3
3
|
require 'mindee'
|
|
4
4
|
require_relative 'products'
|
|
5
|
+
require_relative 'search_commands'
|
|
5
6
|
|
|
6
7
|
module MindeeCLI
|
|
7
8
|
# Mindee Command Line Interface
|
|
8
9
|
# V2 CLI class.
|
|
9
10
|
class V2Parser
|
|
11
|
+
include V2SearchCommands
|
|
12
|
+
|
|
10
13
|
# @return [Array<String>]
|
|
11
14
|
attr_reader :arguments
|
|
12
15
|
|
|
@@ -17,7 +20,10 @@ module MindeeCLI
|
|
|
17
20
|
attr_reader :product_parser
|
|
18
21
|
|
|
19
22
|
# @return [Parser]
|
|
20
|
-
attr_reader :
|
|
23
|
+
attr_reader :search_models_parser
|
|
24
|
+
|
|
25
|
+
# @return [Parser]
|
|
26
|
+
attr_reader :search_rag_docs_parser
|
|
21
27
|
|
|
22
28
|
def initialize(arguments, command_prefix: 'mindee v2')
|
|
23
29
|
@arguments = arguments
|
|
@@ -26,26 +32,18 @@ module MindeeCLI
|
|
|
26
32
|
opts.banner = "Usage: #{@command_prefix} command [options]"
|
|
27
33
|
end
|
|
28
34
|
@product_parser = init_product_parser
|
|
29
|
-
@
|
|
35
|
+
@search_models_parser = init_search_models_parser
|
|
36
|
+
@search_rag_docs_parser = init_search_rag_docs_parser
|
|
30
37
|
end
|
|
31
38
|
|
|
32
39
|
# Summarize and print the result of the command.
|
|
33
40
|
# @param command [String]
|
|
34
41
|
def print_result(command)
|
|
35
|
-
if command
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
@product_parser[command].parse!(@arguments)
|
|
41
|
-
@options[:file_path] = @arguments.shift
|
|
42
|
-
if @options[:file_path].nil?
|
|
43
|
-
warn 'file missing'
|
|
44
|
-
abort(@product_parser[command].help)
|
|
45
|
-
end
|
|
46
|
-
result = send(command, @options)
|
|
47
|
-
summarized_result = output_format == :full ? result.inference.to_s : result.inference.result.to_s
|
|
48
|
-
end
|
|
42
|
+
result, summarized_result = if V2_SEARCH_COMMANDS.key?(command)
|
|
43
|
+
run_search(command)
|
|
44
|
+
else
|
|
45
|
+
run_product(command)
|
|
46
|
+
end
|
|
49
47
|
|
|
50
48
|
if output_format == :raw
|
|
51
49
|
puts JSON.pretty_generate(raw_payload(result.raw_http))
|
|
@@ -63,22 +61,41 @@ module MindeeCLI
|
|
|
63
61
|
validate_command!(command)
|
|
64
62
|
print_result(command)
|
|
65
63
|
rescue OptionParser::InvalidOption, OptionParser::MissingArgument => e
|
|
66
|
-
|
|
67
|
-
abort("#{e.message}\n\n#{@search_parser.help}")
|
|
68
|
-
else
|
|
69
|
-
abort("#{e.message}\n\n#{@product_parser[command].help}")
|
|
70
|
-
end
|
|
64
|
+
abort("#{e.message}\n\n#{command_parser(command).help}")
|
|
71
65
|
rescue Mindee::Error::MindeeError => e
|
|
72
66
|
abort(format_cli_error(e))
|
|
73
67
|
end
|
|
74
68
|
|
|
75
69
|
private
|
|
76
70
|
|
|
71
|
+
# Parse the arguments and run the given product command.
|
|
72
|
+
# @param command [String]
|
|
73
|
+
# @return [Array(Mindee::V2::Parsing::BaseResponse, String)] Response and its summary.
|
|
74
|
+
def run_product(command)
|
|
75
|
+
@product_parser[command].parse!(@arguments)
|
|
76
|
+
@options[:file_path] = @arguments.shift
|
|
77
|
+
if @options[:file_path].nil?
|
|
78
|
+
warn 'file missing'
|
|
79
|
+
abort(@product_parser[command].help)
|
|
80
|
+
end
|
|
81
|
+
result = send(command, @options)
|
|
82
|
+
summarized_result = output_format == :full ? result.inference.to_s : result.inference.result.to_s
|
|
83
|
+
[result, summarized_result]
|
|
84
|
+
end
|
|
85
|
+
|
|
86
|
+
# @param command [String]
|
|
87
|
+
# @return [OptionParser]
|
|
88
|
+
def command_parser(command)
|
|
89
|
+
V2_SEARCH_COMMANDS.key?(command) ? search_parser_for(command) : @product_parser[command]
|
|
90
|
+
end
|
|
91
|
+
|
|
77
92
|
def validate_command!(command)
|
|
78
|
-
return if V2_PRODUCTS.include?(command) || command
|
|
93
|
+
return if V2_PRODUCTS.include?(command) || V2_SEARCH_COMMANDS.key?(command)
|
|
79
94
|
|
|
80
95
|
error_msg = "#{@options_parser.help}\nAvailable commands:\n"
|
|
81
|
-
|
|
96
|
+
V2_SEARCH_COMMANDS.each do |search_command, search_values|
|
|
97
|
+
error_msg += " #{search_command.ljust(50)}#{search_values[:description]}\n"
|
|
98
|
+
end
|
|
82
99
|
|
|
83
100
|
V2_PRODUCTS.each do |product_key, product_values|
|
|
84
101
|
error_msg += " #{product_key.to_s.ljust(50)}#{product_values[:description]}\n"
|
|
@@ -98,21 +115,6 @@ module MindeeCLI
|
|
|
98
115
|
end
|
|
99
116
|
end
|
|
100
117
|
|
|
101
|
-
def init_search_parser
|
|
102
|
-
OptionParser.new do |options_parser|
|
|
103
|
-
options_parser.banner = "Usage: #{@command_prefix} search-models [options]"
|
|
104
|
-
init_common_options(options_parser)
|
|
105
|
-
options_parser.on('-n [NAME]', '--name [NAME]',
|
|
106
|
-
'Search for partial matches in model name. Note: case insensitive') do |v|
|
|
107
|
-
@options[:model_name] = v
|
|
108
|
-
end
|
|
109
|
-
options_parser.on('-t [NAME]', '--type [NAME]',
|
|
110
|
-
'Search for EXACT matches in model type. Note: case sensitive') do |v|
|
|
111
|
-
@options[:model_type] = v
|
|
112
|
-
end
|
|
113
|
-
end
|
|
114
|
-
end
|
|
115
|
-
|
|
116
118
|
def setup_specific_options(options_parser, doc_value)
|
|
117
119
|
options_parser.on('-r', '--rag', 'Enable RAG') { @options[:rag] = true } if doc_value.key?(:rag)
|
|
118
120
|
if doc_value.key?(:raw_text)
|
|
@@ -218,13 +220,6 @@ module MindeeCLI
|
|
|
218
220
|
)
|
|
219
221
|
end
|
|
220
222
|
|
|
221
|
-
# @param options [Hash]
|
|
222
|
-
# @return [Mindee::V2::Parsing::Search::SearchResponse]
|
|
223
|
-
def search(options)
|
|
224
|
-
mindee_client = Mindee::V2::Client.new(api_key: options[:api_key])
|
|
225
|
-
mindee_client.search_models(options[:model_name], options[:model_type])
|
|
226
|
-
end
|
|
227
|
-
|
|
228
223
|
# @param options [Hash]
|
|
229
224
|
# @return [Mindee::Input::InputSource]
|
|
230
225
|
def setup_input_source(options)
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require 'mindee'
|
|
4
|
+
require_relative 'products'
|
|
5
|
+
|
|
6
|
+
module MindeeCLI
|
|
7
|
+
# Search-related commands for the V2 CLI.
|
|
8
|
+
module V2SearchCommands
|
|
9
|
+
# NOTE: keep command names as string instead of symbols due to kebab-case.
|
|
10
|
+
V2_SEARCH_COMMANDS = {
|
|
11
|
+
'search-models' => {
|
|
12
|
+
description: 'Search available models.',
|
|
13
|
+
parser: :search_models_parser,
|
|
14
|
+
runner: :search_models,
|
|
15
|
+
summary: :models,
|
|
16
|
+
},
|
|
17
|
+
'search-rag-docs' => {
|
|
18
|
+
description: 'Search available RAG documents for a given model.',
|
|
19
|
+
parser: :search_rag_docs_parser,
|
|
20
|
+
runner: :search_rag_documents,
|
|
21
|
+
summary: :rag_documents,
|
|
22
|
+
},
|
|
23
|
+
}.freeze
|
|
24
|
+
|
|
25
|
+
private
|
|
26
|
+
|
|
27
|
+
# Parse the arguments and run the given search command.
|
|
28
|
+
# @param command [String]
|
|
29
|
+
# @return [Array(Mindee::V2::Parsing::Search::BaseSearchResponse, String)] Response and its summary.
|
|
30
|
+
def run_search(command)
|
|
31
|
+
search_command = V2_SEARCH_COMMANDS[command]
|
|
32
|
+
search_parser_for(command).parse!(@arguments)
|
|
33
|
+
result = __send__(search_command[:runner], @options)
|
|
34
|
+
summarized_result = output_format == :full ? result.to_s : result.public_send(search_command[:summary]).to_s
|
|
35
|
+
[result, summarized_result]
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# @param command [String]
|
|
39
|
+
# @return [OptionParser]
|
|
40
|
+
def search_parser_for(command)
|
|
41
|
+
__send__(V2_SEARCH_COMMANDS[command][:parser])
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# @return [OptionParser]
|
|
45
|
+
def init_search_models_parser
|
|
46
|
+
OptionParser.new do |options_parser|
|
|
47
|
+
options_parser.banner = "Usage: #{@command_prefix} search-models [options]"
|
|
48
|
+
init_common_options(options_parser)
|
|
49
|
+
options_parser.on('-n [NAME]', '--name [NAME]',
|
|
50
|
+
'Filter by model name partial match (case insensitive).') do |v|
|
|
51
|
+
@options[:model_name] = v
|
|
52
|
+
end
|
|
53
|
+
options_parser.on('-m [MODEL_TYPE]', '--model-type [MODEL_TYPE]',
|
|
54
|
+
'Filter by exact model type (case sensitive).',
|
|
55
|
+
"Available options: #{V2_PRODUCTS.keys.join(', ')}") do |v|
|
|
56
|
+
@options[:model_type] = v
|
|
57
|
+
end
|
|
58
|
+
end
|
|
59
|
+
end
|
|
60
|
+
|
|
61
|
+
# @return [OptionParser]
|
|
62
|
+
def init_search_rag_docs_parser
|
|
63
|
+
OptionParser.new do |options_parser|
|
|
64
|
+
options_parser.banner = "Usage: #{@command_prefix} search-rag-docs [options]"
|
|
65
|
+
init_common_options(options_parser)
|
|
66
|
+
options_parser.on('-m MODEL_ID', '--model-id MODEL_ID', 'Filter by model ID') do |v|
|
|
67
|
+
@options[:model_id] = v
|
|
68
|
+
end
|
|
69
|
+
options_parser.on('-f [FILENAME]', '--filename [FILENAME]',
|
|
70
|
+
'Filter by file name partial match (case insensitive).') do |v|
|
|
71
|
+
@options[:filename] = v
|
|
72
|
+
end
|
|
73
|
+
end
|
|
74
|
+
end
|
|
75
|
+
|
|
76
|
+
# @param options [Hash]
|
|
77
|
+
# @return [Mindee::V2::Search::Models::ModelSearchResponse]
|
|
78
|
+
def search_models(options)
|
|
79
|
+
mindee_client = Mindee::V2::Client.new(api_key: options[:api_key])
|
|
80
|
+
mindee_client.search(
|
|
81
|
+
Mindee::V2::Search::Models::ModelSearchParameters.new(
|
|
82
|
+
name: options[:model_name],
|
|
83
|
+
model_type: options[:model_type]
|
|
84
|
+
)
|
|
85
|
+
)
|
|
86
|
+
end
|
|
87
|
+
|
|
88
|
+
# @param options [Hash]
|
|
89
|
+
# @return [Mindee::V2::Search::RAGDocuments::RAGDocumentSearchResponse]
|
|
90
|
+
def search_rag_documents(options)
|
|
91
|
+
mindee_client = Mindee::V2::Client.new(api_key: options[:api_key])
|
|
92
|
+
mindee_client.search(
|
|
93
|
+
Mindee::V2::Search::RAGDocuments::RAGDocumentSearchParameters.new(
|
|
94
|
+
model_id: options[:model_id],
|
|
95
|
+
filename: options[:filename]
|
|
96
|
+
)
|
|
97
|
+
)
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
end
|
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 Metrics/PerceivedComplexity
|
|
219
|
+
# rubocop:disable-next Metrics/PerceivedComplexity, Metrics/CyclomaticComplexity
|
|
254
220
|
def enqueue_and_parse(
|
|
255
221
|
input_source,
|
|
256
222
|
product_class,
|
|
@@ -293,46 +259,6 @@ module Mindee
|
|
|
293
259
|
|
|
294
260
|
queue_res
|
|
295
261
|
end
|
|
296
|
-
# rubocop:enable Metrics/PerceivedComplexity
|
|
297
|
-
|
|
298
|
-
# rubocop:enable Metrics/CyclomaticComplexity
|
|
299
|
-
# Sends a document to a workflow.
|
|
300
|
-
#
|
|
301
|
-
# Accepts options either as a Hash or as a WorkflowOptions struct.
|
|
302
|
-
#
|
|
303
|
-
# @param input_source [Mindee::Input::Source::LocalInputSource, Mindee::Input::Source::URLInputSource]
|
|
304
|
-
# @param workflow_id [String]
|
|
305
|
-
# @param options [Hash, WorkflowOptions] Options to configure workflow behavior. Possible keys:
|
|
306
|
-
# * `document_alias` [String, nil] Alias to give to the document.
|
|
307
|
-
# * `priority` [Symbol, nil] Priority to give to the document.
|
|
308
|
-
# * `full_text` [bool] Whether to include the full OCR text response in compatible APIs.
|
|
309
|
-
# * `rag` [bool, nil] Whether to enable Retrieval-Augmented Generation.
|
|
310
|
-
#
|
|
311
|
-
# * `public_url` [String, nil] A unique, encrypted URL for accessing the document validation interface without
|
|
312
|
-
# requiring authentication.
|
|
313
|
-
# * `page_options` [Hash, nil] Page cutting/merge options:
|
|
314
|
-
# * `:page_indexes` Zero-based list of page indexes.
|
|
315
|
-
# * `:operation` Operation to apply on the document, given the `page_indexes specified:
|
|
316
|
-
# * `:KEEP_ONLY` - keep only the specified pages, and remove all others.
|
|
317
|
-
# * `:REMOVE` - remove the specified pages, and keep all others.
|
|
318
|
-
# * `:on_min_pages` Apply the operation only if document has at least this many pages.
|
|
319
|
-
# @return [Mindee::V1::Parsing::Common::WorkflowResponse]
|
|
320
|
-
def execute_workflow(input_source, workflow_id, options: {})
|
|
321
|
-
opts = options.is_a?(WorkflowOptions) ? options : WorkflowOptions.new(params: options)
|
|
322
|
-
if opts.respond_to?(:page_options) && input_source.is_a?(Input::Source::LocalInputSource)
|
|
323
|
-
process_pdf_if_required(input_source, opts)
|
|
324
|
-
end
|
|
325
|
-
|
|
326
|
-
workflow_endpoint = V1::HTTP::WorkflowEndpoint.new(workflow_id, api_key: @api_key.to_s)
|
|
327
|
-
logger.debug("Sending document to workflow '#{workflow_id}'")
|
|
328
|
-
|
|
329
|
-
prediction, raw_http = workflow_endpoint.execute_workflow(
|
|
330
|
-
input_source,
|
|
331
|
-
opts
|
|
332
|
-
)
|
|
333
|
-
|
|
334
|
-
Mindee::V1::Parsing::Common::WorkflowResponse.new(V1::Product::Universal::Universal, prediction, raw_http)
|
|
335
|
-
end
|
|
336
262
|
|
|
337
263
|
# Load a prediction.
|
|
338
264
|
#
|
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'
|