From f7e3b264be6a1824da9e8839db86d699706b1772 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ianar=C3=A9=20S=C3=A9vi?= Date: Thu, 3 Dec 2026 15:22:20 +0100 Subject: [PATCH] :sparkles: pass text context to chained model --- AGENTS.md | 2 +- lib/mindee/v2/client_options.rb | 1 + .../base_classifier_product_parameters.rb | 73 +++++++++++++ .../params/classification_parameters.rb | 10 +- .../v2/product/crop/params/crop_parameters.rb | 10 +- .../product/split/params/split_parameters.rb | 10 +- .../base_classifier_product_parameters.rbs | 25 +++++ .../params/classification_parameters.rbs | 5 +- .../product/crop/params/crop_parameters.rbs | 5 +- .../product/split/params/split_parameters.rbs | 5 +- spec/data | 2 +- .../classification_parameter_spec.rb | 61 +++++++++++ spec/v2/product/crop/crop_parameter_spec.rb | 61 +++++++++++ .../extraction/extraction_parameter_spec.rb | 100 +++++++++++++----- spec/v2/product/ocr/ocr_parameter_spec.rb | 50 +++++++++ spec/v2/product/split/split_parameter_spec.rb | 61 +++++++++++ 16 files changed, 436 insertions(+), 45 deletions(-) create mode 100644 lib/mindee/v2/client_options/base_classifier_product_parameters.rb create mode 100644 sig/mindee/v2/client_options/base_classifier_product_parameters.rbs create mode 100644 spec/v2/product/classification/classification_parameter_spec.rb create mode 100644 spec/v2/product/crop/crop_parameter_spec.rb create mode 100644 spec/v2/product/ocr/ocr_parameter_spec.rb create mode 100644 spec/v2/product/split/split_parameter_spec.rb diff --git a/AGENTS.md b/AGENTS.md index 9fa365e4..01a64659 100644 --- a/AGENTS.md +++ b/AGENTS.md @@ -3,7 +3,7 @@ ## Code Converting - When given code in another language for conversion, keep the original's overall naming for class, variable, and function names. - Only adjust as needed to conform to Ruby conventions, ex `myMethod` becomes `my_method`. + Only adjust as needed to conform to Ruby conventions, ex `myMethod` becomes `my_method`, `MyMethodAsync` (C#) becomes `my_method`. ## Code Linting - Run `prek run -a` to lint and format the code. diff --git a/lib/mindee/v2/client_options.rb b/lib/mindee/v2/client_options.rb index 3eaae98b..2c33c4d7 100644 --- a/lib/mindee/v2/client_options.rb +++ b/lib/mindee/v2/client_options.rb @@ -1,4 +1,5 @@ # frozen_string_literal: true require_relative 'client_options/base_product_parameters' +require_relative 'client_options/base_classifier_product_parameters' require_relative 'client_options/base_search_parameters' diff --git a/lib/mindee/v2/client_options/base_classifier_product_parameters.rb b/lib/mindee/v2/client_options/base_classifier_product_parameters.rb new file mode 100644 index 00000000..b8a91db9 --- /dev/null +++ b/lib/mindee/v2/client_options/base_classifier_product_parameters.rb @@ -0,0 +1,73 @@ +# frozen_string_literal: true + +module Mindee + module V2 + module ClientOptions + # Base parameters for classification-based products. + class BaseClassifierProductParameters < BaseProductParameters + # @return [String, nil] Pass additional context to the extraction model chained to this utility inference. + attr_reader :extraction_text_context + + # @param [String] model_id ID of the model + # @param [String, nil] file_alias File alias, if applicable. + # @param [Array, nil] webhook_ids List of webhook IDs to propagate the API response to. + # @param [Boolean, nil] close_file Whether to close the file after parsing. + # @param [String, nil] extraction_text_context Pass additional context to the extraction model + # chained to this utility inference. + def initialize( + model_id, + file_alias: nil, + webhook_ids: nil, + close_file: true, + extraction_text_context: nil + ) + super( + model_id, + file_alias: file_alias, + webhook_ids: webhook_ids, + close_file: close_file + ) + + if !extraction_text_context.nil? && !extraction_text_context.is_a?(String) + raise Error::MindeeInputError, 'Extraction text context must be a string.' + end + + @extraction_text_context = extraction_text_context + end + + # Load from a hash + # @param [Hash] params Parameters to provide as a hash. + # @return [BaseClassifierProductParameters] + def self.from_hash(params: {}) + cleaned_params = load_from_hash(params: params) + new( + cleaned_params[:model_id], + file_alias: cleaned_params[:file_alias], + webhook_ids: cleaned_params[:webhook_ids], + close_file: cleaned_params[:close_file], + extraction_text_context: cleaned_params[:extraction_text_context] + ) + end + + # Loads parameters from a Hash. + # @param [Hash] params Parameters to provide as a hash. + # @return [Hash] + def self.load_from_hash(params: {}) + cleaned_params = super + cleaned_params[:extraction_text_context] = + params[:extraction_text_context] || params['extraction_text_context'] + cleaned_params + end + + # Gets the request parameters for the endpoint. + # @return [Hash{String => String, Array}] + def request_parameters + params = super + text_context = @extraction_text_context + params['extraction_text_context'] = text_context if text_context + params + end + end + end + end +end diff --git a/lib/mindee/v2/product/classification/params/classification_parameters.rb b/lib/mindee/v2/product/classification/params/classification_parameters.rb index a6d41fde..96d41490 100644 --- a/lib/mindee/v2/product/classification/params/classification_parameters.rb +++ b/lib/mindee/v2/product/classification/params/classification_parameters.rb @@ -7,7 +7,7 @@ module Classification # Classification parameters. module Params # Parameters accepted by the classification utility v2 endpoint. - class ClassificationParameters < Mindee::V2::ClientOptions::BaseProductParameters + class ClassificationParameters < Mindee::V2::ClientOptions::BaseClassifierProductParameters # @return [String] Slug for the endpoint. def self.slug 'classification' @@ -17,11 +17,14 @@ def self.slug # @param [String, nil] file_alias File alias, if applicable. # @param [Array, nil] webhook_ids List of webhook IDs to propagate the API response to. # @param [Boolean, nil] close_file Whether to close the file after parsing. + # @param [String, nil] extraction_text_context Pass additional context to the extraction model chained + # to this utility inference. def initialize( model_id, file_alias: nil, webhook_ids: nil, - close_file: true + close_file: true, + extraction_text_context: nil ) super end @@ -34,7 +37,8 @@ def self.from_hash(params: {}) params.fetch(:model_id), file_alias: params.fetch(:file_alias, nil), webhook_ids: params.fetch(:webhook_ids, nil), - close_file: params.fetch(:close_file, true) + close_file: params.fetch(:close_file, true), + extraction_text_context: params.fetch(:extraction_text_context, nil) ) end end diff --git a/lib/mindee/v2/product/crop/params/crop_parameters.rb b/lib/mindee/v2/product/crop/params/crop_parameters.rb index e4d613bd..f95bd6eb 100644 --- a/lib/mindee/v2/product/crop/params/crop_parameters.rb +++ b/lib/mindee/v2/product/crop/params/crop_parameters.rb @@ -7,7 +7,7 @@ module Crop # Crop parameters. module Params # Parameters accepted by the crop utility v2 endpoint. - class CropParameters < Mindee::V2::ClientOptions::BaseProductParameters + class CropParameters < Mindee::V2::ClientOptions::BaseClassifierProductParameters # @return [String] Slug for the endpoint. def self.slug 'crop' @@ -17,11 +17,14 @@ def self.slug # @param [String, nil] file_alias File alias, if applicable. # @param [Array, nil] webhook_ids List of webhook IDs to propagate the API response to. # @param [Boolean, nil] close_file Whether to close the file after parsing. + # @param [String, nil] extraction_text_context Pass additional context to the extraction model chained + # to this utility inference. def initialize( model_id, file_alias: nil, webhook_ids: nil, - close_file: true + close_file: true, + extraction_text_context: nil ) super end @@ -34,7 +37,8 @@ def self.from_hash(params: {}) params.fetch(:model_id), file_alias: params.fetch(:file_alias, nil), webhook_ids: params.fetch(:webhook_ids, nil), - close_file: params.fetch(:close_file, true) + close_file: params.fetch(:close_file, true), + extraction_text_context: params.fetch(:extraction_text_context, nil) ) end end diff --git a/lib/mindee/v2/product/split/params/split_parameters.rb b/lib/mindee/v2/product/split/params/split_parameters.rb index 410e6eac..97185bf6 100644 --- a/lib/mindee/v2/product/split/params/split_parameters.rb +++ b/lib/mindee/v2/product/split/params/split_parameters.rb @@ -8,7 +8,7 @@ module Split # Split parameters. module Params # Parameters accepted by the split utility v2 endpoint. - class SplitParameters < Mindee::V2::ClientOptions::BaseProductParameters + class SplitParameters < Mindee::V2::ClientOptions::BaseClassifierProductParameters # @return [String] Slug for the endpoint. def self.slug 'split' @@ -18,11 +18,14 @@ def self.slug # @param [String, nil] file_alias File alias, if applicable. # @param [Array, nil] webhook_ids List of webhook IDs to propagate the API response to. # @param [Boolean, nil] close_file Whether to close the file after parsing. + # @param [String, nil] extraction_text_context Pass additional context to the extraction model chained + # to this utility inference. def initialize( model_id, file_alias: nil, webhook_ids: nil, - close_file: true + close_file: true, + extraction_text_context: nil ) super end @@ -35,7 +38,8 @@ def self.from_hash(params: {}) params.fetch(:model_id), file_alias: params.fetch(:file_alias, nil), webhook_ids: params.fetch(:webhook_ids, nil), - close_file: params.fetch(:close_file, true) + close_file: params.fetch(:close_file, true), + extraction_text_context: params.fetch(:extraction_text_context, nil) ) end end diff --git a/sig/mindee/v2/client_options/base_classifier_product_parameters.rbs b/sig/mindee/v2/client_options/base_classifier_product_parameters.rbs new file mode 100644 index 00000000..011b8d47 --- /dev/null +++ b/sig/mindee/v2/client_options/base_classifier_product_parameters.rbs @@ -0,0 +1,25 @@ +# lib/mindee/v2/client_options/base_classifier_product_parameters.rb + +module Mindee + module V2 + module ClientOptions + class BaseClassifierProductParameters < BaseProductParameters + def self.from_hash: (params: Hash[String | Symbol, untyped]) -> BaseClassifierProductParameters + + def self.load_from_hash: (params: Hash[String | Symbol, untyped]) -> Hash[String | Symbol, untyped] + + attr_reader extraction_text_context: String? + + def initialize: ( + String, + ?file_alias: String?, + ?webhook_ids: Array[String]?, + ?close_file: bool?, + ?extraction_text_context: String? + ) -> void + + def request_parameters: -> Hash[String, String | Array[String]] + end + end + end +end diff --git a/sig/mindee/v2/product/classification/params/classification_parameters.rbs b/sig/mindee/v2/product/classification/params/classification_parameters.rbs index 566d213c..415e5ca7 100644 --- a/sig/mindee/v2/product/classification/params/classification_parameters.rbs +++ b/sig/mindee/v2/product/classification/params/classification_parameters.rbs @@ -3,7 +3,7 @@ module Mindee module Product module Classification module Params - class ClassificationParameters < ClientOptions::BaseProductParameters + class ClassificationParameters < ClientOptions::BaseClassifierProductParameters def self.slug: -> String def self.from_hash: (params: Hash[String | Symbol, untyped]) -> ClassificationParameters @@ -12,7 +12,8 @@ module Mindee String, ?file_alias: String?, ?webhook_ids: Array[String]?, - ?close_file: bool? + ?close_file: bool?, + ?extraction_text_context: String? ) -> void end end diff --git a/sig/mindee/v2/product/crop/params/crop_parameters.rbs b/sig/mindee/v2/product/crop/params/crop_parameters.rbs index 161b1f7c..8cd31b71 100644 --- a/sig/mindee/v2/product/crop/params/crop_parameters.rbs +++ b/sig/mindee/v2/product/crop/params/crop_parameters.rbs @@ -3,7 +3,7 @@ module Mindee module Product module Crop module Params - class CropParameters < ClientOptions::BaseProductParameters + class CropParameters < ClientOptions::BaseClassifierProductParameters def self.slug: -> String def self.from_hash: (params: Hash[String | Symbol, untyped]) -> CropParameters @@ -12,7 +12,8 @@ module Mindee String, ?file_alias: String?, ?webhook_ids: Array[String]?, - ?close_file: bool? + ?close_file: bool?, + ?extraction_text_context: String? ) -> void end end diff --git a/sig/mindee/v2/product/split/params/split_parameters.rbs b/sig/mindee/v2/product/split/params/split_parameters.rbs index 7f8fe943..12cf19d1 100644 --- a/sig/mindee/v2/product/split/params/split_parameters.rbs +++ b/sig/mindee/v2/product/split/params/split_parameters.rbs @@ -3,7 +3,7 @@ module Mindee module Product module Split module Params - class SplitParameters < ClientOptions::BaseProductParameters + class SplitParameters < ClientOptions::BaseClassifierProductParameters def self.slug: -> String def self.from_hash: (params: Hash[String | Symbol, untyped]) -> SplitParameters @@ -12,7 +12,8 @@ module Mindee String, ?file_alias: String?, ?webhook_ids: Array[String]?, - ?close_file: bool? + ?close_file: bool?, + ?extraction_text_context: String? ) -> void end end diff --git a/spec/data b/spec/data index a4843abd..e6d5046f 160000 --- a/spec/data +++ b/spec/data @@ -1 +1 @@ -Subproject commit a4843abd5ac5a6fac6ac9cf4c5fa0cf9103da7b6 +Subproject commit e6d5046f09c9c3fed4cf086c340664da50734615 diff --git a/spec/v2/product/classification/classification_parameter_spec.rb b/spec/v2/product/classification/classification_parameter_spec.rb new file mode 100644 index 00000000..473b0365 --- /dev/null +++ b/spec/v2/product/classification/classification_parameter_spec.rb @@ -0,0 +1,61 @@ +# frozen_string_literal: true + +require 'mindee' +require 'mindee/v2/product/classification/params/classification_parameters' + +describe Mindee::V2::Product::Classification::Params::ClassificationParameters do + let(:model_id) { 'test-model-id' } + + it 'should init with only required parameters' do + product_params = described_class.new(model_id) + + request_params = product_params.request_parameters + expect(request_params['model_id']).to eq(model_id) + expect(request_params).not_to have_key('alias') + expect(request_params).not_to have_key('webhook_ids') + expect(request_params).not_to have_key('extraction_text_context') + end + + it 'should init with all parameters' do + product_params = described_class.new( + model_id, + file_alias: 'test-alias', + webhook_ids: ['webhook-1', 'webhook-2'], + extraction_text_context: 'context' + ) + + request_params = product_params.request_parameters + expect(request_params['model_id']).to eq(model_id) + expect(request_params['alias']).to eq('test-alias') + expect(request_params['webhook_ids']).to eq('webhook-1,webhook-2') + expect(request_params['extraction_text_context']).to eq('context') + end + + it 'should load from a hash' do + product_params = described_class.from_hash( + params: { + model_id: model_id, + file_alias: 'test-alias', + webhook_ids: ['webhook-1', 'webhook-2'], + extraction_text_context: 'context', + } + ) + + expect(product_params.model_id).to eq(model_id) + expect(product_params.file_alias).to eq('test-alias') + expect(product_params.webhook_ids).to eq(['webhook-1', 'webhook-2']) + expect(product_params.extraction_text_context).to eq('context') + end + + it 'should raise an error if extraction_text_context is not a string' do + expect do + described_class.new(model_id, extraction_text_context: 123) + end.to raise_error(Mindee::Error::MindeeInputError, 'Extraction text context must be a string.') + end + + it 'should raise an error if model_id is empty' do + expect do + described_class.new('') + end.to raise_error(Mindee::Error::MindeeInputError, 'Model ID is required.') + end +end diff --git a/spec/v2/product/crop/crop_parameter_spec.rb b/spec/v2/product/crop/crop_parameter_spec.rb new file mode 100644 index 00000000..19106c41 --- /dev/null +++ b/spec/v2/product/crop/crop_parameter_spec.rb @@ -0,0 +1,61 @@ +# frozen_string_literal: true + +require 'mindee' +require 'mindee/v2/product/crop/params/crop_parameters' + +describe Mindee::V2::Product::Crop::Params::CropParameters do + let(:model_id) { 'test-model-id' } + + it 'should init with only required parameters' do + product_params = described_class.new(model_id) + + request_params = product_params.request_parameters + expect(request_params['model_id']).to eq(model_id) + expect(request_params).not_to have_key('alias') + expect(request_params).not_to have_key('webhook_ids') + expect(request_params).not_to have_key('extraction_text_context') + end + + it 'should init with all parameters' do + product_params = described_class.new( + model_id, + file_alias: 'test-alias', + webhook_ids: ['webhook-1', 'webhook-2'], + extraction_text_context: 'context' + ) + + request_params = product_params.request_parameters + expect(request_params['model_id']).to eq(model_id) + expect(request_params['alias']).to eq('test-alias') + expect(request_params['webhook_ids']).to eq('webhook-1,webhook-2') + expect(request_params['extraction_text_context']).to eq('context') + end + + it 'should load from a hash' do + product_params = described_class.from_hash( + params: { + model_id: model_id, + file_alias: 'test-alias', + webhook_ids: ['webhook-1', 'webhook-2'], + extraction_text_context: 'context', + } + ) + + expect(product_params.model_id).to eq(model_id) + expect(product_params.file_alias).to eq('test-alias') + expect(product_params.webhook_ids).to eq(['webhook-1', 'webhook-2']) + expect(product_params.extraction_text_context).to eq('context') + end + + it 'should raise an error if extraction_text_context is not a string' do + expect do + described_class.new(model_id, extraction_text_context: 123) + end.to raise_error(Mindee::Error::MindeeInputError, 'Extraction text context must be a string.') + end + + it 'should raise an error if model_id is empty' do + expect do + described_class.new('') + end.to raise_error(Mindee::Error::MindeeInputError, 'Model ID is required.') + end +end diff --git a/spec/v2/product/extraction/extraction_parameter_spec.rb b/spec/v2/product/extraction/extraction_parameter_spec.rb index 273364b0..208b0c0a 100644 --- a/spec/v2/product/extraction/extraction_parameter_spec.rb +++ b/spec/v2/product/extraction/extraction_parameter_spec.rb @@ -1,22 +1,90 @@ # frozen_string_literal: true require 'json' +require 'mindee' require_relative '../../../data' require 'mindee/v2/product/extraction/params/data_schema' require 'mindee/v2/product/extraction/params/extraction_parameters' describe Mindee::V2::Product::Extraction::Params::ExtractionParameters do + let(:model_id) { 'test-model-id' } let(:replace_path) { File.join(V2_PRODUCT_DATA_DIR, 'extraction', 'data_schema_replace_param.json') } let(:data_schema_dict) { JSON.parse(File.read(replace_path)) } let(:data_schema_string) { data_schema_dict.to_h.to_json } let(:data_schema_instance) { Mindee::V2::Product::Extraction::Params::DataSchema.new(data_schema_dict) } - it 'should init with minimum values' do - model_id = 'dummy-model' - product_params = Mindee::V2::Product::Extraction::Params::ExtractionParameters.new(model_id) + it 'should init with only required parameters' do + product_params = described_class.new(model_id) expect(product_params.model_id).to eq(model_id) - expect(product_params.request_parameters['model_id']).to eq(model_id) + + request_params = product_params.request_parameters + expect(request_params['model_id']).to eq(model_id) + expect(request_params).not_to have_key('alias') + expect(request_params).not_to have_key('webhook_ids') + expect(request_params).not_to have_key('rag') + expect(request_params).not_to have_key('raw_text') + expect(request_params).not_to have_key('polygon') + expect(request_params).not_to have_key('confidence') + expect(request_params).not_to have_key('text_context') + expect(request_params).not_to have_key('data_schema') + end + + it 'should init with all parameters' do + product_params = described_class.new( + model_id, + file_alias: 'test-alias', + webhook_ids: ['webhook-1', 'webhook-2'], + rag: true, + raw_text: false, + polygon: true, + confidence: false, + text_context: 'test context', + data_schema: data_schema_string + ) + + request_params = product_params.request_parameters + expect(request_params['model_id']).to eq(model_id) + expect(request_params['alias']).to eq('test-alias') + expect(request_params['webhook_ids']).to eq('webhook-1,webhook-2') + expect(request_params['rag']).to eq('true') + expect(request_params['raw_text']).to eq('false') + expect(request_params['polygon']).to eq('true') + expect(request_params['confidence']).to eq('false') + expect(request_params['text_context']).to eq('test context') + expect(request_params['data_schema']).to eq(data_schema_string) + end + + it 'should load from a hash' do + product_params = described_class.from_hash( + params: { + model_id: model_id, + file_alias: 'test-alias', + webhook_ids: ['webhook-1', 'webhook-2'], + rag: true, + raw_text: false, + polygon: true, + confidence: false, + text_context: 'test context', + data_schema: data_schema_string, + } + ) + + expect(product_params.model_id).to eq(model_id) + expect(product_params.file_alias).to eq('test-alias') + expect(product_params.webhook_ids).to eq(['webhook-1', 'webhook-2']) + expect(product_params.rag).to eq(true) + expect(product_params.raw_text).to eq(false) + expect(product_params.polygon).to eq(true) + expect(product_params.confidence).to eq(false) + expect(product_params.text_context).to eq('test context') + expect(product_params.data_schema.to_s).to eq(data_schema_string) + end + + it 'should raise an error if model_id is empty' do + expect do + described_class.new('') + end.to raise_error(Mindee::Error::MindeeInputError, 'Model ID is required.') end describe 'Data Schema' do @@ -53,28 +121,4 @@ end end end - - describe 'request_parameters' do - it 'returns hash with correct parameters' do - param = Mindee::V2::Product::Extraction::Params::ExtractionParameters.new( - 'dummy-model', - text_context: 'sample context', - webhook_ids: ['hook-1', 'hook-2'], - file_alias: 'my_file', - rag: true, - raw_text: false, - polygon: true, - confidence: false - ) - params = param.request_parameters - expect(params['model_id']).to eq('dummy-model') - expect(params['alias']).to eq('my_file') - expect(params['webhook_ids']).to eq('hook-1,hook-2') - expect(params['text_context']).to eq('sample context') - expect(params['rag']).to eq('true') - expect(params['raw_text']).to eq('false') - expect(params['polygon']).to eq('true') - expect(params['confidence']).to eq('false') - end - end end diff --git a/spec/v2/product/ocr/ocr_parameter_spec.rb b/spec/v2/product/ocr/ocr_parameter_spec.rb new file mode 100644 index 00000000..9dedbca6 --- /dev/null +++ b/spec/v2/product/ocr/ocr_parameter_spec.rb @@ -0,0 +1,50 @@ +# frozen_string_literal: true + +require 'mindee' +require 'mindee/v2/product/ocr/params/ocr_parameters' + +describe Mindee::V2::Product::OCR::Params::OCRParameters do + let(:model_id) { 'test-model-id' } + + it 'should init with only required parameters' do + product_params = described_class.new(model_id) + + request_params = product_params.request_parameters + expect(request_params['model_id']).to eq(model_id) + expect(request_params).not_to have_key('alias') + expect(request_params).not_to have_key('webhook_ids') + end + + it 'should init with all parameters' do + product_params = described_class.new( + model_id, + file_alias: 'test-alias', + webhook_ids: ['webhook-1', 'webhook-2'] + ) + + request_params = product_params.request_parameters + expect(request_params['model_id']).to eq(model_id) + expect(request_params['alias']).to eq('test-alias') + expect(request_params['webhook_ids']).to eq('webhook-1,webhook-2') + end + + it 'should load from a hash' do + product_params = described_class.from_hash( + params: { + model_id: model_id, + file_alias: 'test-alias', + webhook_ids: ['webhook-1', 'webhook-2'], + } + ) + + expect(product_params.model_id).to eq(model_id) + expect(product_params.file_alias).to eq('test-alias') + expect(product_params.webhook_ids).to eq(['webhook-1', 'webhook-2']) + end + + it 'should raise an error if model_id is empty' do + expect do + described_class.new('') + end.to raise_error(Mindee::Error::MindeeInputError, 'Model ID is required.') + end +end diff --git a/spec/v2/product/split/split_parameter_spec.rb b/spec/v2/product/split/split_parameter_spec.rb new file mode 100644 index 00000000..855fea92 --- /dev/null +++ b/spec/v2/product/split/split_parameter_spec.rb @@ -0,0 +1,61 @@ +# frozen_string_literal: true + +require 'mindee' +require 'mindee/v2/product/split/params/split_parameters' + +describe Mindee::V2::Product::Split::Params::SplitParameters do + let(:model_id) { 'test-model-id' } + + it 'should init with only required parameters' do + product_params = described_class.new(model_id) + + request_params = product_params.request_parameters + expect(request_params['model_id']).to eq(model_id) + expect(request_params).not_to have_key('alias') + expect(request_params).not_to have_key('webhook_ids') + expect(request_params).not_to have_key('extraction_text_context') + end + + it 'should init with all parameters' do + product_params = described_class.new( + model_id, + file_alias: 'test-alias', + webhook_ids: ['webhook-1', 'webhook-2'], + extraction_text_context: 'context' + ) + + request_params = product_params.request_parameters + expect(request_params['model_id']).to eq(model_id) + expect(request_params['alias']).to eq('test-alias') + expect(request_params['webhook_ids']).to eq('webhook-1,webhook-2') + expect(request_params['extraction_text_context']).to eq('context') + end + + it 'should load from a hash' do + product_params = described_class.from_hash( + params: { + model_id: model_id, + file_alias: 'test-alias', + webhook_ids: ['webhook-1', 'webhook-2'], + extraction_text_context: 'context', + } + ) + + expect(product_params.model_id).to eq(model_id) + expect(product_params.file_alias).to eq('test-alias') + expect(product_params.webhook_ids).to eq(['webhook-1', 'webhook-2']) + expect(product_params.extraction_text_context).to eq('context') + end + + it 'should raise an error if extraction_text_context is not a string' do + expect do + described_class.new(model_id, extraction_text_context: 123) + end.to raise_error(Mindee::Error::MindeeInputError, 'Extraction text context must be a string.') + end + + it 'should raise an error if model_id is empty' do + expect do + described_class.new('') + end.to raise_error(Mindee::Error::MindeeInputError, 'Model ID is required.') + end +end