mindee-lite 5.4.0 → 5.5.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.
Files changed (62) hide show
  1. checksums.yaml +4 -4
  2. data/.git-hooks/pre_commit/gitleaks.rb +19 -0
  3. data/.overcommit.yml +46 -0
  4. data/CHANGELOG.md +8 -0
  5. data/CONTRIBUTING.md +128 -0
  6. data/bin/mindee.rb +4 -1
  7. data/bin/v2/parser.rb +40 -45
  8. data/bin/v2/search_commands.rb +100 -0
  9. data/lib/mindee/v1/client.rb +1 -2
  10. data/lib/mindee/v2/client.rb +18 -11
  11. data/lib/mindee/v2/client_options/base_product_parameters.rb +162 -0
  12. data/lib/mindee/v2/client_options/base_search_parameters.rb +51 -0
  13. data/lib/mindee/v2/client_options.rb +4 -0
  14. data/lib/mindee/v2/http/mindee_api_v2.rb +28 -32
  15. data/lib/mindee/v2/parsing/search/base_search_response.rb +47 -0
  16. data/lib/mindee/v2/parsing/search/model_webhook.rb +3 -3
  17. data/lib/mindee/v2/parsing/search/pagination_metadata.rb +1 -1
  18. data/lib/mindee/v2/parsing/search/search_models.rb +2 -1
  19. data/lib/mindee/v2/parsing/search/search_rag_document.rb +60 -0
  20. data/lib/mindee/v2/parsing/search/search_rag_documents.rb +39 -0
  21. data/lib/mindee/v2/parsing/search/search_response.rb +2 -29
  22. data/lib/mindee/v2/parsing/search.rb +5 -1
  23. data/lib/mindee/v2/product/base_product.rb +2 -2
  24. data/lib/mindee/v2/product/classification/classification_classifier.rb +1 -2
  25. data/lib/mindee/v2/product/classification/params/classification_parameters.rb +1 -1
  26. data/lib/mindee/v2/product/crop/crop_item.rb +1 -2
  27. data/lib/mindee/v2/product/crop/params/crop_parameters.rb +1 -1
  28. data/lib/mindee/v2/product/extraction/params/extraction_parameters.rb +2 -2
  29. data/lib/mindee/v2/product/ocr/params/ocr_parameters.rb +1 -1
  30. data/lib/mindee/v2/product/split/params/split_parameters.rb +1 -1
  31. data/lib/mindee/v2/product/split/split_range.rb +1 -2
  32. data/lib/mindee/v2/search/models/model_search_parameters.rb +51 -0
  33. data/lib/mindee/v2/search/models/model_search_response.rb +28 -0
  34. data/lib/mindee/v2/search/rag_documents/rag_document_search_parameters.rb +52 -0
  35. data/lib/mindee/v2/search/rag_documents/rag_document_search_response.rb +28 -0
  36. data/lib/mindee/v2/search.rb +6 -0
  37. data/lib/mindee/v2.rb +2 -0
  38. data/lib/mindee/version.rb +1 -1
  39. data/mindee.gemspec +1 -0
  40. data/sig/custom/net_http.rbs +1 -1
  41. data/sig/mindee/v2/client.rbs +7 -4
  42. data/sig/mindee/v2/client_options/base_product_parameters.rbs +41 -0
  43. data/sig/mindee/v2/client_options/base_search_parameters.rbs +19 -0
  44. data/sig/mindee/v2/http/mindee_api_v2.rbs +12 -6
  45. data/sig/mindee/v2/parsing/search/base_search_response.rbs +19 -0
  46. data/sig/mindee/v2/parsing/search/search_rag_document.rbs +23 -0
  47. data/sig/mindee/v2/parsing/search/search_rag_documents.rbs +16 -0
  48. data/sig/mindee/v2/parsing/search/search_response.rbs +4 -9
  49. data/sig/mindee/v2/product/base_product.rbs +3 -3
  50. data/sig/mindee/v2/product/classification/params/classification_parameters/classification_parameters.rbs +1 -1
  51. data/sig/mindee/v2/product/crop/params/crop_parameters/crop_parameters.rbs +1 -1
  52. data/sig/mindee/v2/product/extraction/params/extraction_parameters.rbs +1 -1
  53. data/sig/mindee/v2/product/ocr/params/ocr_parameters/ocr_parameters.rbs +1 -1
  54. data/sig/mindee/v2/product/split/params/split_parameters/split_parameters.rbs +1 -1
  55. data/sig/mindee/v2/search/models/model_search_parameters.rbs +22 -0
  56. data/sig/mindee/v2/search/models/model_search_response.rbs +17 -0
  57. data/sig/mindee/v2/search/rag_documents/rag_document_search_parameters.rbs +22 -0
  58. data/sig/mindee/v2/search/rag_documents/rag_document_search_response.rbs +17 -0
  59. metadata +25 -5
  60. data/.pre-commit-config.yaml +0 -36
  61. data/lib/mindee/input/base_parameters.rb +0 -156
  62. data/sig/mindee/input/base_parameters.rbs +0 -36
