diff --git a/lib/mindee/client_v2.rb b/lib/mindee/client_v2.rb index 39def57c..835d7642 100644 --- a/lib/mindee/client_v2.rb +++ b/lib/mindee/client_v2.rb @@ -19,47 +19,27 @@ def initialize(api_key: '') @mindee_api = Mindee::HTTP::MindeeApiV2.new(api_key: api_key) end - # Retrieves an inference. - # @param inference_id [String] - # @return [Mindee::Parsing::V2::InferenceResponse] - def get_inference(inference_id) - @mindee_api.req_get_inference(inference_id) - end - # Retrieves a result from a given queue or URL to the result. # @param product [Class] The return class. # @param resource [String] ID of the inference or URL to the result. - # @return [Mindee::Parsing::V2::BaseResponse] + # @return [Mindee::V2::Parsing::BaseResponse] def get_result(product, resource) @mindee_api.req_get_result(product, resource) end # Retrieves an inference from a given queue or URL to the job. # @param job_id [String] ID of the job. - # @return [Mindee::Parsing::V2::JobResponse] + # @return [Mindee::V2::Parsing::JobResponse] def get_job(job_id) @mindee_api.req_get_job(job_id) end - # Enqueue a document for async parsing. - # @param input_source [Mindee::Input::Source::LocalInputSource, Mindee::Input::Source::URLInputSource] - # The source of the input document (local file or URL). - # @param params [Hash, InferenceParameters] - # @return [Mindee::Parsing::V2::JobResponse] - def enqueue_inference(input_source, params, disable_redundant_warnings: false) - unless disable_redundant_warnings - warn '[DEPRECATION] `enqueue_inference` is deprecated; use `enqueue` instead.', uplevel: 1 - end - normalized_params = normalize_parameters(Input::InferenceParameters, params) - enqueue(Mindee::Parsing::V2::Inference, input_source, normalized_params) - end - # Enqueue a document for async parsing. # @param product [Class] The return class. # @param input_source [Mindee::Input::Source::LocalInputSource, Mindee::Input::Source::URLInputSource] # The source of the input document (local file or URL). - # @param params [Hash, InferenceParameters] Parameters for the inference. - # @return [Mindee::Parsing::V2::JobResponse] + # @param params [Hash, Input::BaseParameters] Parameters for the inference. + # @return [Mindee::V2::Parsing::JobResponse] def enqueue( product, input_source, @@ -77,8 +57,8 @@ def enqueue( # @param product [Class] The return class. # @param input_source [Mindee::Input::Source::LocalInputSource, Mindee::Input::Source::URLInputSource] # The source of the input document (local file or URL). - # @param params [Hash, InferenceParameters] Parameters for the inference. - # @return [Mindee::Parsing::Common::ApiResponse] + # @param params [Hash, Input::BaseParameters] Parameters for the inference. + # @return [Parsing::BaseResponse] def enqueue_and_get_result( product, input_source, @@ -130,26 +110,7 @@ def enqueue_and_get_result( "Asynchronous parsing request timed out after #{sec_count} seconds" end - # Enqueue a document for async parsing and automatically try to retrieve it. - # @param input_source [Mindee::Input::Source::LocalInputSource, Mindee::Input::Source::URLInputSource] - # The source of the input document (local file or URL). - # @param params [Hash, InferenceParameters] Parameters for the inference. - # @return [Mindee::Parsing::V2::InferenceResponse] - def enqueue_and_get_inference(input_source, params, disable_redundant_warnings: false) - unless disable_redundant_warnings - warn '[DEPRECATION] `enqueue_and_get_inference` is deprecated; use `enqueue_and_get_result` instead.', - uplevel: 1 - end - - response = enqueue_and_get_result(Mindee::Parsing::V2::Inference, input_source, params) - unless response.is_a?(Mindee::Parsing::V2::InferenceResponse) - raise TypeError, "Invalid response type \"#{response.class}\"" - end - - response - end - - # If needed, converts the parsing options provided as a hash into a proper InferenceParameters object. + # If needed, converts the parsing options provided as a hash into a proper BaseParameters subclass object. # @param params [Hash, Class] Params. # @return [BaseParameters] def normalize_parameters(param_class, params) diff --git a/lib/mindee/errors/mindee_http_error_v2.rb b/lib/mindee/errors/mindee_http_error_v2.rb index 90af794a..a482d1df 100644 --- a/lib/mindee/errors/mindee_http_error_v2.rb +++ b/lib/mindee/errors/mindee_http_error_v2.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true require_relative 'mindee_error' -require_relative '../parsing/v2/error_item' +require_relative '../v2/parsing/error_item' module Mindee module Errors @@ -18,9 +18,9 @@ class MindeeHTTPErrorV2 < MindeeError # @return [Array] A list of explicit error details. attr_reader :errors - # @param http_error [Hash, Mindee::Parsing::V2::ErrorResponse] + # @param http_error [Hash, Mindee::V2::Parsing::ErrorResponse] def initialize(http_error) - if http_error.is_a?(Parsing::V2::ErrorResponse) + if http_error.is_a?(V2::Parsing::ErrorResponse) http_error = { 'detail' => http_error.detail, 'status' => http_error.status, 'title' => http_error.title, @@ -33,7 +33,7 @@ def initialize(http_error) @code = http_error['code'] @errors = if http_error.key?('errors') http_error['errors'].map do |error| - Mindee::Parsing::V2::ErrorItem.new(error) + Mindee::V2::Parsing::ErrorItem.new(error) end else [] diff --git a/lib/mindee/http/mindee_api_v2.rb b/lib/mindee/http/mindee_api_v2.rb index 1c1d4b7e..f911c283 100644 --- a/lib/mindee/http/mindee_api_v2.rb +++ b/lib/mindee/http/mindee_api_v2.rb @@ -3,7 +3,6 @@ require_relative 'api_settings_v2' require_relative '../input' require_relative '../errors' -require_relative '../parsing/v2' module Mindee module HTTP @@ -17,11 +16,11 @@ def initialize(api_key: nil) @settings = ApiSettingsV2.new(api_key: api_key) end - # Sends a file to the inference queue. + # Sends a file to the queue. # # @param input_source [Input::Source::LocalInputSource, Input::Source::URLInputSource] # @param params [Input::BaseParameters] - # @return [Mindee::Parsing::V2::JobResponse] + # @return [Mindee::V2::Parsing::JobResponse] # @raise [Mindee::Errors::MindeeHttpErrorV2] def req_post_enqueue(input_source, params) @settings.check_api_key @@ -29,21 +28,13 @@ def req_post_enqueue(input_source, params) input_source, params ) - Mindee::Parsing::V2::JobResponse.new(process_response(response)) - end - - # Retrieves a queued inference. - # - # @param inference_id [String] - # @return [Mindee::Parsing::V2::InferenceResponse] - def req_get_inference(inference_id) - req_get_result(Parsing::V2::Inference, inference_id) + Mindee::V2::Parsing::JobResponse.new(process_response(response)) end # Retrieves a result from a given queue. # @param product [Class] The return class. # @param resource [String] ID of the inference or URL to the result. - # @return [Mindee::Parsing::V2::BaseResponse] + # @return [Mindee::V2::Parsing::BaseResponse] def req_get_result(product, resource) return req_get_result_url(product.response_type, resource) if uri?(resource) @@ -58,13 +49,11 @@ def req_get_result(product, resource) # Retrieves a queued job. # # @param job_id [String] ID of the job or URL to the job. - # @return [Mindee::Parsing::V2::JobResponse] + # @return [Mindee::V2::Parsing::JobResponse] def req_get_job(job_id) @settings.check_api_key - response = inference_job_req_get( - job_id - ) - Mindee::Parsing::V2::JobResponse.new(process_response(response)) + response = poll("#{@settings.base_url}/jobs/#{job_id}") + Mindee::V2::Parsing::JobResponse.new(process_response(response)) end private @@ -72,18 +61,18 @@ def req_get_job(job_id) # Retrieves a queued job. # # @param url [String] - # @return [Mindee::Parsing::V2::JobResponse] + # @return [Mindee::V2::Parsing::JobResponse] def req_get_job_url(url) @settings.check_api_key response = poll(url) - Mindee::Parsing::V2::JobResponse.new(process_response(response)) + Mindee::V2::Parsing::JobResponse.new(process_response(response)) end # Retrieves a queued job. # - # @param result_class [Mindee::V2::Parsing::BaseResponse] + # @param result_class [Class] # @param url [String] - # @return [Mindee::Parsing::V2::JobResponse] + # @return [Mindee::V2::Parsing::BaseResponse] def req_get_result_url(result_class, url) @settings.check_api_key response = poll(url) @@ -137,22 +126,6 @@ def poll(url) raise Mindee::Errors::MindeeError, 'Could not resolve server response.' end - # Polls the API for the status of a job. - # - # @param job_id [String] ID of the job. - # @return [Net::HTTPResponse] - def inference_job_req_get(job_id) - poll("#{@settings.base_url}/jobs/#{job_id}") - end - - # Polls the API for the result of an inference. - # - # @param queue_id [String] ID of the queue. - # @return [Net::HTTPResponse] - def inference_result_req_get(queue_id) - poll("#{@settings.base_url}/inferences/#{queue_id}") - end - # Polls the API for the result of an inference. # # @param queue_id [String] ID of the queue. @@ -164,7 +137,7 @@ def result_req_get(queue_id, product) # Handle parameters for the enqueue form # @param form_data [Array] Array of form fields - # @param params [Input::InferenceParameters] Inference options. + # @param params [Input::BaseParameters] Inference options. def enqueue_form_options(form_data, params) # deal with optional features form_data.push(['rag', params.rag.to_s]) unless params.rag.nil? diff --git a/lib/mindee/input.rb b/lib/mindee/input.rb index 9bbf38a8..ea85e6fd 100644 --- a/lib/mindee/input.rb +++ b/lib/mindee/input.rb @@ -1,6 +1,5 @@ # frozen_string_literal: true require_relative 'input/data_schema' -require_relative 'input/inference_parameters' require_relative 'input/polling_options' require_relative 'input/sources' diff --git a/lib/mindee/input/inference_parameters.rb b/lib/mindee/input/inference_parameters.rb deleted file mode 100644 index a377d052..00000000 --- a/lib/mindee/input/inference_parameters.rb +++ /dev/null @@ -1,119 +0,0 @@ -# frozen_string_literal: true - -require_relative 'data_schema' -require_relative '../input/base_parameters' - -module Mindee - module Input - # Parameters to set when sending a file for inference. - class InferenceParameters < Mindee::Input::BaseParameters - # @return [Boolean, nil] Enhance extraction accuracy with Retrieval-Augmented Generation. - attr_reader :rag - - # @return [Boolean, nil] Extract the full text content from the document as strings, - # and fill the raw_text` attribute. - attr_reader :raw_text - - # @return [Boolean, nil] Calculate bounding box polygons for all fields, - # and fill their `locations` attribute. - attr_reader :polygon - - # @return [Boolean, nil] Boost the precision and accuracy of all extractions. - # Calculate confidence scores for all fields, and fill their confidence attribute. - attr_reader :confidence - - # @return [String, nil] Additional text context used by the model during inference. - # Not recommended, for specific use only. - attr_reader :text_context - - # @return [DataSchemaField] - attr_reader :data_schema - - # @return [String] Slug for the endpoint. - def self.slug - 'extraction' - end - - # rubocop:disable Metrics/ParameterLists - # @param [String] model_id ID of the model - # @param [Boolean, nil] rag Whether to enable RAG. - # @param [Boolean, nil] raw_text Whether to enable rax text. - # @param [Boolean, nil] polygon Whether to enable polygons. - # @param [Boolean, nil] confidence Whether to enable confidence scores. - # @param [String, nil] file_alias File alias, if applicable. - # @param [Array, nil] webhook_ids - # @param [String, nil] text_context - # @param [Hash, nil] polling_options - # @param [Boolean, nil] close_file - # @param [DataSchemaField, String, Hash nil] data_schema - def initialize( - model_id, - rag: nil, - raw_text: nil, - polygon: nil, - confidence: nil, - file_alias: nil, - webhook_ids: nil, - text_context: nil, - polling_options: nil, - close_file: true, - data_schema: nil - ) - super( - model_id, - file_alias: file_alias, - webhook_ids: webhook_ids, - polling_options: polling_options, - close_file: close_file - ) - - @rag = rag - @raw_text = raw_text - @polygon = polygon - @confidence = confidence - @text_context = text_context - @data_schema = DataSchema.new(data_schema) unless data_schema.nil? - # rubocop:enable Metrics/ParameterLists - end - - # Appends inference-specific form data to the provided array. - # @param [Array] form_data Array of form fields - # @return [Array] - def append_form_data(form_data) - new_form_data = super - - new_form_data.push(['rag', @rag.to_s]) unless @rag.nil? - new_form_data.push(['raw_text', @raw_text.to_s]) unless @raw_text.nil? - new_form_data.push(['polygon', @polygon.to_s]) unless @polygon.nil? - new_form_data.push(['confidence', @confidence.to_s]) unless @confidence.nil? - new_form_data.push(['text_context', @text_context]) if @text_context - new_form_data.push(['data_schema', @data_schema.to_s]) if @data_schema - - new_form_data - end - - # Loads a prediction from a Hash. - # @param [Hash] params Parameters to provide as a hash. - # @return [InferenceParameters] - def self.from_hash(params: {}) - rag = params.fetch(:rag, nil) - raw_text = params.fetch(:raw_text, nil) - polygon = params.fetch(:polygon, nil) - confidence = params.fetch(:confidence, nil) - base_params = load_from_hash(params: params) - new_params = base_params.merge(rag: rag, raw_text: raw_text, polygon: polygon, confidence: confidence) - model_id = new_params.fetch(:model_id) - - InferenceParameters.new( - model_id, rag: rag, - raw_text: raw_text, - polygon: polygon, - confidence: confidence, - file_alias: params.fetch(:file_alias, nil), - webhook_ids: params.fetch(:webhook_ids, nil), - close_file: params.fetch(:close_file, true) - ) - end - end - end -end diff --git a/lib/mindee/input/local_response.rb b/lib/mindee/input/local_response.rb index 5e6c1440..b32711e5 100644 --- a/lib/mindee/input/local_response.rb +++ b/lib/mindee/input/local_response.rb @@ -70,12 +70,10 @@ def valid_hmac_signature?(secret_key, signature) end # Deserializes a loaded response - # @param response_class [Parsing::V2::CommonResponse] class to return. - # @return [Parsing::V2::JobResponse, Mindee::V2::Parsing::CommonResponse] + # @param response_class [Class] class to return. + # @return [V2::Parsing::JobResponse, Mindee::V2::Parsing::BaseResponse] def deserialize_response(response_class) - response_class.new(as_hash) # : Mindee::Parsing::V2::JobResponse | Mindee::Parsing::V2::InferenceResponse - rescue StandardError - raise Errors::MindeeInputError, 'Invalid response provided.' + response_class.new(as_hash) # : Mindee::V2::Parsing::JobResponse | Mindee::V2::Parsing::BaseResponse end end end diff --git a/lib/mindee/parsing/v2.rb b/lib/mindee/parsing/v2.rb deleted file mode 100644 index d5ae4ebb..00000000 --- a/lib/mindee/parsing/v2.rb +++ /dev/null @@ -1,16 +0,0 @@ -# frozen_string_literal: true - -require_relative 'v2/common_response' -require_relative 'v2/error_response' -require_relative 'v2/field' -require_relative 'v2/inference' -require_relative 'v2/inference_file' -require_relative 'v2/inference_model' -require_relative 'v2/inference_response' -require_relative 'v2/inference_result' -require_relative 'v2/inference_active_options' -require_relative 'v2/job' -require_relative 'v2/job_response' -require_relative 'v2/job_webhook' -require_relative 'v2/raw_text' -require_relative 'v2/raw_text_page' diff --git a/lib/mindee/parsing/v2/inference.rb b/lib/mindee/parsing/v2/inference.rb deleted file mode 100644 index 32801564..00000000 --- a/lib/mindee/parsing/v2/inference.rb +++ /dev/null @@ -1,44 +0,0 @@ -# frozen_string_literal: true - -require_relative 'inference_job' -require_relative 'inference_model' -require_relative 'inference_file' -require_relative 'inference_result' -require_relative 'inference_active_options' -require_relative '../../v2/parsing/base_inference' - -module Mindee - module Parsing - module V2 - # Complete data returned by an inference request. - class Inference < Mindee::V2::Parsing::BaseInference - # @return [InferenceActiveOptions] Options which were activated during the inference. - attr_reader :active_options - # @return [InferenceResult] Result contents. - attr_reader :result - - @params_type = Input::InferenceParameters - @slug = 'extraction' - @response_type = InferenceResponse - - # @param server_response [Hash] Hash representation of the JSON returned by the service. - def initialize(server_response) - super - @active_options = InferenceActiveOptions.new(server_response['active_options']) - @result = InferenceResult.new(server_response['result']) - end - - # String representation. - # @return [String] - def to_s - [ - super, - @active_options.to_s, - @result.to_s, - '', - ].join("\n") - end - end - end - end -end diff --git a/lib/mindee/parsing/v2/inference_response.rb b/lib/mindee/parsing/v2/inference_response.rb deleted file mode 100644 index 7911c33b..00000000 --- a/lib/mindee/parsing/v2/inference_response.rb +++ /dev/null @@ -1,33 +0,0 @@ -# frozen_string_literal: true - -require_relative 'common_response' -require_relative 'inference' -require_relative '../../v2/parsing/base_response' - -module Mindee - module Parsing - module V2 - # HTTP response wrapper that embeds a V2 Inference. - class InferenceResponse < Mindee::V2::Parsing::BaseResponse - # @return [Inference] Parsed inference payload. - attr_reader :inference - - @slug = 'extraction' - @_params_type = Input::InferenceParameters - - # @param server_response [Hash] Hash parsed from the API JSON response. - def initialize(server_response) - super - - @inference = Inference.new(server_response['inference']) - end - - # String representation. - # @return [String] - def to_s - @inference.to_s - end - end - end - end -end diff --git a/lib/mindee/parsing/v2/inference_result.rb b/lib/mindee/parsing/v2/inference_result.rb deleted file mode 100644 index 8ee1bd1c..00000000 --- a/lib/mindee/parsing/v2/inference_result.rb +++ /dev/null @@ -1,42 +0,0 @@ -# frozen_string_literal: true - -require_relative 'field/inference_fields' -require_relative 'raw_text' -require_relative 'rag_metadata' - -module Mindee - module Parsing - module V2 - # Wrapper for the result of a V2 inference request. - class InferenceResult - # @return [Mindee::Parsing::V2::Field::InferenceFields] Fields produced by the model. - attr_reader :fields - # @return [Mindee::Parsing::V2::RawText, nil] Optional extra data. - attr_reader :raw_text - # @return [Mindee::Parsing::V2::RAGMetadata, nil] Optional RAG metadata. - attr_reader :rag - - # @param server_response [Hash] Hash version of the JSON returned by the API. - def initialize(server_response) - raise ArgumentError, 'server_response must be a Hash' unless server_response.is_a?(Hash) - - @fields = Field::InferenceFields.new(server_response['fields']) - - @raw_text = server_response['raw_text'] ? RawText.new(server_response['raw_text']) : nil - @rag = (V2::RAGMetadata.new(server_response['rag']) if server_response.key?('rag') && server_response['rag']) - end - - # String representation. - # @return [String] - def to_s - parts = [ - 'Fields', - '======', - @fields.to_s, - ] - parts.join("\n") - end - end - end - end -end diff --git a/lib/mindee/v2.rb b/lib/mindee/v2.rb index 6950e5f9..59d6e415 100644 --- a/lib/mindee/v2.rb +++ b/lib/mindee/v2.rb @@ -1,4 +1,4 @@ # frozen_string_literal: true -require_relative 'parsing' -require_relative 'product' +require_relative 'v2/parsing' +require_relative 'v2/product' diff --git a/lib/mindee/v2/parsing.rb b/lib/mindee/v2/parsing.rb new file mode 100644 index 00000000..f8784e63 --- /dev/null +++ b/lib/mindee/v2/parsing.rb @@ -0,0 +1,15 @@ +# frozen_string_literal: true + +require_relative 'parsing/common_response' +require_relative 'parsing/error_response' +require_relative 'parsing/field' +require_relative 'parsing/inference_file' +require_relative 'parsing/inference_job' +require_relative 'parsing/inference_model' +require_relative 'parsing/inference_active_options' +require_relative 'parsing/job' +require_relative 'parsing/job_response' +require_relative 'parsing/job_webhook' +require_relative 'parsing/rag_metadata' +require_relative 'parsing/raw_text' +require_relative 'parsing/raw_text_page' diff --git a/lib/mindee/v2/parsing/base_inference.rb b/lib/mindee/v2/parsing/base_inference.rb index 31cbe87c..8e62cf02 100644 --- a/lib/mindee/v2/parsing/base_inference.rb +++ b/lib/mindee/v2/parsing/base_inference.rb @@ -1,7 +1,7 @@ # frozen_string_literal: true require_relative '../product/base_product' -require_relative '../../parsing/v2/inference_response' +require_relative '../parsing' module Mindee module V2 @@ -10,9 +10,9 @@ module Parsing class BaseInference < Mindee::V2::Product::BaseProduct # @return [InferenceJob] Metadata about the job. attr_reader :job - # @return [Parsing::V2::InferenceModel] Model info for the inference. + # @return [V2::Parsing::InferenceModel] Model info for the inference. attr_reader :model - # @return [Parsing::V2::InferenceFile] File info for the inference. + # @return [V2::Parsing::InferenceFile] File info for the inference. attr_reader :file # @return [String] ID of the inference. attr_reader :id @@ -21,10 +21,10 @@ def initialize(http_response) raise ArgumentError, 'Server response must be a Hash' unless http_response.is_a?(Hash) super() - @model = Mindee::Parsing::V2::InferenceModel.new(http_response['model']) - @file = Mindee::Parsing::V2::InferenceFile.new(http_response['file']) + @model = Mindee::V2::Parsing::InferenceModel.new(http_response['model']) + @file = Mindee::V2::Parsing::InferenceFile.new(http_response['file']) @id = http_response['id'] - @job = Mindee::Parsing::V2::InferenceJob.new(http_response['job']) if http_response.key?('job') + @job = Mindee::V2::Parsing::InferenceJob.new(http_response['job']) if http_response.key?('job') end # String representation. diff --git a/lib/mindee/v2/parsing/base_response.rb b/lib/mindee/v2/parsing/base_response.rb index a604e156..126baeec 100644 --- a/lib/mindee/v2/parsing/base_response.rb +++ b/lib/mindee/v2/parsing/base_response.rb @@ -1,10 +1,12 @@ # frozen_string_literal: true +require_relative 'common_response' + module Mindee module V2 module Parsing # Base class for V2 inference responses. - class BaseResponse < Mindee::Parsing::V2::CommonResponse + class BaseResponse < Mindee::V2::Parsing::CommonResponse # @return [BaseInference] The inference result for a split utility request attr_reader :inference end diff --git a/lib/mindee/parsing/v2/common_response.rb b/lib/mindee/v2/parsing/common_response.rb similarity index 91% rename from lib/mindee/parsing/v2/common_response.rb rename to lib/mindee/v2/parsing/common_response.rb index b2893804..ad631411 100644 --- a/lib/mindee/parsing/v2/common_response.rb +++ b/lib/mindee/v2/parsing/common_response.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true module Mindee - module Parsing - module V2 + module V2 + module Parsing # Base class for inference and job responses on the V2 API. class CommonResponse # @return [Hash] diff --git a/lib/mindee/parsing/v2/error_item.rb b/lib/mindee/v2/parsing/error_item.rb similarity index 94% rename from lib/mindee/parsing/v2/error_item.rb rename to lib/mindee/v2/parsing/error_item.rb index bc81da6a..d7747578 100644 --- a/lib/mindee/parsing/v2/error_item.rb +++ b/lib/mindee/v2/parsing/error_item.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true module Mindee - module Parsing - module V2 + module V2 + module Parsing # Individual error item. class ErrorItem # @return [String, nil] A JSON Pointer to the location of the body property. diff --git a/lib/mindee/parsing/v2/error_response.rb b/lib/mindee/v2/parsing/error_response.rb similarity index 98% rename from lib/mindee/parsing/v2/error_response.rb rename to lib/mindee/v2/parsing/error_response.rb index 6745603e..cec15610 100644 --- a/lib/mindee/parsing/v2/error_response.rb +++ b/lib/mindee/v2/parsing/error_response.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true module Mindee - module Parsing - module V2 + module V2 + module Parsing # Encapsulates information returned by the API when an error occurs. class ErrorResponse # @return [Integer] The HTTP status code returned by the server. diff --git a/lib/mindee/parsing/v2/field.rb b/lib/mindee/v2/parsing/field.rb similarity index 100% rename from lib/mindee/parsing/v2/field.rb rename to lib/mindee/v2/parsing/field.rb diff --git a/lib/mindee/parsing/v2/field/base_field.rb b/lib/mindee/v2/parsing/field/base_field.rb similarity index 98% rename from lib/mindee/parsing/v2/field/base_field.rb rename to lib/mindee/v2/parsing/field/base_field.rb index 1256c642..89913d73 100644 --- a/lib/mindee/parsing/v2/field/base_field.rb +++ b/lib/mindee/v2/parsing/field/base_field.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true module Mindee - module Parsing - module V2 + module V2 + module Parsing # Field submodule for V2. module Field # Base class for V2 fields. diff --git a/lib/mindee/parsing/v2/field/field_confidence.rb b/lib/mindee/v2/parsing/field/field_confidence.rb similarity index 99% rename from lib/mindee/parsing/v2/field/field_confidence.rb rename to lib/mindee/v2/parsing/field/field_confidence.rb index 0570b7a9..64719674 100644 --- a/lib/mindee/parsing/v2/field/field_confidence.rb +++ b/lib/mindee/v2/parsing/field/field_confidence.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true module Mindee - module Parsing - module V2 + module V2 + module Parsing module Field # Confidence level of a field as returned by the V2 API. class FieldConfidence diff --git a/lib/mindee/parsing/v2/field/field_location.rb b/lib/mindee/v2/parsing/field/field_location.rb similarity index 96% rename from lib/mindee/parsing/v2/field/field_location.rb rename to lib/mindee/v2/parsing/field/field_location.rb index d5869b57..5b1e49bc 100644 --- a/lib/mindee/parsing/v2/field/field_location.rb +++ b/lib/mindee/v2/parsing/field/field_location.rb @@ -3,8 +3,8 @@ require_relative '../../../geometry/polygon' module Mindee - module Parsing - module V2 + module V2 + module Parsing module Field # Location of a field. class FieldLocation diff --git a/lib/mindee/parsing/v2/field/inference_fields.rb b/lib/mindee/v2/parsing/field/inference_fields.rb similarity index 99% rename from lib/mindee/parsing/v2/field/inference_fields.rb rename to lib/mindee/v2/parsing/field/inference_fields.rb index 8d1094c9..16aa7fc8 100644 --- a/lib/mindee/parsing/v2/field/inference_fields.rb +++ b/lib/mindee/v2/parsing/field/inference_fields.rb @@ -3,8 +3,8 @@ require_relative 'base_field' module Mindee - module Parsing - module V2 + module V2 + module Parsing module Field # Represents a hash-like collection of inference fields, providing methods for # retrieval and string representation. diff --git a/lib/mindee/parsing/v2/field/list_field.rb b/lib/mindee/v2/parsing/field/list_field.rb similarity index 98% rename from lib/mindee/parsing/v2/field/list_field.rb rename to lib/mindee/v2/parsing/field/list_field.rb index 33bb5470..ab8c36a1 100644 --- a/lib/mindee/parsing/v2/field/list_field.rb +++ b/lib/mindee/v2/parsing/field/list_field.rb @@ -3,8 +3,8 @@ require_relative 'base_field' module Mindee - module Parsing - module V2 + module V2 + module Parsing module Field # Represents a field that contains a list of items. class ListField < BaseField diff --git a/lib/mindee/parsing/v2/field/object_field.rb b/lib/mindee/v2/parsing/field/object_field.rb similarity index 99% rename from lib/mindee/parsing/v2/field/object_field.rb rename to lib/mindee/v2/parsing/field/object_field.rb index 39a1f548..a0ce89a4 100644 --- a/lib/mindee/parsing/v2/field/object_field.rb +++ b/lib/mindee/v2/parsing/field/object_field.rb @@ -4,8 +4,8 @@ require_relative 'inference_fields' module Mindee - module Parsing - module V2 + module V2 + module Parsing module Field # A field containing a nested set of inference fields. class ObjectField < BaseField diff --git a/lib/mindee/parsing/v2/field/simple_field.rb b/lib/mindee/v2/parsing/field/simple_field.rb similarity index 98% rename from lib/mindee/parsing/v2/field/simple_field.rb rename to lib/mindee/v2/parsing/field/simple_field.rb index f5e1903e..2bc8f675 100644 --- a/lib/mindee/parsing/v2/field/simple_field.rb +++ b/lib/mindee/v2/parsing/field/simple_field.rb @@ -3,8 +3,8 @@ require_relative 'base_field' module Mindee - module Parsing - module V2 + module V2 + module Parsing module Field # A simple field with a scalar value. class SimpleField < BaseField diff --git a/lib/mindee/parsing/v2/inference_active_options.rb b/lib/mindee/v2/parsing/inference_active_options.rb similarity index 98% rename from lib/mindee/parsing/v2/inference_active_options.rb rename to lib/mindee/v2/parsing/inference_active_options.rb index 47d88473..32db887a 100644 --- a/lib/mindee/parsing/v2/inference_active_options.rb +++ b/lib/mindee/v2/parsing/inference_active_options.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true module Mindee - module Parsing - module V2 + module V2 + module Parsing # Data schema options activated during the inference. class DataSchemaActiveOption # @return [Boolean] diff --git a/lib/mindee/parsing/v2/inference_file.rb b/lib/mindee/v2/parsing/inference_file.rb similarity index 97% rename from lib/mindee/parsing/v2/inference_file.rb rename to lib/mindee/v2/parsing/inference_file.rb index 78dda706..6758c698 100644 --- a/lib/mindee/parsing/v2/inference_file.rb +++ b/lib/mindee/v2/parsing/inference_file.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true module Mindee - module Parsing - module V2 + module V2 + module Parsing # Information about a file returned in an inference. class InferenceFile # @return [String] File name. diff --git a/lib/mindee/parsing/v2/inference_job.rb b/lib/mindee/v2/parsing/inference_job.rb similarity index 94% rename from lib/mindee/parsing/v2/inference_job.rb rename to lib/mindee/v2/parsing/inference_job.rb index e6b6f4b6..c6e3c476 100644 --- a/lib/mindee/parsing/v2/inference_job.rb +++ b/lib/mindee/v2/parsing/inference_job.rb @@ -4,8 +4,8 @@ require_relative 'job' module Mindee - module Parsing - module V2 + module V2 + module Parsing # HTTP response wrapper that embeds a V2 job. class InferenceJob # @return [String] UUID of the Job. diff --git a/lib/mindee/parsing/v2/inference_model.rb b/lib/mindee/v2/parsing/inference_model.rb similarity index 95% rename from lib/mindee/parsing/v2/inference_model.rb rename to lib/mindee/v2/parsing/inference_model.rb index 85cb4eb8..fa6b19f9 100644 --- a/lib/mindee/parsing/v2/inference_model.rb +++ b/lib/mindee/v2/parsing/inference_model.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true module Mindee - module Parsing - module V2 + module V2 + module Parsing # ID of the model that produced the inference. class InferenceModel # @return [String] Identifier of the model. diff --git a/lib/mindee/parsing/v2/job.rb b/lib/mindee/v2/parsing/job.rb similarity index 99% rename from lib/mindee/parsing/v2/job.rb rename to lib/mindee/v2/parsing/job.rb index 3185397f..41b091c3 100644 --- a/lib/mindee/parsing/v2/job.rb +++ b/lib/mindee/v2/parsing/job.rb @@ -5,8 +5,8 @@ require_relative 'job_webhook' module Mindee - module Parsing - module V2 + module V2 + module Parsing # Metadata returned when polling a job (asynchronous request). class Job # @return [String] Unique job identifier. diff --git a/lib/mindee/parsing/v2/job_response.rb b/lib/mindee/v2/parsing/job_response.rb similarity index 95% rename from lib/mindee/parsing/v2/job_response.rb rename to lib/mindee/v2/parsing/job_response.rb index 70aab84a..5515a11b 100644 --- a/lib/mindee/parsing/v2/job_response.rb +++ b/lib/mindee/v2/parsing/job_response.rb @@ -4,8 +4,8 @@ require_relative 'job' module Mindee - module Parsing - module V2 + module V2 + module Parsing # HTTP response wrapper that embeds a V2 job. class JobResponse < CommonResponse # @return [Job] Parsed job payload. diff --git a/lib/mindee/parsing/v2/job_webhook.rb b/lib/mindee/v2/parsing/job_webhook.rb similarity index 95% rename from lib/mindee/parsing/v2/job_webhook.rb rename to lib/mindee/v2/parsing/job_webhook.rb index ac291a0b..15aae54a 100644 --- a/lib/mindee/parsing/v2/job_webhook.rb +++ b/lib/mindee/v2/parsing/job_webhook.rb @@ -1,12 +1,11 @@ -# lib/mindee/parsing/v2/job_response_webhook.rb # frozen_string_literal: true require 'date' require_relative 'error_response' module Mindee - module Parsing - module V2 + module V2 + module Parsing # Information about a webhook created for a job response. class JobWebhook # @return [String] Identifier of the webhook. diff --git a/lib/mindee/parsing/v2/rag_metadata.rb b/lib/mindee/v2/parsing/rag_metadata.rb similarity index 92% rename from lib/mindee/parsing/v2/rag_metadata.rb rename to lib/mindee/v2/parsing/rag_metadata.rb index 5bebc603..e9682413 100644 --- a/lib/mindee/parsing/v2/rag_metadata.rb +++ b/lib/mindee/v2/parsing/rag_metadata.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true module Mindee - module Parsing - module V2 + module V2 + module Parsing # Metadata about the RAG operation. class RAGMetadata # The UUID of the matched document used during the RAG operation. diff --git a/lib/mindee/parsing/v2/raw_text.rb b/lib/mindee/v2/parsing/raw_text.rb similarity index 85% rename from lib/mindee/parsing/v2/raw_text.rb rename to lib/mindee/v2/parsing/raw_text.rb index 9fa829f8..033d7f26 100644 --- a/lib/mindee/parsing/v2/raw_text.rb +++ b/lib/mindee/v2/parsing/raw_text.rb @@ -1,11 +1,11 @@ # frozen_string_literal: true module Mindee - module Parsing - module V2 + module V2 + module Parsing # Raw text extracted from all pages in the document. class RawText - # @return [Array[Mindee::Parsing::V2::RawTextPage]] List of pages with their extracted text content. + # @return [Array[Mindee::V2::Parsing::RawTextPage]] List of pages with their extracted text content. attr_reader :pages # @param server_response [Hash] Raw JSON parsed into a Hash. diff --git a/lib/mindee/parsing/v2/raw_text_page.rb b/lib/mindee/v2/parsing/raw_text_page.rb similarity index 94% rename from lib/mindee/parsing/v2/raw_text_page.rb rename to lib/mindee/v2/parsing/raw_text_page.rb index 3b952b62..bf34ee42 100644 --- a/lib/mindee/parsing/v2/raw_text_page.rb +++ b/lib/mindee/v2/parsing/raw_text_page.rb @@ -1,8 +1,8 @@ # frozen_string_literal: true module Mindee - module Parsing - module V2 + module V2 + module Parsing # Raw text extracted from a single page. class RawTextPage # @return [String] Text content of the page as a single string. '\n' is used to separate lines. diff --git a/lib/mindee/v2/product/base_product.rb b/lib/mindee/v2/product/base_product.rb index a11e0eb1..d6633a70 100644 --- a/lib/mindee/v2/product/base_product.rb +++ b/lib/mindee/v2/product/base_product.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true require_relative '../parsing/base_response' +require_relative '../../input/base_parameters' module Mindee module V2 diff --git a/lib/mindee/v2/product/classification/classification_inference.rb b/lib/mindee/v2/product/classification/classification_inference.rb index 837c19c2..da7042e5 100644 --- a/lib/mindee/v2/product/classification/classification_inference.rb +++ b/lib/mindee/v2/product/classification/classification_inference.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true require_relative 'classification_result' +require_relative '../../parsing/base_inference' module Mindee module V2 diff --git a/lib/mindee/v2/product/crop/crop_item.rb b/lib/mindee/v2/product/crop/crop_item.rb index 036b8c43..592fc999 100644 --- a/lib/mindee/v2/product/crop/crop_item.rb +++ b/lib/mindee/v2/product/crop/crop_item.rb @@ -8,13 +8,13 @@ module Crop class CropItem # @return [String] Type or classification of the detected object. attr_reader :object_type - # @return [Parsing::V2::Field::FieldLocation] Coordinates of the detected object on the document. + # @return [V2::Parsing::Field::FieldLocation] Coordinates of the detected object on the document. attr_reader :location # @param server_response [Hash] Hash representation of the JSON returned by the service. def initialize(server_response) @object_type = server_response['object_type'] - @location = Mindee::Parsing::V2::Field::FieldLocation.new(server_response['location']) + @location = Mindee::V2::Parsing::Field::FieldLocation.new(server_response['location']) end # String representation. diff --git a/lib/mindee/v2/product/extraction/extraction.rb b/lib/mindee/v2/product/extraction/extraction.rb index c01afee3..289a78da 100644 --- a/lib/mindee/v2/product/extraction/extraction.rb +++ b/lib/mindee/v2/product/extraction/extraction.rb @@ -9,7 +9,8 @@ module Product module Extraction # Extraction product. # Note: currently a placeholder for the `Inference` class. - class Extraction < Mindee::Parsing::V2::Inference + class Extraction < Product::BaseProduct + @slug = 'extraction' @params_type = Product::Extraction::Params::ExtractionParameters @response_type = Product::Extraction::ExtractionResponse end diff --git a/lib/mindee/v2/product/extraction/extraction_inference.rb b/lib/mindee/v2/product/extraction/extraction_inference.rb index 08f66d17..e8cc017b 100644 --- a/lib/mindee/v2/product/extraction/extraction_inference.rb +++ b/lib/mindee/v2/product/extraction/extraction_inference.rb @@ -1,22 +1,37 @@ # frozen_string_literal: true -require_relative '../../../parsing/v2/inference' +require_relative 'extraction_response' require_relative 'extraction_result' +require_relative 'params/extraction_parameters' module Mindee module V2 module Product module Extraction # Extraction inference. - class ExtractionInference < Mindee::Parsing::V2::Inference - # @return [ExtractionResult] Parsed inference payload. + class ExtractionInference < Mindee::V2::Parsing::BaseInference + # @return [InferenceActiveOptions] Options which were activated during the inference. + attr_reader :active_options + # @return [ExtractionResult] Result contents. attr_reader :result # @param server_response [Hash] Hash representation of the JSON returned by the service. def initialize(server_response) super - @result = Mindee::V2::Product::Extraction::ExtractionResult.new(server_response['result']) + @active_options = V2::Parsing::InferenceActiveOptions.new(server_response['active_options']) + @result = ExtractionResult.new(server_response['result']) + end + + # String representation. + # @return [String] + def to_s + [ + super, + @active_options.to_s, + @result.to_s, + '', + ].join("\n") end end end diff --git a/lib/mindee/v2/product/extraction/extraction_response.rb b/lib/mindee/v2/product/extraction/extraction_response.rb index 5b9f29b7..af85cad3 100644 --- a/lib/mindee/v2/product/extraction/extraction_response.rb +++ b/lib/mindee/v2/product/extraction/extraction_response.rb @@ -1,6 +1,5 @@ # frozen_string_literal: true -require_relative '../../../parsing/v2/inference_response' require_relative 'extraction_inference' module Mindee @@ -8,14 +7,24 @@ module V2 module Product module Extraction # HTTP response wrapper that embeds a V2 Inference. - class ExtractionResponse < Mindee::Parsing::V2::InferenceResponse + class ExtractionResponse < Mindee::V2::Parsing::BaseResponse # @return [ExtractionInference] Parsed inference payload. attr_reader :inference + @slug = 'extraction' + @_params_type = Params::ExtractionParameters + def initialize(server_response) super + @inference = Mindee::V2::Product::Extraction::ExtractionInference.new(server_response['inference']) end + + # String representation. + # @return [String] + def to_s + @inference.to_s + end end end end diff --git a/lib/mindee/v2/product/extraction/extraction_result.rb b/lib/mindee/v2/product/extraction/extraction_result.rb index ac080ea3..13205243 100644 --- a/lib/mindee/v2/product/extraction/extraction_result.rb +++ b/lib/mindee/v2/product/extraction/extraction_result.rb @@ -1,13 +1,42 @@ # frozen_string_literal: true -require_relative '../../../parsing/v2/inference_result' +require_relative '../../parsing' module Mindee module V2 module Product module Extraction # Result of an extraction utility inference. - class ExtractionResult < Mindee::Parsing::V2::InferenceResult + class ExtractionResult + # @return [Mindee::V2::Parsing::Field::InferenceFields] Fields produced by the model. + attr_reader :fields + # @return [Mindee::V2::Parsing::RawText, nil] Optional extra data. + attr_reader :raw_text + # @return [Mindee::V2::Parsing::RAGMetadata, nil] Optional RAG metadata. + attr_reader :rag + + # @param server_response [Hash] Hash version of the JSON returned by the API. + def initialize(server_response) + raise ArgumentError, 'server_response must be a Hash' unless server_response.is_a?(Hash) + + @fields = Parsing::Field::InferenceFields.new(server_response['fields']) + + @raw_text = server_response['raw_text'] ? Parsing::RawText.new(server_response['raw_text']) : nil + return unless server_response.key?('rag') && server_response['rag'] + + @rag = Parsing::RAGMetadata.new(server_response['rag']) + end + + # String representation. + # @return [String] + def to_s + parts = [ + 'Fields', + '======', + @fields.to_s, + ] + parts.join("\n") + end end end end diff --git a/lib/mindee/v2/product/extraction/params/extraction_parameters.rb b/lib/mindee/v2/product/extraction/params/extraction_parameters.rb index daabbc72..dc5218ae 100644 --- a/lib/mindee/v2/product/extraction/params/extraction_parameters.rb +++ b/lib/mindee/v2/product/extraction/params/extraction_parameters.rb @@ -1,6 +1,6 @@ # frozen_string_literal: true -require_relative '../../../../input/inference_parameters' +require_relative '../../../../input/base_parameters' module Mindee module V2 @@ -8,8 +8,114 @@ module Product module Extraction module Params # Parameters accepted by the extraction v2 endpoint. - # Currently a placeholder for the InferenceParameters class. - class ExtractionParameters < Input::InferenceParameters + class ExtractionParameters < Mindee::Input::BaseParameters + # @return [Boolean, nil] Enhance extraction accuracy with Retrieval-Augmented Generation. + attr_reader :rag + + # @return [Boolean, nil] Extract the full text content from the document as strings, + # and fill the raw_text` attribute. + attr_reader :raw_text + + # @return [Boolean, nil] Calculate bounding box polygons for all fields, + # and fill their `locations` attribute. + attr_reader :polygon + + # @return [Boolean, nil] Boost the precision and accuracy of all extractions. + # Calculate confidence scores for all fields, and fill their confidence attribute. + attr_reader :confidence + + # @return [String, nil] Additional text context used by the model during inference. + # Not recommended, for specific use only. + attr_reader :text_context + + # @return [DataSchemaField] + attr_reader :data_schema + + # @return [String] Slug for the endpoint. + def self.slug + 'extraction' + end + + # rubocop:disable Metrics/ParameterLists + # @param [String] model_id ID of the model + # @param [Boolean, nil] rag Whether to enable RAG. + # @param [Boolean, nil] raw_text Whether to enable rax text. + # @param [Boolean, nil] polygon Whether to enable polygons. + # @param [Boolean, nil] confidence Whether to enable confidence scores. + # @param [String, nil] file_alias File alias, if applicable. + # @param [Array, nil] webhook_ids + # @param [String, nil] text_context + # @param [Hash, nil] polling_options + # @param [Boolean, nil] close_file + # @param [DataSchemaField, String, Hash nil] data_schema + def initialize( + model_id, + rag: nil, + raw_text: nil, + polygon: nil, + confidence: nil, + file_alias: nil, + webhook_ids: nil, + text_context: nil, + polling_options: nil, + close_file: true, + data_schema: nil + ) + super( + model_id, + file_alias: file_alias, + webhook_ids: webhook_ids, + polling_options: polling_options, + close_file: close_file + ) + + @rag = rag + @raw_text = raw_text + @polygon = polygon + @confidence = confidence + @text_context = text_context + @data_schema = Input::DataSchema.new(data_schema) unless data_schema.nil? + # rubocop:enable Metrics/ParameterLists + end + + # Appends inference-specific form data to the provided array. + # @param [Array] form_data Array of form fields + # @return [Array] + def append_form_data(form_data) + new_form_data = super + + new_form_data.push(['rag', @rag.to_s]) unless @rag.nil? + new_form_data.push(['raw_text', @raw_text.to_s]) unless @raw_text.nil? + new_form_data.push(['polygon', @polygon.to_s]) unless @polygon.nil? + new_form_data.push(['confidence', @confidence.to_s]) unless @confidence.nil? + new_form_data.push(['text_context', @text_context]) if @text_context + new_form_data.push(['data_schema', @data_schema.to_s]) if @data_schema + + new_form_data + end + + # Loads a prediction from a Hash. + # @param [Hash] params Parameters to provide as a hash. + # @return [ExtractionParameters] + def self.from_hash(params: {}) + rag = params.fetch(:rag, nil) + raw_text = params.fetch(:raw_text, nil) + polygon = params.fetch(:polygon, nil) + confidence = params.fetch(:confidence, nil) + base_params = load_from_hash(params: params) + new_params = base_params.merge(rag: rag, raw_text: raw_text, polygon: polygon, confidence: confidence) + model_id = new_params.fetch(:model_id) + + ExtractionParameters.new( + model_id, rag: rag, + raw_text: raw_text, + polygon: polygon, + confidence: confidence, + file_alias: params.fetch(:file_alias, nil), + webhook_ids: params.fetch(:webhook_ids, nil), + close_file: params.fetch(:close_file, true) + ) + end end end end diff --git a/lib/mindee/version.rb b/lib/mindee/version.rb index 54847964..ab6545c5 100644 --- a/lib/mindee/version.rb +++ b/lib/mindee/version.rb @@ -3,7 +3,7 @@ # Mindee module Mindee # Current version. - VERSION = '4.13.0' + VERSION = '5.0.0-alpha.1' # Finds and return the current platform. # @return [Symbol, Hash[String | Symbol, Regexp], Nil?] diff --git a/sig/mindee/client_v2.rbs b/sig/mindee/client_v2.rbs index 66b5409c..ab69e9e6 100644 --- a/sig/mindee/client_v2.rbs +++ b/sig/mindee/client_v2.rbs @@ -7,14 +7,10 @@ module Mindee def logger: () -> Logger def initialize: (?api_key: String) -> void - def get_inference: (String inference_id) -> Parsing::V2::InferenceResponse def get_result: [T] (HTTP::_ProductClass[T] product, String resource) -> T - def get_result_url: [T] (HTTP::_ResponseFactory[T] response_class, String inference_id) -> T - def get_job: (String job_id) -> Parsing::V2::JobResponse - def enqueue_inference: (Input::Source::LocalInputSource | Input::Source::URLInputSource, Hash[String | Symbol, untyped] | Input::InferenceParameters params, ?disable_redundant_warnings: bool) -> Parsing::V2::JobResponse - def enqueue: [T] (HTTP::_ProductClass[T] product, Input::Source::LocalInputSource | Input::Source::URLInputSource, Hash[String | Symbol, untyped] | Input::BaseParameters params) -> Parsing::V2::JobResponse + def get_job: (String job_id) -> V2::Parsing::JobResponse + def enqueue: [T] (HTTP::_ProductClass[T] product, Input::Source::LocalInputSource | Input::Source::URLInputSource, Hash[String | Symbol, untyped] | Input::BaseParameters params) -> V2::Parsing::JobResponse def enqueue_and_get_result: [T] (HTTP::_ProductClass[T] product, Input::Source::LocalInputSource | Input::Source::URLInputSource, Hash[String | Symbol, untyped] | Input::BaseParameters params) -> T - def enqueue_and_get_inference: (Input::Source::LocalInputSource | Input::Source::URLInputSource, Hash[String | Symbol, untyped] | Input::InferenceParameters params, ?disable_redundant_warnings: bool) -> Parsing::V2::InferenceResponse def validate_async_params: (Integer | Float, Integer | Float, Integer) -> void def normalize_parameters: (singleton(Input::BaseParameters) param_class, Hash[String | Symbol, untyped] | Input::BaseParameters params) -> Input::BaseParameters end diff --git a/sig/mindee/errors/mindee_http_error_v2.rbs b/sig/mindee/errors/mindee_http_error_v2.rbs index 02e403a1..0c4381e1 100644 --- a/sig/mindee/errors/mindee_http_error_v2.rbs +++ b/sig/mindee/errors/mindee_http_error_v2.rbs @@ -7,9 +7,9 @@ module Mindee attr_reader status: Integer attr_reader code: String attr_reader title: String - attr_reader errors: Array[Parsing::V2::ErrorItem] + attr_reader errors: Array[V2::Parsing::ErrorItem] - def initialize: (Hash[String, untyped] | Mindee::Parsing::V2::ErrorResponse) -> void + def initialize: (Hash[String, untyped] | Mindee::V2::Parsing::ErrorResponse) -> void end end end diff --git a/sig/mindee/http/mindee_api_v2.rbs b/sig/mindee/http/mindee_api_v2.rbs index c67b09b3..66b3c91b 100644 --- a/sig/mindee/http/mindee_api_v2.rbs +++ b/sig/mindee/http/mindee_api_v2.rbs @@ -18,21 +18,17 @@ module Mindee def req_get_result: [T] (_ProductClass[T] product, String resource) -> T - def req_post_enqueue: (Input::Source::LocalInputSource | Input::Source::URLInputSource, Input::BaseParameters) -> Parsing::V2::JobResponse - def req_get_inference: (String) -> Parsing::V2::InferenceResponse - def req_get_job: (String) -> Parsing::V2::JobResponse + def req_post_enqueue: (Input::Source::LocalInputSource | Input::Source::URLInputSource, Input::BaseParameters) -> V2::Parsing::JobResponse + def req_get_job: (String) -> V2::Parsing::JobResponse def process_response: (Net::HTTPResponse?) -> Hash[String | Symbol, untyped] def poll: (String) -> Net::HTTPResponse - def inference_job_req_get: (String) -> Net::HTTPResponse - def inference_result_req_get: (String) -> Net::HTTPResponse def result_req_get: [T] (String, _ProductClass[T] product) -> Net::HTTPResponse def enqueue: (Input::Source::LocalInputSource | Input::Source::URLInputSource, Input::BaseParameters) -> Net::HTTPResponse? private - def req_get_job_url: (String) -> Parsing::V2::JobResponse + def req_get_job_url: (String) -> V2::Parsing::JobResponse def req_get_result_url: [T] (_ResponseFactory[T] result_class, String url) -> T def uri?: (String) -> bool - def enqueue_form_options: (Array[untyped], Input::InferenceParameters) -> Array[untyped] end end end diff --git a/sig/mindee/input/inference_parameters.rbs b/sig/mindee/input/inference_parameters.rbs deleted file mode 100644 index b88d8ef2..00000000 --- a/sig/mindee/input/inference_parameters.rbs +++ /dev/null @@ -1,32 +0,0 @@ -# lib/mindee/input/inference_parameters.rb -module Mindee - module Input - class InferenceParameters < BaseParameters - def self.slug: -> String - - attr_reader confidence: bool? - attr_reader polygon: bool? - attr_reader rag: bool? - attr_reader raw_text: bool? - attr_reader text_context: String? - attr_reader data_schema: DataSchema? - - def initialize: ( - String, - ?rag: bool?, - ?raw_text: bool?, - ?polygon: bool?, - ?confidence: bool?, - ?file_alias: String?, - ?text_context: String?, - ?webhook_ids: Array[String]?, - ?polling_options: Hash[Symbol | String, untyped] | PollingOptions?, - ?close_file: bool?, - ?data_schema: DataSchema|String|Hash[Symbol | String, untyped]? - ) -> void - - def self.from_hash: (params: Hash[String | Symbol, untyped]) -> InferenceParameters - def append_form_data: (Array[Array[untyped]]) -> Array[Array[untyped]] - end - end -end diff --git a/sig/mindee/input/local_response.rbs b/sig/mindee/input/local_response.rbs index 4f0468fb..6b384f01 100644 --- a/sig/mindee/input/local_response.rbs +++ b/sig/mindee/input/local_response.rbs @@ -8,7 +8,7 @@ module Mindee def self.process_secret_key: (String) -> String def get_hmac_signature: (String) -> String def valid_hmac_signature?: (String, String) -> bool - def deserialize_response: (singleton(Parsing::V2::CommonResponse))-> (Parsing::V2::JobResponse | Mindee::Parsing::V2::InferenceResponse) + def deserialize_response: (singleton(V2::Parsing::CommonResponse))-> (V2::Parsing::CommonResponse) end end end diff --git a/sig/mindee/parsing/v2/inference.rbs b/sig/mindee/parsing/v2/inference.rbs deleted file mode 100644 index b6584c95..00000000 --- a/sig/mindee/parsing/v2/inference.rbs +++ /dev/null @@ -1,18 +0,0 @@ -# lib/mindee/parsing/v2/inference.rb -module Mindee - module Parsing - module V2 - class Inference < Mindee::V2::Parsing::BaseInference - attr_reader self.params_type: singleton(Input::InferenceParameters) - attr_reader self.response_type: singleton(InferenceResponse) - attr_reader self.slug: String - - attr_reader active_options: InferenceActiveOptions - attr_reader result: InferenceResult - - def initialize: (Hash[String | Symbol, untyped]) -> void - def to_s: -> String - end - end - end -end diff --git a/sig/mindee/parsing/v2/inference_response.rbs b/sig/mindee/parsing/v2/inference_response.rbs deleted file mode 100644 index 05138748..00000000 --- a/sig/mindee/parsing/v2/inference_response.rbs +++ /dev/null @@ -1,21 +0,0 @@ -# lib/mindee/parsing/v2/inference_response.rb -module Mindee - module Parsing - module V2 - class InferenceResponse < Mindee::V2::Parsing::BaseResponse[Mindee::Parsing::V2::Inference] - - self.@slug: String - self.@_params_type: singleton(Input::BaseParameters) - - attr_reader inference: Mindee::Parsing::V2::Inference - def initialize: (Hash[String | Symbol, untyped]) -> void - - def _params_type: -> singleton(Input::InferenceParameters) - - def to_s: -> String - def self._params_type: () -> singleton(Input::InferenceParameters) - def self.slug: () -> String - end - end - end -end diff --git a/sig/mindee/parsing/v2/inference_result.rbs b/sig/mindee/parsing/v2/inference_result.rbs deleted file mode 100644 index a8342780..00000000 --- a/sig/mindee/parsing/v2/inference_result.rbs +++ /dev/null @@ -1,15 +0,0 @@ -# lib/mindee/parsing/v2/inference_result.rb -module Mindee - module Parsing - module V2 - class InferenceResult - attr_reader fields: Field::InferenceFields - attr_reader raw_text: RawText? - attr_reader rag: RAGMetadata? - - def initialize: (Hash[String | Symbol, untyped]) -> void - def to_s: -> String - end - end - end -end diff --git a/sig/mindee/v2/parsing/base_inference.rbs b/sig/mindee/v2/parsing/base_inference.rbs index 4f6b0396..b9ddd9e2 100644 --- a/sig/mindee/v2/parsing/base_inference.rbs +++ b/sig/mindee/v2/parsing/base_inference.rbs @@ -4,10 +4,10 @@ module Mindee module V2 module Parsing class BaseInference - attr_reader job: Mindee::Parsing::V2::InferenceJob - attr_reader file: Mindee::Parsing::V2::InferenceFile + attr_reader job: Mindee::V2::Parsing::InferenceJob + attr_reader file: Mindee::V2::Parsing::InferenceFile attr_reader id: String - attr_reader model: Mindee::Parsing::V2::InferenceModel + attr_reader model: Mindee::V2::Parsing::InferenceModel def initialize: (Hash[String | Symbol, untyped]) -> void diff --git a/sig/mindee/v2/parsing/base_response.rbs b/sig/mindee/v2/parsing/base_response.rbs index 8d1c7814..803afaf2 100644 --- a/sig/mindee/v2/parsing/base_response.rbs +++ b/sig/mindee/v2/parsing/base_response.rbs @@ -3,7 +3,7 @@ module Mindee module V2 module Parsing - class BaseResponse[T] < Mindee::Parsing::V2::CommonResponse + class BaseResponse[T] < Mindee::V2::Parsing::CommonResponse attr_reader inference: T end end diff --git a/sig/mindee/parsing/v2/common_response.rbs b/sig/mindee/v2/parsing/common_response.rbs similarity index 72% rename from sig/mindee/parsing/v2/common_response.rbs rename to sig/mindee/v2/parsing/common_response.rbs index 8c94189a..890ab345 100644 --- a/sig/mindee/parsing/v2/common_response.rbs +++ b/sig/mindee/v2/parsing/common_response.rbs @@ -1,7 +1,7 @@ -# lib/mindee/parsing/v2/common_response.rb +# lib/mindee/v2/parsing/common_response.rb module Mindee - module Parsing - module V2 + module V2 + module Parsing class CommonResponse attr_reader raw_http: Hash[String | Symbol, untyped] def initialize: (Hash[String | Symbol, untyped]) -> void diff --git a/sig/mindee/parsing/v2/error_item.rbs b/sig/mindee/v2/parsing/error_item.rbs similarity index 74% rename from sig/mindee/parsing/v2/error_item.rbs rename to sig/mindee/v2/parsing/error_item.rbs index 04b4e675..05d2d7d2 100644 --- a/sig/mindee/parsing/v2/error_item.rbs +++ b/sig/mindee/v2/parsing/error_item.rbs @@ -1,7 +1,7 @@ -# lib/mindee/parsing/v2/error_item.rb +# lib/mindee/v2/parsing/error_item.rb module Mindee - module Parsing - module V2 + module V2 + module Parsing class ErrorItem attr_reader pointer: String attr_reader detail: String|nil diff --git a/sig/mindee/parsing/v2/error_response.rbs b/sig/mindee/v2/parsing/error_response.rbs similarity index 84% rename from sig/mindee/parsing/v2/error_response.rbs rename to sig/mindee/v2/parsing/error_response.rbs index 7c0fdf55..334ca8b3 100644 --- a/sig/mindee/parsing/v2/error_response.rbs +++ b/sig/mindee/v2/parsing/error_response.rbs @@ -1,7 +1,7 @@ -# lib/mindee/parsing/v2/error_response.rb +# lib/mindee/v2/parsing/error_response.rb module Mindee - module Parsing - module V2 + module V2 + module Parsing class ErrorResponse attr_reader detail: String attr_reader status: Integer diff --git a/sig/mindee/parsing/v2/field/base_field.rbs b/sig/mindee/v2/parsing/field/base_field.rbs similarity index 85% rename from sig/mindee/parsing/v2/field/base_field.rbs rename to sig/mindee/v2/parsing/field/base_field.rbs index 5c401ab1..b0500207 100644 --- a/sig/mindee/parsing/v2/field/base_field.rbs +++ b/sig/mindee/v2/parsing/field/base_field.rbs @@ -1,7 +1,7 @@ -# lib/mindee/parsing/v2/field/base_field.rb +# lib/mindee/v2/parsing/field/base_field.rb module Mindee - module Parsing - module V2 + module V2 + module Parsing module Field class BaseField attr_reader indent_level: Integer diff --git a/sig/mindee/parsing/v2/field/field_confidence.rbs b/sig/mindee/v2/parsing/field/field_confidence.rbs similarity index 91% rename from sig/mindee/parsing/v2/field/field_confidence.rbs rename to sig/mindee/v2/parsing/field/field_confidence.rbs index 77ca6b68..e1c72817 100644 --- a/sig/mindee/parsing/v2/field/field_confidence.rbs +++ b/sig/mindee/v2/parsing/field/field_confidence.rbs @@ -1,7 +1,7 @@ -# lib/mindee/parsing/v2/field/field_confidence.rb +# lib/mindee/v2/parsing/field/field_confidence.rb module Mindee - module Parsing - module V2 + module V2 + module Parsing module Field class FieldConfidence attr_reader value: String diff --git a/sig/mindee/parsing/v2/field/field_location.rbs b/sig/mindee/v2/parsing/field/field_location.rbs similarity index 78% rename from sig/mindee/parsing/v2/field/field_location.rbs rename to sig/mindee/v2/parsing/field/field_location.rbs index 0c400ee0..d8cb365c 100644 --- a/sig/mindee/parsing/v2/field/field_location.rbs +++ b/sig/mindee/v2/parsing/field/field_location.rbs @@ -1,7 +1,7 @@ -# lib/mindee/parsing/v2/field/field_location.rb +# lib/mindee/v2/parsing/field/field_location.rb module Mindee - module Parsing - module V2 + module V2 + module Parsing module Field class FieldLocation attr_reader page: Integer diff --git a/sig/mindee/parsing/v2/field/inference_fields.rbs b/sig/mindee/v2/parsing/field/inference_fields.rbs similarity index 87% rename from sig/mindee/parsing/v2/field/inference_fields.rbs rename to sig/mindee/v2/parsing/field/inference_fields.rbs index 203f06aa..4c29c612 100644 --- a/sig/mindee/parsing/v2/field/inference_fields.rbs +++ b/sig/mindee/v2/parsing/field/inference_fields.rbs @@ -1,7 +1,7 @@ -# lib/mindee/parsing/v2/field/inference_fields.rb +# lib/mindee/v2/parsing/field/inference_fields.rb module Mindee - module Parsing - module V2 + module V2 + module Parsing module Field class InferenceFields < Hash[String, ListField | ObjectField | SimpleField?] attr_reader indent_level: Integer diff --git a/sig/mindee/parsing/v2/field/list_field.rbs b/sig/mindee/v2/parsing/field/list_field.rbs similarity index 89% rename from sig/mindee/parsing/v2/field/list_field.rbs rename to sig/mindee/v2/parsing/field/list_field.rbs index 1f0295da..ff17adc8 100644 --- a/sig/mindee/parsing/v2/field/list_field.rbs +++ b/sig/mindee/v2/parsing/field/list_field.rbs @@ -1,7 +1,7 @@ -# lib/mindee/parsing/v2/field/list_field.rb +# lib/mindee/v2/parsing/field/list_field.rb module Mindee - module Parsing - module V2 + module V2 + module Parsing module Field class ListField < BaseField include Enumerable[BaseField] diff --git a/sig/mindee/parsing/v2/field/object_field.rbs b/sig/mindee/v2/parsing/field/object_field.rbs similarity index 91% rename from sig/mindee/parsing/v2/field/object_field.rbs rename to sig/mindee/v2/parsing/field/object_field.rbs index 149dd23c..1aa3557a 100644 --- a/sig/mindee/parsing/v2/field/object_field.rbs +++ b/sig/mindee/v2/parsing/field/object_field.rbs @@ -1,7 +1,7 @@ -# lib/mindee/parsing/v2/field/object_field.rb +# lib/mindee/v2/parsing/field/object_field.rb module Mindee - module Parsing - module V2 + module V2 + module Parsing module Field # A field containing a nested set of inference fields. class ObjectField < BaseField diff --git a/sig/mindee/parsing/v2/field/simple_field.rbs b/sig/mindee/v2/parsing/field/simple_field.rbs similarity index 81% rename from sig/mindee/parsing/v2/field/simple_field.rbs rename to sig/mindee/v2/parsing/field/simple_field.rbs index facf0b12..b0a35b29 100644 --- a/sig/mindee/parsing/v2/field/simple_field.rbs +++ b/sig/mindee/v2/parsing/field/simple_field.rbs @@ -1,7 +1,7 @@ -# lib/mindee/parsing/v2/field/simple_field.rb +# lib/mindee/v2/parsing/field/simple_field.rb module Mindee - module Parsing - module V2 + module V2 + module Parsing module Field class SimpleField < BaseField attr_reader value: String | Integer | Float | bool | nil diff --git a/sig/mindee/parsing/v2/inference_active_options.rbs b/sig/mindee/v2/parsing/inference_active_options.rbs similarity index 94% rename from sig/mindee/parsing/v2/inference_active_options.rbs rename to sig/mindee/v2/parsing/inference_active_options.rbs index f0cc0296..f0d69034 100644 --- a/sig/mindee/parsing/v2/inference_active_options.rbs +++ b/sig/mindee/v2/parsing/inference_active_options.rbs @@ -1,6 +1,6 @@ module Mindee - module Parsing - module V2 + module V2 + module Parsing class DataSchemaActiveOption attr_reader replace: bool diff --git a/sig/mindee/parsing/v2/inference_file.rbs b/sig/mindee/v2/parsing/inference_file.rbs similarity index 81% rename from sig/mindee/parsing/v2/inference_file.rbs rename to sig/mindee/v2/parsing/inference_file.rbs index 43e31311..ce8c56f3 100644 --- a/sig/mindee/parsing/v2/inference_file.rbs +++ b/sig/mindee/v2/parsing/inference_file.rbs @@ -1,7 +1,7 @@ -# lib/mindee/parsing/v2/inference_file.rb +# lib/mindee/v2/parsing/inference_file.rb module Mindee - module Parsing - module V2 + module V2 + module Parsing class InferenceFile attr_reader name: String attr_reader file_alias: String? diff --git a/sig/mindee/parsing/v2/inference_job.rbs b/sig/mindee/v2/parsing/inference_job.rbs similarity index 86% rename from sig/mindee/parsing/v2/inference_job.rbs rename to sig/mindee/v2/parsing/inference_job.rbs index 02957681..d763e4af 100644 --- a/sig/mindee/parsing/v2/inference_job.rbs +++ b/sig/mindee/v2/parsing/inference_job.rbs @@ -1,6 +1,6 @@ module Mindee - module Parsing - module V2 + module V2 + module Parsing class InferenceJob attr_reader id: String diff --git a/sig/mindee/parsing/v2/inference_model.rbs b/sig/mindee/v2/parsing/inference_model.rbs similarity index 69% rename from sig/mindee/parsing/v2/inference_model.rbs rename to sig/mindee/v2/parsing/inference_model.rbs index 07a9be23..6b094696 100644 --- a/sig/mindee/parsing/v2/inference_model.rbs +++ b/sig/mindee/v2/parsing/inference_model.rbs @@ -1,7 +1,7 @@ -# lib/mindee/parsing/v2/inference_model.rb +# lib/mindee/v2/parsing/inference_model.rb module Mindee - module Parsing - module V2 + module V2 + module Parsing class InferenceModel attr_reader id: String def initialize: (Hash[String | Symbol, untyped]) -> void diff --git a/sig/mindee/parsing/v2/job.rbs b/sig/mindee/v2/parsing/job.rbs similarity index 90% rename from sig/mindee/parsing/v2/job.rbs rename to sig/mindee/v2/parsing/job.rbs index 1b60d013..3b7e2bcc 100644 --- a/sig/mindee/parsing/v2/job.rbs +++ b/sig/mindee/v2/parsing/job.rbs @@ -1,7 +1,7 @@ -# lib/mindee/parsing/v2/job.rb +# lib/mindee/v2/parsing/job.rb module Mindee - module Parsing - module V2 + module V2 + module Parsing class Job attr_reader alias: String attr_reader created_at: Time diff --git a/sig/mindee/parsing/v2/job_response.rbs b/sig/mindee/v2/parsing/job_response.rbs similarity index 74% rename from sig/mindee/parsing/v2/job_response.rbs rename to sig/mindee/v2/parsing/job_response.rbs index 1ecf8683..1277fdca 100644 --- a/sig/mindee/parsing/v2/job_response.rbs +++ b/sig/mindee/v2/parsing/job_response.rbs @@ -1,7 +1,7 @@ -# lib/mindee/parsing/v2/job_response.rb +# lib/mindee/v2/parsing/job_response.rb module Mindee - module Parsing - module V2 + module V2 + module Parsing class JobResponse < CommonResponse attr_reader job: Job def initialize: (Hash[String | Symbol, untyped]) -> void diff --git a/sig/mindee/parsing/v2/job_webhook.rbs b/sig/mindee/v2/parsing/job_webhook.rbs similarity index 83% rename from sig/mindee/parsing/v2/job_webhook.rbs rename to sig/mindee/v2/parsing/job_webhook.rbs index 5d9ea920..5d3e3017 100644 --- a/sig/mindee/parsing/v2/job_webhook.rbs +++ b/sig/mindee/v2/parsing/job_webhook.rbs @@ -1,7 +1,7 @@ -# lib/mindee/parsing/v2/job_webhook.rb +# lib/mindee/v2/parsing/job_webhook.rb module Mindee - module Parsing - module V2 + module V2 + module Parsing class JobWebhook attr_reader created_at: DateTime? attr_reader error: ErrorResponse? diff --git a/sig/mindee/parsing/v2/rag_metadata.rbs b/sig/mindee/v2/parsing/rag_metadata.rbs similarity index 72% rename from sig/mindee/parsing/v2/rag_metadata.rbs rename to sig/mindee/v2/parsing/rag_metadata.rbs index 2995de66..bbb6c70c 100644 --- a/sig/mindee/parsing/v2/rag_metadata.rbs +++ b/sig/mindee/v2/parsing/rag_metadata.rbs @@ -1,8 +1,8 @@ -# lib/mindee/parsing/v2/rag_metadata.rb +# lib/mindee/v2/parsing/rag_metadata.rb module Mindee - module Parsing - module V2 + module V2 + module Parsing class RAGMetadata attr_accessor retrieved_document_id: string | nil diff --git a/sig/mindee/parsing/v2/raw_text.rbs b/sig/mindee/v2/parsing/raw_text.rbs similarity index 72% rename from sig/mindee/parsing/v2/raw_text.rbs rename to sig/mindee/v2/parsing/raw_text.rbs index b5959005..a8e0a9f7 100644 --- a/sig/mindee/parsing/v2/raw_text.rbs +++ b/sig/mindee/v2/parsing/raw_text.rbs @@ -1,7 +1,7 @@ -# lib/mindee/parsing/v2/raw_text.rb +# lib/mindee/v2/parsing/raw_text.rb module Mindee - module Parsing - module V2 + module V2 + module Parsing class RawText attr_reader pages: Array[RawTextPage] diff --git a/sig/mindee/parsing/v2/raw_text_page.rbs b/sig/mindee/v2/parsing/raw_text_page.rbs similarity index 84% rename from sig/mindee/parsing/v2/raw_text_page.rbs rename to sig/mindee/v2/parsing/raw_text_page.rbs index 536d2c48..ce87f51c 100644 --- a/sig/mindee/parsing/v2/raw_text_page.rbs +++ b/sig/mindee/v2/parsing/raw_text_page.rbs @@ -1,6 +1,6 @@ module Mindee - module Parsing - module V2 + module V2 + module Parsing class RawTextPage attr_reader content: String diff --git a/sig/mindee/v2/product/classification/classification_response.rbs b/sig/mindee/v2/product/classification/classification_response.rbs index ee34fbc1..6e43050c 100644 --- a/sig/mindee/v2/product/classification/classification_response.rbs +++ b/sig/mindee/v2/product/classification/classification_response.rbs @@ -4,7 +4,7 @@ module Mindee module V2 module Product module Classification - class ClassificationResponse + class ClassificationResponse < Parsing::BaseResponse[ClassificationInference] self.@slug: String self.@_params_type: singleton(Params::ClassificationParameters) diff --git a/sig/mindee/v2/product/crop/crop_item.rbs b/sig/mindee/v2/product/crop/crop_item.rbs index 1e3e7998..f9594bd5 100644 --- a/sig/mindee/v2/product/crop/crop_item.rbs +++ b/sig/mindee/v2/product/crop/crop_item.rbs @@ -4,7 +4,7 @@ module Mindee module Crop class CropItem attr_reader object_type: String - attr_reader location: Mindee::Parsing::V2::Field::FieldLocation + attr_reader location: Mindee::V2::Parsing::Field::FieldLocation def initialize: (Hash[String | Symbol, untyped]) -> void def to_s: -> String diff --git a/sig/mindee/v2/product/crop/crop_response.rbs b/sig/mindee/v2/product/crop/crop_response.rbs index 4b0c638f..773045a9 100644 --- a/sig/mindee/v2/product/crop/crop_response.rbs +++ b/sig/mindee/v2/product/crop/crop_response.rbs @@ -4,7 +4,7 @@ module Mindee module V2 module Product module Crop - class CropResponse + class CropResponse < Parsing::BaseResponse[CropInference] self.@slug: String self.@_params_type: singleton(Params::CropParameters) diff --git a/sig/mindee/v2/product/extraction/extraction.rbs b/sig/mindee/v2/product/extraction/extraction.rbs index c747c7b8..197a5f7e 100644 --- a/sig/mindee/v2/product/extraction/extraction.rbs +++ b/sig/mindee/v2/product/extraction/extraction.rbs @@ -1,3 +1,5 @@ +# lib/mindee/v2/product/extraction/extraction.rb + module Mindee module V2 module Product @@ -5,6 +7,7 @@ module Mindee class Extraction self.@params_type: singleton(Mindee::V2::Product::Extraction::Params::ExtractionParameters) self.@response_type: singleton(Mindee::V2::Product::Extraction::ExtractionResponse) + self.@slug: String end end end diff --git a/sig/mindee/v2/product/extraction/extraction_inference.rbs b/sig/mindee/v2/product/extraction/extraction_inference.rbs index ffefa44b..2facf4f7 100644 --- a/sig/mindee/v2/product/extraction/extraction_inference.rbs +++ b/sig/mindee/v2/product/extraction/extraction_inference.rbs @@ -3,6 +3,11 @@ module Mindee module Product module Extraction class ExtractionInference + attr_reader self.params_type: singleton(Params::ExtractionParameters) + attr_reader self.response_type: singleton(ExtractionResponse) + attr_reader self.slug: String + + attr_reader active_options: Mindee::V2::Parsing::InferenceActiveOptions attr_reader result: ExtractionResult def initialize: (Hash[String | Symbol, untyped]) -> void diff --git a/sig/mindee/v2/product/extraction/extraction_response.rbs b/sig/mindee/v2/product/extraction/extraction_response.rbs index 000d7f82..0b5cec06 100644 --- a/sig/mindee/v2/product/extraction/extraction_response.rbs +++ b/sig/mindee/v2/product/extraction/extraction_response.rbs @@ -1,16 +1,22 @@ +# lib/mindee/v2/product/extraction/extraction_response.rb + module Mindee module V2 module Product module Extraction - class ExtractionResponse + class ExtractionResponse < Parsing::BaseResponse[ExtractionInference] self.@_params_type: singleton(Params::ExtractionParameters) - attr_reader inference: Mindee::V2::Product::Extraction::ExtractionInference + self.@slug: String + + attr_reader inference: ExtractionInference def initialize: (Hash[String | Symbol, untyped]) -> void def _params_type: -> singleton(Params::ExtractionParameters) def self._params_type: () -> singleton(Params::ExtractionParameters) + + def to_s: -> String end end end diff --git a/sig/mindee/v2/product/extraction/extraction_result.rbs b/sig/mindee/v2/product/extraction/extraction_result.rbs index 975d364c..c8e0ea00 100644 --- a/sig/mindee/v2/product/extraction/extraction_result.rbs +++ b/sig/mindee/v2/product/extraction/extraction_result.rbs @@ -1,8 +1,16 @@ +# lib/mindee/v2/product/extraction/extraction_result.rb + module Mindee module V2 module Product module Extraction - class ExtractionResult < Mindee::Parsing::V2::InferenceResult + class ExtractionResult + attr_reader fields: Parsing::Field::InferenceFields + attr_reader raw_text: Parsing::RawText? + attr_reader rag: Parsing::RAGMetadata? + + def initialize: (Hash[String | Symbol, untyped]) -> void + def to_s: -> String end end end diff --git a/sig/mindee/v2/product/extraction/params/extraction_parameters.rbs b/sig/mindee/v2/product/extraction/params/extraction_parameters.rbs index f93bcdae..8cb96595 100644 --- a/sig/mindee/v2/product/extraction/params/extraction_parameters.rbs +++ b/sig/mindee/v2/product/extraction/params/extraction_parameters.rbs @@ -3,7 +3,33 @@ module Mindee module Product module Extraction module Params - class ExtractionParameters < Input::InferenceParameters + class ExtractionParameters < Input::BaseParameters + + def self.slug: -> String + + attr_reader confidence: bool? + attr_reader polygon: bool? + attr_reader rag: bool? + attr_reader raw_text: bool? + attr_reader text_context: String? + attr_reader data_schema: Input::DataSchema? + + def initialize: ( + String, + ?rag: bool?, + ?raw_text: bool?, + ?polygon: bool?, + ?confidence: bool?, + ?file_alias: String?, + ?text_context: String?, + ?webhook_ids: Array[String]?, + ?polling_options: Hash[Symbol | String, untyped] | Input::PollingOptions?, + ?close_file: bool?, + ?data_schema: Input::DataSchema|String|Hash[Symbol | String, untyped]? + ) -> void + + def self.from_hash: (params: Hash[String | Symbol, untyped]) -> ExtractionParameters + def append_form_data: (Array[Array[untyped]]) -> Array[Array[untyped]] end end end diff --git a/sig/mindee/v2/product/ocr/ocr_response.rbs b/sig/mindee/v2/product/ocr/ocr_response.rbs index 609aef0e..f9d96875 100644 --- a/sig/mindee/v2/product/ocr/ocr_response.rbs +++ b/sig/mindee/v2/product/ocr/ocr_response.rbs @@ -4,7 +4,7 @@ module Mindee module V2 module Product module Ocr - class OcrResponse + class OcrResponse < Parsing::BaseResponse[OcrInference] self.@slug: String self.@_params_type: singleton(Params::OcrParameters) diff --git a/sig/mindee/v2/product/split/split_response.rbs b/sig/mindee/v2/product/split/split_response.rbs index 9068eeb5..9a023251 100644 --- a/sig/mindee/v2/product/split/split_response.rbs +++ b/sig/mindee/v2/product/split/split_response.rbs @@ -4,7 +4,7 @@ module Mindee module V2 module Product module Split - class SplitResponse + class SplitResponse < Parsing::BaseResponse[SplitInference] self.@slug: String self.@_params_type: singleton(Params::SplitParameters) diff --git a/spec/v2/client_v2_integration.rb b/spec/v2/client_v2_integration.rb index 598a72b9..6affbdd7 100644 --- a/spec/v2/client_v2_integration.rb +++ b/spec/v2/client_v2_integration.rb @@ -1,6 +1,10 @@ # frozen_string_literal: true require 'mindee' +require 'mindee/v2/product' + +using Mindee::V2::Product::Extraction::Params +using Mindee::V2::Product::Extraction describe 'Mindee::ClientV2 – integration tests (V2)', :integration, order: :defined do let(:api_key) { ENV.fetch('MINDEE_V2_API_KEY') } @@ -19,7 +23,7 @@ max_retries: 80 ) - inference_params = Mindee::Input::InferenceParameters.new( + inference_params = Mindee::V2::Product::Extraction::Params::ExtractionParameters.new( model_id, rag: false, raw_text: true, @@ -30,25 +34,25 @@ text_context: 'this is a test' ) - response = client.enqueue_and_get_inference(input, inference_params) + response = client.enqueue_and_get_result(Mindee::V2::Product::Extraction::Extraction, input, inference_params) expect(response).not_to be_nil expect(response.inference).not_to be_nil file = response.inference.file expect(file).not_to be_nil - expect(file).to be_a(Mindee::Parsing::V2::InferenceFile) + expect(file).to be_a(Mindee::V2::Parsing::InferenceFile) expect(file.name).to eq('multipage_cut-2.pdf') expect(file.page_count).to eq(2) model = response.inference.model expect(model).not_to be_nil - expect(model).to be_a(Mindee::Parsing::V2::InferenceModel) + expect(model).to be_a(Mindee::V2::Parsing::InferenceModel) expect(model.id).to eq(model_id) active_options = response.inference.active_options expect(active_options).not_to be_nil - expect(active_options).to be_a(Mindee::Parsing::V2::InferenceActiveOptions) + expect(active_options).to be_a(Mindee::V2::Parsing::InferenceActiveOptions) expect(active_options.raw_text).to eq(true) expect(active_options.polygon).to eq(false) expect(active_options.confidence).to eq(false) @@ -68,7 +72,7 @@ src_path = File.join(V1_PRODUCT_DATA_DIR, 'financial_document', 'default_sample.jpg') input = Mindee::Input::Source::FileInputSource.new(File.open(src_path, 'rb'), 'default_sample.jpg') - inference_params = Mindee::Input::InferenceParameters.new( + inference_params = Mindee::V2::Product::Extraction::Params::ExtractionParameters.new( model_id, raw_text: false, polygon: false, @@ -77,23 +81,23 @@ file_alias: 'rb_integration_test' ) - response = client.enqueue_and_get_inference(input, inference_params) + response = client.enqueue_and_get_result(Mindee::V2::Product::Extraction::Extraction, input, inference_params) expect(response).not_to be_nil file = response.inference.file expect(file).not_to be_nil - expect(file).to be_a(Mindee::Parsing::V2::InferenceFile) + expect(file).to be_a(Mindee::V2::Parsing::InferenceFile) expect(file.name).to eq('default_sample.jpg') expect(file.page_count).to eq(1) model = response.inference.model expect(model).not_to be_nil - expect(model).to be_a(Mindee::Parsing::V2::InferenceModel) + expect(model).to be_a(Mindee::V2::Parsing::InferenceModel) expect(model.id).to eq(model_id) active_options = response.inference.active_options expect(active_options).not_to be_nil - expect(active_options).to be_a(Mindee::Parsing::V2::InferenceActiveOptions) + expect(active_options).to be_a(Mindee::V2::Parsing::InferenceActiveOptions) expect(active_options.raw_text).to eq(false) expect(active_options.polygon).to eq(false) expect(active_options.confidence).to eq(false) @@ -116,10 +120,10 @@ src_path = File.join(FILE_TYPES_DIR, 'pdf', 'blank_1.pdf') input = Mindee::Input::Source::FileInputSource.new(File.open(src_path, 'rb'), 'blank_1.pdf') - inference_params = Mindee::Input::InferenceParameters.new('INVALID_MODEL_ID') + inference_params = Mindee::V2::Product::Extraction::Params::ExtractionParameters.new('INVALID_MODEL_ID') expect do - client.enqueue_inference(input, inference_params) + client.enqueue(Mindee::V2::Product::Extraction::Extraction, input, inference_params) end.to raise_error(Mindee::Errors::MindeeHTTPErrorV2) { |e| expect(e.status).to eq(422) } end @@ -127,13 +131,13 @@ src_path = File.join(FILE_TYPES_DIR, 'pdf', 'blank_1.pdf') input = Mindee::Input::Source::FileInputSource.new(File.open(src_path, 'rb'), 'blank_1.pdf') - params = Mindee::Input::InferenceParameters.new( + params = Mindee::V2::Product::Extraction::Params::ExtractionParameters.new( model_id, webhook_ids: ['INVALID_WEBHOOK_ID'] ) expect do - client.enqueue_inference(input, params) + client.enqueue(Mindee::V2::Product::Extraction::Extraction, input, params) end.to raise_error(Mindee::Errors::MindeeHTTPErrorV2) { |e| expect(e.status).to eq(422) expect(e.code).to start_with('422-') @@ -148,13 +152,13 @@ src_path = File.join(FILE_TYPES_DIR, 'pdf', 'blank_1.pdf') input = Mindee::Input::Source::FileInputSource.new(File.open(src_path, 'rb'), 'blank_1.pdf') - inference_params = Mindee::Input::InferenceParameters.new( + inference_params = Mindee::V2::Product::Extraction::Params::ExtractionParameters.new( model_id, webhook_ids: ['fc405e37-4ba4-4d03-aeba-533a8d1f0f21', 'fc405e37-4ba4-4d03-aeba-533a8d1f0f21'] ) expect do - client.enqueue_inference(input, inference_params) + client.enqueue(Mindee::V2::Product::Extraction::Extraction, input, inference_params) end.to raise_error(Mindee::Errors::MindeeHTTPErrorV2) { |e| expect(e.status).to eq(422) expect(e.code).to start_with('422-') @@ -162,13 +166,13 @@ expect(e.title).to_not be_nil expect(e.errors).to be_an_instance_of(Array) expect(e.errors.count).to be_positive - expect(e.errors[0]).to be_an_instance_of(Mindee::Parsing::V2::ErrorItem) + expect(e.errors[0]).to be_an_instance_of(Mindee::V2::Parsing::ErrorItem) } end it 'raises MindeeHTTPErrorV2 on invalid job id' do expect do - client.get_inference('INVALID_JOB_ID') + client.get_result(Mindee::V2::Product::Extraction::Extraction, 'INVALID_JOB_ID') end.to raise_error(Mindee::Errors::MindeeHTTPErrorV2) { |e| expect(e.status).to eq(422) expect(e.code).to start_with('422-') @@ -187,7 +191,7 @@ 'default_sample.jpg' ) - inference_params = Mindee::Input::InferenceParameters.new( + inference_params = Mindee::V2::Product::Extraction::Params::ExtractionParameters.new( 'fc405e37-4ba4-4d03-aeba-533a8d1f0f21', raw_text: false, polygon: false, @@ -195,7 +199,7 @@ rag: false, file_alias: 'rb_integration_test' ) - client.enqueue_and_get_inference(input, inference_params) + client.enqueue_and_get_result(Mindee::V2::Product::Extraction::Extraction, input, inference_params) end.to raise_error(Mindee::Errors::MindeeHTTPErrorV2) { |e| expect(e.status).to eq(404) expect(e.code).to start_with('404-') @@ -210,9 +214,9 @@ it 'parses an URL input source without errors' do url_input = Mindee::Input::Source::URLInputSource.new(blank_pdf_url) - inference_params = Mindee::Input::InferenceParameters.new(model_id) + inference_params = Mindee::V2::Product::Extraction::Params::ExtractionParameters.new(model_id) - response = client.enqueue_and_get_inference(url_input, inference_params) + response = client.enqueue_and_get_result(Mindee::V2::Product::Extraction::Extraction, url_input, inference_params) expect(response).not_to be_nil expect(response.inference).not_to be_nil @@ -225,7 +229,7 @@ 'data_schema_replace_param.json')) input = Mindee::Input::Source::PathInputSource.new(File.join(FILE_TYPES_DIR, 'pdf', 'blank_1.pdf')) - inference_params = Mindee::Input::InferenceParameters.new( + inference_params = Mindee::V2::Product::Extraction::Params::ExtractionParameters.new( model_id, raw_text: false, polygon: false, @@ -235,17 +239,17 @@ data_schema: data_schema_replace ) - response = client.enqueue_and_get_inference(input, inference_params) + response = client.enqueue_and_get_result(Mindee::V2::Product::Extraction::Extraction, input, inference_params) expect(response).not_to be_nil model = response.inference.model expect(model).not_to be_nil - expect(model).to be_a(Mindee::Parsing::V2::InferenceModel) + expect(model).to be_a(Mindee::V2::Parsing::InferenceModel) expect(model.id).to eq(model_id) active_options = response.inference.active_options expect(active_options).not_to be_nil - expect(active_options).to be_a(Mindee::Parsing::V2::InferenceActiveOptions) + expect(active_options).to be_a(Mindee::V2::Parsing::InferenceActiveOptions) expect(active_options.raw_text).to eq(false) expect(active_options.polygon).to eq(false) expect(active_options.confidence).to eq(false) diff --git a/spec/v2/client_v2_spec.rb b/spec/v2/client_v2_spec.rb index 57c3c2fa..19da0605 100644 --- a/spec/v2/client_v2_spec.rb +++ b/spec/v2/client_v2_spec.rb @@ -2,8 +2,12 @@ require 'json' require 'mindee' +require 'mindee/v2/product' require_relative '../http/mock_http_response' # <- the original helper +using Mindee::V2::Product::Extraction::Params +using Mindee::V2::Product::Extraction + describe Mindee::ClientV2 do let(:input_doc) { Mindee::Input::Source::PathInputSource.new(File.join(FILE_TYPES_DIR, 'pdf', 'blank.pdf')) } let(:base_url) { 'https://dummy-url' } @@ -45,12 +49,12 @@ def stub_next_request_with(method, hash:, status_code: 0) it 'enqueue(path) raises MindeeHTTPErrorV2 on 4xx' do expect do stub_next_request_with(:enqueue, hash: JSON.generate(json400)) - inference_params = Mindee::Input::InferenceParameters.new( + params = Mindee::V2::Product::Extraction::Params::ExtractionParameters.new( 'dummy-model', raw_text: false, text_context: 'Hello my name is mud.' ) - client.enqueue_inference(input_doc, inference_params) + client.enqueue(Mindee::V2::Product::Extraction::Extraction, input_doc, params) end.to raise_error(Mindee::Errors::MindeeHTTPErrorV2) { |e| expect(e.status).to eq(400) expect(e.detail).to eq('Unsupported content.') @@ -60,8 +64,8 @@ def stub_next_request_with(method, hash:, status_code: 0) it 'enqueue_and_get_inference(path) raises MindeeHTTPErrorV2 on 4xx' do expect do stub_next_request_with(:enqueue, hash: JSON.generate(json400)) - inference_params = Mindee::Input::InferenceParameters.new('dummy-model') - client.enqueue_and_get_inference(input_doc, inference_params) + params = Mindee::V2::Product::Extraction::Params::ExtractionParameters.new('dummy-model') + client.enqueue_and_get_result(Mindee::V2::Product::Extraction::Extraction, input_doc, params) end.to raise_error(Mindee::Errors::MindeeHTTPErrorV2) { |e| expect(e.status).to eq(400) expect(e.detail).to eq('Unsupported content.') @@ -73,8 +77,8 @@ def stub_next_request_with(method, hash:, status_code: 0) expect do stub_next_request_with(:enqueue, hash: JSON.generate(error_hash)) - inference_params = Mindee::Input::InferenceParameters.new('dummy-model') - client.enqueue_inference(input_doc, inference_params) + params = Mindee::V2::Product::Extraction::Params::ExtractionParameters.new('dummy-model') + client.enqueue(Mindee::V2::Product::Extraction::Extraction, input_doc, params) end.to raise_error(Mindee::Errors::MindeeHTTPErrorV2) { |e| expect(e.status).to eq(413) expect(e.detail).to include('File exceeds size limit') @@ -84,10 +88,10 @@ def stub_next_request_with(method, hash:, status_code: 0) it 'get_job(job_id) returns a fully-formed JobResponse' do json_path = File.join(V2_DATA_DIR, 'job', 'ok_processing.json') parsed = File.read(json_path) - stub_next_request_with(:inference_job_req_get, hash: parsed, status_code: 200) + stub_next_request_with(:poll, hash: parsed, status_code: 200) resp = client.get_job('123e4567-e89b-12d3-a456-426614174000') - expect(resp).to be_a(Mindee::Parsing::V2::JobResponse) + expect(resp).to be_a(Mindee::V2::Parsing::JobResponse) expect(resp.job.status).to eq('Processing') expect( resp.job.created_at.strftime('%Y-%m-%dT%H:%M:%S.%6N') @@ -98,10 +102,10 @@ def stub_next_request_with(method, hash:, status_code: 0) it 'should deserialize a job properly' do json_path = File.join(V2_DATA_DIR, 'job', 'ok_processed_webhooks_ok.json') parsed = File.read(json_path) - stub_next_request_with(:inference_job_req_get, hash: parsed, status_code: 200) + stub_next_request_with(:poll, hash: parsed, status_code: 200) resp = client.get_job('123e4567-e89b-12d3-a456-426614174000') - expect(resp).to be_a(Mindee::Parsing::V2::JobResponse) + expect(resp).to be_a(Mindee::V2::Parsing::JobResponse) expect(resp.job.status).to eq('Processed') expect(resp.job.model_id).to eq('87654321-4321-4321-4321-CBA987654321') expect(resp.job.filename).to eq('default_sample.jpg') diff --git a/spec/v2/input/local_response_v2_spec.rb b/spec/v2/input/local_response_v2_spec.rb index ee5dd549..7cf1d54b 100644 --- a/spec/v2/input/local_response_v2_spec.rb +++ b/spec/v2/input/local_response_v2_spec.rb @@ -11,8 +11,8 @@ def assert_local_response(local_response) dummy_secret_key, 'invalid signature' )).to be(false) expect(local_response.get_hmac_signature(dummy_secret_key)).to eq(signature) - inference_response = local_response.deserialize_response(Mindee::Parsing::V2::InferenceResponse) - expect(inference_response).to be_a(Mindee::Parsing::V2::InferenceResponse) + inference_response = local_response.deserialize_response(Mindee::V2::Product::Extraction::ExtractionResponse) + expect(inference_response).to be_a(Mindee::V2::Product::Extraction::ExtractionResponse) expect(inference_response).not_to be_nil expect(inference_response.inference).not_to be_nil end diff --git a/spec/v2/parsing/inference_spec.rb b/spec/v2/parsing/inference_spec.rb index 31f2c2b0..d0a4fe1e 100644 --- a/spec/v2/parsing/inference_spec.rb +++ b/spec/v2/parsing/inference_spec.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true require 'mindee' +require 'mindee/v2/parsing/field' describe 'inference' do let(:findoc_path) { File.join(V2_PRODUCT_DATA_DIR, 'extraction', 'financial_document') } @@ -19,13 +20,13 @@ def load_v2_inference(resource_path) local_response = Mindee::Input::LocalResponse.new(resource_path) - local_response.deserialize_response(Mindee::Parsing::V2::InferenceResponse) + local_response.deserialize_response(Mindee::V2::Product::Extraction::ExtractionResponse) end - simple_field = Mindee::Parsing::V2::Field::SimpleField - object_field = Mindee::Parsing::V2::Field::ObjectField - list_field = Mindee::Parsing::V2::Field::ListField - field_confidence = Mindee::Parsing::V2::Field::FieldConfidence + simple_field = Mindee::V2::Parsing::Field::SimpleField + object_field = Mindee::V2::Parsing::Field::ObjectField + list_field = Mindee::V2::Parsing::Field::ListField + field_confidence = Mindee::V2::Parsing::Field::FieldConfidence describe 'simple' do it 'loads a blank inference with valid properties' do @@ -33,7 +34,7 @@ def load_v2_inference(resource_path) fields = response.inference.result.fields expect(fields).not_to be_empty - expect(fields).to be_a(Mindee::Parsing::V2::Field::InferenceFields) + expect(fields).to be_a(Mindee::V2::Parsing::Field::InferenceFields) expect(fields.size).to eq(21) expect(fields).to have_key('taxes') @@ -64,7 +65,7 @@ def load_v2_inference(resource_path) inference = response.inference job = inference.job expect(job).not_to be_nil - expect(job).to be_a(Mindee::Parsing::V2::InferenceJob) + expect(job).to be_a(Mindee::V2::Parsing::InferenceJob) expect(job.id).to eq('12345678-1234-1234-1234-jobid1234567') expect(inference).not_to be_nil @@ -191,7 +192,7 @@ def load_standard_fields expect(active_options.raw_text).to eq(true) fields = response.inference.result.fields - expect(fields).to be_a(Mindee::Parsing::V2::Field::InferenceFields) + expect(fields).to be_a(Mindee::V2::Parsing::Field::InferenceFields) fields end @@ -291,13 +292,13 @@ def load_standard_fields raw_text = response.inference.result.raw_text expect(raw_text).not_to be_nil - expect(raw_text).to be_a(Mindee::Parsing::V2::RawText) + expect(raw_text).to be_a(Mindee::V2::Parsing::RawText) expect(raw_text.to_s).to eq(File.read(raw_text_str_path, encoding: 'UTF-8')) expect(raw_text.pages.length).to eq(2) first = raw_text.pages.first - expect(first).to be_a(Mindee::Parsing::V2::RawTextPage) + expect(first).to be_a(Mindee::V2::Parsing::RawTextPage) expect(first.content).to eq('This is the raw text of the first page...') raw_text.pages.each do |page| diff --git a/spec/v2/parsing/job_webhook_spec.rb b/spec/v2/parsing/job_webhook_spec.rb index b07e6263..3fbead36 100644 --- a/spec/v2/parsing/job_webhook_spec.rb +++ b/spec/v2/parsing/job_webhook_spec.rb @@ -1,8 +1,9 @@ # frozen_string_literal: true require 'mindee' +require 'mindee/v2/parsing/job_webhook' -describe Mindee::Parsing::V2::JobWebhook do +describe Mindee::V2::Parsing::JobWebhook do describe '#initialize' do context 'when error key is present but value is nil' do it 'does not raise an error and sets @error to nil' do @@ -52,7 +53,7 @@ expect(webhook.id).to eq('12345678-1234-1234-1234-123456789012') expect(webhook.status).to eq('Failed') - expect(webhook.error).to be_a(Mindee::Parsing::V2::ErrorResponse) + expect(webhook.error).to be_a(Mindee::V2::Parsing::ErrorResponse) expect(webhook.error.status).to eq(500) expect(webhook.error.detail).to eq('Internal server error') end diff --git a/spec/v2/input/inference_parameter_spec.rb b/spec/v2/product/extraction/extraction_parameter_spec.rb similarity index 72% rename from spec/v2/input/inference_parameter_spec.rb rename to spec/v2/product/extraction/extraction_parameter_spec.rb index bd4ae299..59289cff 100644 --- a/spec/v2/input/inference_parameter_spec.rb +++ b/spec/v2/product/extraction/extraction_parameter_spec.rb @@ -1,9 +1,9 @@ # frozen_string_literal: true -require 'mindee/input/inference_parameters' require 'mindee/input/data_schema' +require 'mindee/v2/product/extraction/params/extraction_parameters' -describe Mindee::Input::InferenceParameters do +describe Mindee::V2::Product::Extraction::Params::ExtractionParameters do let(:extracted_schema_content) do File.read(File.join(V2_PRODUCT_DATA_DIR, 'extraction', 'data_schema_replace_param.json')) end @@ -14,14 +14,14 @@ describe 'Data Schema' do describe "shouldn't replace when unset" do it 'should initialize with a data schema' do - param = Mindee::Input::InferenceParameters.new( + param = Mindee::V2::Product::Extraction::Params::ExtractionParameters.new( 'dummy-model' ) expect(param.data_schema).to be_nil end it 'should initialize with string' do - param = Mindee::Input::InferenceParameters.new( + param = Mindee::V2::Product::Extraction::Params::ExtractionParameters.new( 'dummy-model', data_schema: extracted_schema_str ) @@ -29,7 +29,7 @@ end it 'should initialize with hash' do - param = Mindee::Input::InferenceParameters.new( + param = Mindee::V2::Product::Extraction::Params::ExtractionParameters.new( 'dummy-model', data_schema: extracted_schema_hash ) @@ -37,7 +37,7 @@ end it 'should initialize with DataSchema object' do - param = Mindee::Input::InferenceParameters.new( + param = Mindee::V2::Product::Extraction::Params::ExtractionParameters.new( 'dummy-model', data_schema: extracted_schema_object ) diff --git a/spec/v2/product/extraction/extraction_spec.rb b/spec/v2/product/extraction/extraction_spec.rb index 352a822f..4a676f19 100644 --- a/spec/v2/product/extraction/extraction_spec.rb +++ b/spec/v2/product/extraction/extraction_spec.rb @@ -3,6 +3,11 @@ require 'mindee' require 'mindee/input/local_response' require 'mindee/v2/product' +require 'mindee/v2/parsing/field' +require 'mindee/v2/product/extraction/extraction_response' + +using Mindee::V2::Product::Extraction +using Mindee::V2::Parsing::Field describe 'extraction' do let(:findoc_path) { File.join(V2_PRODUCT_DATA_DIR, 'extraction', 'financial_document') } @@ -24,10 +29,10 @@ def load_v2_extraction_inference(resource_path) local_response.deserialize_response(Mindee::V2::Product::Extraction::ExtractionResponse) end - simple_field = Mindee::Parsing::V2::Field::SimpleField - object_field = Mindee::Parsing::V2::Field::ObjectField - list_field = Mindee::Parsing::V2::Field::ListField - field_confidence = Mindee::Parsing::V2::Field::FieldConfidence + simple_field = Mindee::V2::Parsing::Field::SimpleField + object_field = Mindee::V2::Parsing::Field::ObjectField + list_field = Mindee::V2::Parsing::Field::ListField + field_confidence = Mindee::V2::Parsing::Field::FieldConfidence describe 'simple' do it 'loads a blank extraction inference with valid properties' do @@ -35,7 +40,7 @@ def load_v2_extraction_inference(resource_path) fields = response.inference.result.fields expect(fields).not_to be_empty - expect(fields).to be_a(Mindee::Parsing::V2::Field::InferenceFields) + expect(fields).to be_a(Mindee::V2::Parsing::Field::InferenceFields) expect(fields.size).to eq(21) expect(fields).to have_key('taxes') @@ -66,7 +71,7 @@ def load_v2_extraction_inference(resource_path) inference = response.inference job = inference.job expect(job).not_to be_nil - expect(job).to be_a(Mindee::Parsing::V2::InferenceJob) + expect(job).to be_a(Mindee::V2::Parsing::InferenceJob) expect(job.id).to eq('12345678-1234-1234-1234-jobid1234567') expect(inference).not_to be_nil @@ -193,7 +198,7 @@ def load_standard_fields expect(active_options.raw_text).to eq(true) fields = response.inference.result.fields - expect(fields).to be_a(Mindee::Parsing::V2::Field::InferenceFields) + expect(fields).to be_a(Mindee::V2::Parsing::Field::InferenceFields) fields end @@ -293,13 +298,13 @@ def load_standard_fields raw_text = response.inference.result.raw_text expect(raw_text).not_to be_nil - expect(raw_text).to be_a(Mindee::Parsing::V2::RawText) + expect(raw_text).to be_a(Mindee::V2::Parsing::RawText) expect(raw_text.to_s).to eq(File.read(raw_text_str_path, encoding: 'UTF-8')) expect(raw_text.pages.length).to eq(2) first = raw_text.pages.first - expect(first).to be_a(Mindee::Parsing::V2::RawTextPage) + expect(first).to be_a(Mindee::V2::Parsing::RawTextPage) expect(first.content).to eq('This is the raw text of the first page...') raw_text.pages.each do |page|