@@ -0,0 +1,162 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mindee
4
+ module V2
5
+ module ClientOptions
6
+ # Base class for parameters accepted by all V2 endpoints.
7
+ class BaseProductParameters
8
+ # @return [String] Model ID to use for the inference. Required.
9
+ attr_reader :model_id
10
+
11
+ # @return [String, nil] Optional: a free-form string to tag the request with your own identifier.
12
+ # For example, an internal document ID, reference number, or database key.
13
+ # If set, it will be included in the job and result responses.
14
+ attr_reader :file_alias
15
+
16
+ # @return [Array<String>, nil] Webhook IDs to call after all processing is finished.
17
+ # If empty, no webhooks will be used.
18
+ attr_reader :webhook_ids
19
+
20
+ # @return [Input::PollingOptions] Options for polling. Set only if having timeout issues.
21
+ attr_reader :polling_options
22
+
23
+ # @return [Boolean, nil] Whether to close the file after parsing.
24
+ attr_reader :close_file
25
+
26
+ # @param [String] model_id ID of the model
27
+ # @param [String, nil] file_alias File alias, if applicable.
28
+ # @param [Array<String>, nil] webhook_ids List of webhook IDs to propagate the API response to.
29
+ # @param [Hash, Input::PollingOptions, nil] polling_options Options for polling. Set only if having timeout
30
+ # issues.
31
+ # @param [Boolean, nil] close_file Whether to close the file after parsing.
32
+ def initialize(
33
+ model_id,
34
+ file_alias: nil,
35
+ webhook_ids: nil,
36
+ polling_options: nil,
37
+ close_file: true
38
+ )
39
+ raise Error::MindeeInputError, 'Model ID is required.' if model_id.nil? || model_id.empty?
40
+
41
+ @model_id = model_id
42
+ @file_alias = file_alias
43
+ @webhook_ids = webhook_ids || []
44
+ @polling_options = get_clean_polling_options(polling_options)
45
+ @close_file = close_file.nil? || close_file
46
+ end
47
+
48
+ # Sets polling options after normalizing hash inputs.
49
+ # @param [Hash, Input::PollingOptions, nil] polling_options
50
+ # @return [Input::PollingOptions]
51
+ def polling_options=(polling_options)
52
+ @polling_options = get_clean_polling_options(polling_options)
53
+ end
54
+
55
+ # @return [String] Slug for the endpoint.
56
+ def self.slug
57
+ if self == BaseProductParameters
58
+ raise NotImplementedError, 'Cannot access `slug` directly on the BaseProductParameters class.'
59
+ end
60
+
61
+ ''
62
+ end
63
+
64
+ # @return [String] Slug for the endpoint.
65
+ def slug
66
+ self.class.slug
67
+ end
68
+
69
+ # Load from a hash
70
+ # @param [Hash] params Parameters to provide as a hash.
71
+ # @return [BaseProductParameters]
72
+ def self.from_hash(params: {})
73
+ load_from_hash(params: params)
74
+ new(
75
+ params[:model_id],
76
+ file_alias: params[:file_alias],
77
+ webhook_ids: params[:webhook_ids],
78
+ polling_options: params[:polling_options],
79
+ close_file: params[:close_file]
80
+ )
81
+ end
82
+
83
+ # Loads a prediction from a Hash.
84
+ # @param [Hash] params Parameters to provide as a hash.
85
+ # @return [Hash]
86
+ def self.load_from_hash(params: {})
87
+ params.transform_keys!(&:to_sym)
88
+
89
+ if params.empty? || params[:model_id].nil? || params[:model_id].empty?
90
+ raise Error::MindeeInputError, 'Model ID is required.'
91
+ end
92
+
93
+ polling_options_input = params.fetch(:page_options, Input::PollingOptions.new)
94
+ if polling_options_input.is_a?(Hash)
95
+ polling_options_input = polling_options_input.transform_keys(&:to_sym)
96
+ Input::PollingOptions.new(
97
+ initial_delay_sec: polling_options_input.fetch(:initial_delay_sec, 2.0),
98
+ delay_sec: polling_options_input.fetch(:delay_sec, 1.5),
99
+ max_retries: polling_options_input.fetch(:max_retries, 80)
100
+ )
101
+ end
102
+ params
103
+ end
104
+
105
+ # Appends base form data to the provided array.
106
+ # @param [Array] form_data Array of form fields
107
+ # @return [Array]
108
+ def append_form_data(form_data)
109
+ form_data.push(['alias', @file_alias]) if @file_alias
110
+ webhook_ids = @webhook_ids || []
111
+ form_data.push(['webhook_ids', webhook_ids.join(',')]) unless @webhook_ids.nil? || webhook_ids.empty?
112
+ form_data
113
+ end
114
+
115
+ # Validates the parameters for async auto-polling
116
+ def validate_async_params
117
+ min_delay_sec = 1
118
+ min_initial_delay_sec = 1
119
+ min_retries = 2
120
+
121
+ if @polling_options.delay_sec < min_delay_sec
122
+ raise ArgumentError,
123
+ "Cannot set auto-poll delay to less than #{min_delay_sec} second(s)"
124
+ end
125
+ if @polling_options.initial_delay_sec < min_initial_delay_sec
126
+ raise ArgumentError,
127
+ "Cannot set initial parsing delay to less than #{min_initial_delay_sec} second(s)"
128
+ end
129
+ return unless @polling_options.max_retries < min_retries
130
+
131
+ raise ArgumentError,
132
+ "Cannot set auto-poll retries to less than #{min_retries}"
133
+ end
134
+
135
+ private
136
+
137
+ # Cleans a proper polling options object potentially from a hash.
138
+ # @param [Hash, Input::PollingOptions, nil] polling_options Polling options.
139
+ # @return [Input::PollingOptions] Valid polling options object.
140
+ def get_clean_polling_options(polling_options)
141
+ return Input::PollingOptions.new if polling_options.is_a?(Input::PollingOptions)
142
+
143
+ if polling_options.is_a?(Hash)
144
+ polling_options = polling_options.transform_keys(&:to_sym)
145
+ output_polling_options = Input::PollingOptions.new(
146
+ initial_delay_sec: polling_options.fetch(:initial_delay_sec, 2.0),
147
+ delay_sec: polling_options.fetch(:delay_sec, 1.5),
148
+ max_retries: polling_options.fetch(:max_retries, 80)
149
+ )
150
+ else
151
+ output_polling_options = if polling_options.is_a?(Input::PollingOptions)
152
+ polling_options || Input::PollingOptions.new
153
+ else
154
+ Input::PollingOptions.new
155
+ end
156
+ end
157
+ output_polling_options
158
+ end
159
+ end
160
+ end
161
+ end
162
+ end
@@ -0,0 +1,51 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mindee
4
+ module V2
5
+ module ClientOptions
6
+ # Base parameters for searches.
7
+ class BaseSearchParameters
8
+ # @return [Integer, nil] 1-based page index.
9
+ attr_reader :page
10
+ # @return [Integer, nil] Number of items per page.
11
+ attr_reader :per_page
12
+
13
+ # @param page [Integer, nil] 1-based page index.
14
+ # @param per_page [Integer, nil] Number of items per page.
15
+ def initialize(page: nil, per_page: nil)
16
+ @page = page
17
+ @per_page = per_page
18
+ end
19
+
20
+ # Gets the request parameters for the search request.
21
+ # @return [Hash{String => String, Array<String>}]
22
+ def request_parameters
23
+ params = {} # : Hash[String, String | Array[String]]
24
+ params['page'] = @page.to_s unless @page.nil?
25
+ params['per_page'] = @per_page.to_s unless @per_page.nil?
26
+ params
27
+ end
28
+
29
+ # @return [String] Slug of searchable resources.
30
+ def self.slug
31
+ raise NotImplementedError, 'Subclasses must implement the `slug` class method'
32
+ end
33
+
34
+ # @return [String] Slug of searchable resources.
35
+ def slug
36
+ self.class.slug
37
+ end
38
+
39
+ # @return [Class<Mindee::V2::Parsing::Search::BaseSearchResponse>] Response class for the search.
40
+ def self.response_class
41
+ raise NotImplementedError, 'Subclasses must implement the `response_class` class method'
42
+ end
43
+
44
+ # @return [Class<Mindee::V2::Parsing::Search::BaseSearchResponse>] Response class for the search.
45
+ def response_class
46
+ self.class.response_class
47
+ end
48
+ end
49
+ end
50
+ end
51
+ end
@@ -0,0 +1,4 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'client_options/base_product_parameters'
4
+ require_relative 'client_options/base_search_parameters'
@@ -17,13 +17,13 @@ module Mindee
17
17
  @settings = ApiV2Settings.new(api_key: api_key)
18
18
  end
19
19
 
20
- # Sends a file to the queue.
20
+ # Send a file to the asynchronous processing queue for inference processing.
21
21
  #
22
22
  # @param input_source [Input::Source::LocalInputSource, Input::Source::URLInputSource]
23
- # @param params [Input::BaseParameters]
23
+ # @param params [ClientOptions::BaseProductParameters]
24
24
  # @return [Mindee::V2::Parsing::JobResponse]
25
25
  # @raise [Mindee::Error::MindeeHttpErrorV2]
26
- def req_post_enqueue(input_source, params)
26
+ def req_post_product_enqueue(input_source, params)
27
27
  @settings.check_api_key
28
28
  response = enqueue(
29
29
  input_source,
@@ -57,28 +57,15 @@ module Mindee
57
57
  Mindee::V2::Parsing::JobResponse.new(process_response(response))
58
58
  end
59
59
 
60
- # Retrieves a list of models.
61
- # @param model_name [String, nil]
62
- # @param model_type [String, nil]
63
- # @return [Mindee::V2::Parsing::Search::SearchResponse]
64
- def search_models(model_name, model_type)
65
- Mindee::V2::Parsing::Search::SearchResponse.new(process_response(req_get_search_models(model_name,
66
- model_type)))
67
- end
68
-
69
- private
70
-
71
- # Retrieves a list of models.
72
- # @param model_name [String, nil]
73
- # @param model_type [String, nil]
74
- # @return [Net::HTTPResponse]
75
- def req_get_search_models(model_name, model_type)
76
- url = "#{@settings.base_url}/v2/search/models"
77
- uri = URI(url)
60
+ # Retrieves a list of resources with the given criteria.
61
+ # @param params [ClientOptions::BaseSearchParameters] Search parameters.
62
+ # @return [Mindee::V2::Parsing::Search::BaseSearchResponse] A search response containing the matching
63
+ # resources.
64
+ def req_get_search(params)
65
+ @settings.check_api_key
66
+ uri = URI("#{@settings.base_url}/v2/search/#{params.slug}")
78
67
 
79
- query_params = {} # @type var query_params: Hash[Symbol, String | nil]
80
- query_params[:name] = model_name if model_name
81
- query_params[:model_type] = model_type if model_type
68
+ query_params = params.request_parameters
82
69
  uri.query = URI.encode_www_form(query_params) unless query_params.empty?
83
70
 
84
71
  headers = {
@@ -86,14 +73,18 @@ module Mindee
86
73
  'User-Agent' => @settings.user_agent,
87
74
  }
88
75
  req = Net::HTTP::Get.new(uri, headers)
89
- req['Transfer-Encoding'] = 'chunked'
90
76
 
91
- Net::HTTP.start(uri.hostname, uri.port, use_ssl: true, read_timeout: @settings.request_timeout) do |http|
92
- return http.request(req)
77
+ response = Net::HTTP.start(uri.hostname, uri.port,
78
+ use_ssl: true,
79
+ open_timeout: @settings.request_timeout,
80
+ read_timeout: @settings.request_timeout) do |http|
81
+ http.request(req)
93
82
  end
94
- raise Mindee::Error::MindeeError, 'Could not resolve server response.'
83
+ params.response_class.new(process_response(response))
95
84
  end
96
85
 
86
+ private
87
+
97
88
  # @param resource [String] Resource to check.
98
89
  # @return [Boolean]
99
90
  def uri?(resource)
@@ -155,9 +146,11 @@ module Mindee
155
146
  'User-Agent' => @settings.user_agent,
156
147
  }
157
148
  req = Net::HTTP::Get.new(uri, headers)
158
- req['Transfer-Encoding'] = 'chunked'
159
149
 
160
- Net::HTTP.start(uri.hostname, uri.port, use_ssl: true, read_timeout: @settings.request_timeout) do |http|
150
+ Net::HTTP.start(uri.hostname, uri.port,
151
+ use_ssl: true,
152
+ open_timeout: @settings.request_timeout,
153
+ read_timeout: @settings.request_timeout) do |http|
161
154
  return http.request(req)
162
155
  end
163
156
  raise Mindee::Error::MindeeError, 'Could not resolve server response.'
@@ -191,7 +184,7 @@ module Mindee
191
184
  end
192
185
 
193
186
  # @param input_source [Mindee::Input::Source::LocalInputSource, Mindee::Input::Source::URLInputSource]
194
- # @param params [Input::BaseParameters] Inference options.
187
+ # @param params [ClientOptions::BaseProductParameters] Inference options.
195
188
  # @return [Net::HTTPResponse, nil]
196
189
  def enqueue(input_source, params)
197
190
  uri = URI("#{@settings.base_url}/v2/products/#{params.slug}/enqueue")
@@ -218,7 +211,10 @@ module Mindee
218
211
  req.set_form(form_data, 'multipart/form-data')
219
212
  req['Transfer-Encoding'] = 'chunked'
220
213
 
221
- Net::HTTP.start(uri.hostname, uri.port, use_ssl: true, read_timeout: @settings.request_timeout) do |http|
214
+ Net::HTTP.start(uri.hostname, uri.port,
215
+ use_ssl: true,
216
+ open_timeout: @settings.request_timeout,
217
+ read_timeout: @settings.request_timeout) do |http|
222
218
  return http.request(req)
223
219
  end
224
220
  raise Mindee::Error::MindeeError, 'Could not resolve server response.'
@@ -0,0 +1,47 @@
1
+ # frozen_string_literal: true
2
+
3
+ module Mindee
4
+ module V2
5
+ module Parsing
6
+ module Search
7
+ # Base class for search responses.
8
+ class BaseSearchResponse < CommonResponse
9
+ # Pagination metadata.
10
+ # @return [Mindee::V2::Parsing::Search::PaginationMetadata]
11
+ attr_reader :pagination
12
+
13
+ # @param http_response [Hash] The parsed JSON payload from the API.
14
+ def initialize(http_response)
15
+ super
16
+
17
+ @pagination = PaginationMetadata.new(http_response['pagination'])
18
+ end
19
+
20
+ # Lines composing the response-specific body (header + items).
21
+ # @return [Array<String>]
22
+ def body_lines
23
+ raise NotImplementedError, 'body_lines must be implemented in subclasses'
24
+ end
25
+
26
+ # Pagination metadata (Obsolete).
27
+ # @deprecated Use {#pagination} instead.
28
+ # @return [Mindee::V2::Parsing::Search::PaginationMetadata]
29
+ def pagination_metadata
30
+ pagination
31
+ end
32
+
33
+ # String representation of the search response.
34
+ # @return [String]
35
+ def to_s
36
+ lines = body_lines
37
+ lines.push('Pagination Metadata')
38
+ lines.push('###################')
39
+ lines.push(@pagination.to_s)
40
+
41
+ lines.join("\n")
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
47
+ end
@@ -4,7 +4,7 @@ module Mindee
4
4
  module V2
5
5
  module Parsing
6
6
  module Search
7
- # Individual webhook information.
7
+ # Information about a model's webhook.
8
8
  class ModelWebhook
9
9
  # @return [String] ID of the webhook.
10
10
  attr_reader :id
@@ -15,14 +15,14 @@ module Mindee
15
15
  # @return [String] URL of the webhook.
16
16
  attr_reader :url
17
17
 
18
- # @param payload [Hash] The parsed JSON payload mapping to the search model.
18
+ # @param payload [Hash] The parsed JSON payload mapping to the webhook.
19
19
  def initialize(payload)
20
20
  @id = payload['id']
21
21
  @name = payload['name']
22
22
  @url = payload['url']
23
23
  end
24
24
 
25
- # String representation of the model.
25
+ # String representation of the webhook.
26
26
  # @return [String]
27
27
  def to_s
28
28
  [
@@ -4,7 +4,7 @@ module Mindee
4
4
  module V2
5
5
  module Parsing
6
6
  module Search
7
- # Pagination Metadata data associated with model search.
7
+ # Pagination metadata associated with searches.
8
8
  class PaginationMetadata
9
9
  # @return [Integer] Number of items per page.
10
10
  attr_reader :per_page
@@ -4,8 +4,9 @@ module Mindee
4
4
  module V2
5
5
  module Parsing
6
6
  module Search
7
- # Array of search models.
7
+ # List of search models.
8
8
  class SearchModels < Array
9
+ # @param prediction [Array<Hash>] The parsed JSON payload mapping to the search models.
9
10
  def initialize(prediction)
10
11
  super(prediction.map { |entry| SearchModel.new(entry) })
11
12
  end
@@ -0,0 +1,60 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'time'
4
+
5
+ module Mindee
6
+ module V2
7
+ module Parsing
8
+ module Search
9
+ # Individual RAG document information.
10
+ class SearchRAGDocument
11
+ # @return [String] Unique identifier of the RAG document.
12
+ attr_reader :id
13
+
14
+ # @return [String] Model identifier linked to the RAG document.
15
+ attr_reader :model_id
16
+
17
+ # @return [String] Original filename of the uploaded document.
18
+ attr_reader :filename
19
+
20
+ # @return [Time] Date and time of the document creation.
21
+ attr_reader :created_at
22
+
23
+ # @return [Integer] Number of times this document was used in an inference.
24
+ attr_reader :total_matches
25
+
26
+ # @return [Time, nil] Date and time of the latest matching inference, if any.
27
+ attr_reader :last_match_at
28
+
29
+ # @return [String] Current status of the RAG document.
30
+ attr_reader :status
31
+
32
+ # @param server_response [Hash] The parsed JSON payload mapping to the RAG document.
33
+ def initialize(server_response)
34
+ @id = server_response['id']
35
+ @model_id = server_response['model_id']
36
+ @filename = server_response['filename']
37
+ @created_at = Time.iso8601(server_response['created_at'])
38
+ @total_matches = server_response['total_matches']
39
+ @last_match_at = (Time.iso8601(server_response['last_match_at']) if server_response['last_match_at'])
40
+ @status = server_response['status']
41
+ end
42
+
43
+ # String representation of the RAG document.
44
+ # @return [String]
45
+ def to_s
46
+ [
47
+ ":ID: #{@id}",
48
+ ":Model ID: #{@model_id}",
49
+ ":Filename: #{@filename}",
50
+ ":Created At: #{@created_at}",
51
+ ":Total Matches: #{@total_matches}",
52
+ ":Last Match At: #{@last_match_at}",
53
+ ":Status: #{@status}",
54
+ ].join("\n")
55
+ end
56
+ end
57
+ end
58
+ end
59
+ end
60
+ end
@@ -0,0 +1,39 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative 'search_rag_document'
4
+
5
+ module Mindee
6
+ module V2
7
+ module Parsing
8
+ module Search
9
+ # List of RAG documents.
10
+ class SearchRAGDocuments < Array
11
+ # @param raw_response [Array<Hash>] The parsed JSON payload mapping to the RAG documents.
12
+ def initialize(raw_response)
13
+ super(raw_response.map { |entry| SearchRAGDocument.new(entry) })
14
+ end
15
+
16
+ # Default string representation.
17
+ # @return [String]
18
+ def to_s
19
+ return "\n" if empty?
20
+
21
+ lines = flat_map do |rag_document|
22
+ [
23
+ "* :ID: #{rag_document.id}",
24
+ " :Model ID: #{rag_document.model_id}",
25
+ " :Filename: #{rag_document.filename}",
26
+ " :Created At: #{rag_document.created_at}",
27
+ " :Total Matches: #{rag_document.total_matches}",
28
+ " :Last Match At: #{rag_document.last_match_at}",
29
+ " :Status: #{rag_document.status}",
30
+ ]
31
+ end
32
+
33
+ "#{lines.join("\n")}\n"
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
39
+ end
@@ -5,35 +5,8 @@ module Mindee
5
5
  module Parsing
6
6
  module Search
7
7
  # Models search response.
8
- class SearchResponse < CommonResponse
9
- # @return [Search::SearchModels] Parsed search payload.
10
- attr_reader :models
11
- # @return [Search::PaginationMetadata] Pagination metadata.
12
- attr_reader :pagination
13
- # @return [Search::PaginationMetadata] Pagination metadata.
14
- attr_reader :pagination_metadata
15
-
16
- def initialize(server_response)
17
- super
18
-
19
- @models = SearchModels.new(server_response['models'])
20
- @pagination = PaginationMetadata.new(server_response['pagination'])
21
- @pagination_metadata = @pagination
22
- end
23
-
24
- # String representation.
25
- # @return [String]
26
- def to_s
27
- [
28
- 'Models',
29
- '######',
30
- @models.to_s,
31
- 'Pagination Metadata',
32
- '###################',
33
- @pagination.to_s,
34
- '',
35
- ].join("\n")
36
- end
8
+ # @deprecated Use {Mindee::V2::Search::Models::ModelSearchResponse} instead.
9
+ class SearchResponse < Mindee::V2::Search::Models::ModelSearchResponse
37
10
  end
38
11
  end
39
12
  end
@@ -1,7 +1,11 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative 'search/pagination_metadata'
4
+ require_relative 'search/model_webhook'
4
5
  require_relative 'search/search_model'
5
6
  require_relative 'search/search_models'
7
+ require_relative 'search/search_rag_document'
8
+ require_relative 'search/search_rag_documents'
9
+ require_relative 'search/base_search_response'
10
+ require_relative '../search/models/model_search_response'
6
11
  require_relative 'search/search_response'
7
- require_relative 'search/model_webhook'
@@ -1,7 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require_relative '../parsing/base_response'
4
- require_relative '../../input/base_parameters'
4
+ require_relative '../client_options/base_product_parameters'
5
5
 
6
6
  module Mindee
7
7
  module V2
@@ -11,7 +11,7 @@ module Mindee
11
11
  # @return [String] The slug of the endpoint used for this response
12
12
  @slug = ''
13
13
  # @return [Class<BaseParameters>] The class of the parameters used for this response
14
- @params_type = Mindee::Input::BaseParameters
14
+ @params_type = Mindee::V2::ClientOptions::BaseProductParameters
15
15
  # @return [Class<BaseResponse>] The class of the response used for this product
16
16
  @response_type = Mindee::V2::Parsing::BaseResponse
17
17
 
@@ -13,11 +13,10 @@ 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
- # rubocop:disable Style/GuardClause
16
+ # rubocop:disable-next Style/GuardClause
17
17
  unless server_response['extraction_response'].nil?
18
18
  @extraction_response = V2::Product::Extraction::ExtractionResponse.new(server_response['extraction_response'])
19
19
  end
20
- # rubocop:enable Style/GuardClause
21
20
  end
22
21
 
23
22
  # @return [String] String representation.
@@ -7,7 +7,7 @@ module Mindee
7
7
  # Classification parameters.
8
8
  module Params
9
9
  # Parameters accepted by the classification utility v2 endpoint.
10
- class ClassificationParameters < Mindee::Input::BaseParameters
10
+ class ClassificationParameters < Mindee::V2::ClientOptions::BaseProductParameters
11
11
  # @return [String] Slug for the endpoint.
12
12
  def self.slug
13
13
  'classification'
@@ -16,11 +16,10 @@ 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
- # rubocop:disable Style/GuardClause
19
+ # rubocop:disable-next Style/GuardClause
20
20
  unless server_response['extraction_response'].nil?
21
21
  @extraction_response = V2::Product::Extraction::ExtractionResponse.new(server_response['extraction_response'])
22
22
  end
23
- # rubocop:enable Style/GuardClause
24
23
  end
25
24
 
26
25
  # String representation.
@@ -7,7 +7,7 @@ module Mindee
7
7
  # Crop parameters.
8
8
  module Params
9
9
  # Parameters accepted by the crop utility v2 endpoint.
10
- class CropParameters < Mindee::Input::BaseParameters
10
+ class CropParameters < Mindee::V2::ClientOptions::BaseProductParameters
11
11
  # @return [String] Slug for the endpoint.
12
12
  def self.slug
13
13
  'crop'
@@ -1,6 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require_relative '../../../../input/base_parameters'
3
+ require_relative '../../../client_options/base_product_parameters'
4
4
  require_relative 'data_schema'
5
5
 
6
6
  module Mindee
@@ -9,7 +9,7 @@ module Mindee
9
9
  module Extraction
10
10
  module Params
11
11
  # Parameters accepted by the extraction v2 endpoint.
12
- class ExtractionParameters < Mindee::Input::BaseParameters
12
+ class ExtractionParameters < Mindee::V2::ClientOptions::BaseProductParameters
13
13
  # @return [Boolean, nil] Enhance extraction accuracy with Retrieval-Augmented Generation.
14
14
  attr_reader :rag
15
15