From c1d713a3d18c3f069e44903ce5a56bd11e650b59 Mon Sep 17 00:00:00 2001 From: sebastianMindee <130448732+sebastianMindee@users.noreply.github.com> Date: Tue, 2 Dec 2025 11:35:33 +0100 Subject: [PATCH 1/3] :sparkles: add text context option return param --- .../parsing/v2/inference_active_options.rb | 3 + sig/mindee/input/local_response.rbs | 2 +- .../parsing/v2/inference_active_options.rbs | 1 + spec/data | 2 +- ...onse_spec.rb => local_response_v1_spec.rb} | 0 spec/v2/client_v2_integration.rb | 5 +- spec/v2/input/local_response_v2_spec.rb | 60 +++++++++++++++++++ spec/v2/parsing/inference_spec.rb | 10 ++++ 8 files changed, 80 insertions(+), 3 deletions(-) rename spec/v1/input/{local_response_spec.rb => local_response_v1_spec.rb} (100%) create mode 100644 spec/v2/input/local_response_v2_spec.rb diff --git a/lib/mindee/parsing/v2/inference_active_options.rb b/lib/mindee/parsing/v2/inference_active_options.rb index 3a198c7b..3dad5b00 100644 --- a/lib/mindee/parsing/v2/inference_active_options.rb +++ b/lib/mindee/parsing/v2/inference_active_options.rb @@ -13,6 +13,8 @@ class InferenceActiveOptions attr_reader :confidence # @return [Boolean] Whether the Retrieval-Augmented Generation feature was activated. attr_reader :rag + # @return [Boolean] Whether the text context feature was activated. + attr_reader :text_context # @param server_response [Hash] Raw JSON parsed into a Hash. def initialize(server_response) @@ -20,6 +22,7 @@ def initialize(server_response) @polygon = server_response['polygon'] @confidence = server_response['confidence'] @rag = server_response['rag'] + @text_context = server_response['text_context'] end # String representation. diff --git a/sig/mindee/input/local_response.rbs b/sig/mindee/input/local_response.rbs index 89a35dff..fd28bd5f 100644 --- a/sig/mindee/input/local_response.rbs +++ b/sig/mindee/input/local_response.rbs @@ -3,7 +3,7 @@ module Mindee module Input class LocalResponse def file: -> StringIO - def initialize: (File | IO | StringIO | String | Pathname) -> void + def initialize: (File | IO | StringIO | String | Pathname | Tempfile) -> void def as_hash: -> Hash[String | Symbol, untyped] def self.process_secret_key: (String) -> String def get_hmac_signature: (String) -> String diff --git a/sig/mindee/parsing/v2/inference_active_options.rbs b/sig/mindee/parsing/v2/inference_active_options.rbs index 6ef779bf..2dd4b626 100644 --- a/sig/mindee/parsing/v2/inference_active_options.rbs +++ b/sig/mindee/parsing/v2/inference_active_options.rbs @@ -6,6 +6,7 @@ module Mindee attr_reader polygon: bool attr_reader rag: bool attr_reader raw_text: bool + attr_reader text_context: bool def initialize: (Hash[String | Symbol, untyped]) -> void end diff --git a/spec/data b/spec/data index b0d725b7..f86f3eaf 160000 --- a/spec/data +++ b/spec/data @@ -1 +1 @@ -Subproject commit b0d725b71784a45db611c325739320b6c192b7e5 +Subproject commit f86f3eaf540f0babeb3d4f1a458d764856a2170b diff --git a/spec/v1/input/local_response_spec.rb b/spec/v1/input/local_response_v1_spec.rb similarity index 100% rename from spec/v1/input/local_response_spec.rb rename to spec/v1/input/local_response_v1_spec.rb diff --git a/spec/v2/client_v2_integration.rb b/spec/v2/client_v2_integration.rb index 80b2810f..53af04f6 100644 --- a/spec/v2/client_v2_integration.rb +++ b/spec/v2/client_v2_integration.rb @@ -24,7 +24,8 @@ polygon: false, confidence: false, file_alias: 'ruby-integration-test', - polling_options: polling + polling_options: polling, + text_context: 'this is a test' ) response = client.enqueue_and_get_inference(input, inference_params) @@ -50,6 +51,7 @@ expect(active_options.polygon).to eq(false) expect(active_options.confidence).to eq(false) expect(active_options.rag).to eq(false) + expect(active_options.text_context).to eq(true) result = response.inference.result expect(result).not_to be_nil @@ -94,6 +96,7 @@ expect(active_options.polygon).to eq(false) expect(active_options.confidence).to eq(false) expect(active_options.rag).to eq(false) + expect(active_options.text_context).to eq(false) result = response.inference.result expect(result).not_to be_nil diff --git a/spec/v2/input/local_response_v2_spec.rb b/spec/v2/input/local_response_v2_spec.rb new file mode 100644 index 00000000..59fa0f3c --- /dev/null +++ b/spec/v2/input/local_response_v2_spec.rb @@ -0,0 +1,60 @@ +# frozen_string_literal: true + +require 'mindee/input/local_response' +require_relative '../../data' + + +def assert_local_response(local_response) + dummy_secret_key = 'ogNjY44MhvKPGTtVsI8zG82JqWQa68woYQH' + signature = 'b82a515c832fd2c4f4ce3a7e6f53c12e8d10e19223f6cf0e3a9809a7a3da26be' + expect(local_response.file).to_not be(nil) + expect(local_response.valid_hmac_signature?( + dummy_secret_key, 'invalid signature' + )).to be(false) + expect(local_response.get_hmac_signature(dummy_secret_key)).to eq(signature) +end + +describe Mindee::Input::LocalResponse do + let(:file_path) { File.join(V2_DATA_DIR, 'inference', 'standard_field_types.json') } + context 'A V2 local response' do + it 'should load from a path' do + response = Mindee::Input::LocalResponse.new(file_path) + assert_local_response(response) + end + + it 'should load from a string' do + str_file = File.read(file_path) + response = Mindee::Input::LocalResponse.new(str_file) + assert_local_response(response) + end + + it 'should load from a StringIO' do + strio_file = StringIO.new(File.read(file_path)) + response = Mindee::Input::LocalResponse.new(strio_file) + assert_local_response(response) + end + + it 'should load from a file-like object' do + str_file = File.read(file_path) + Tempfile.open do |tempfile| + tempfile.write(str_file) + tempfile.rewind + response = Mindee::Input::LocalResponse.new(tempfile) + assert_local_response(response) + end + end + + it 'should trigger an error when something invalid is passed' do + expect do + Mindee::Input::LocalResponse.new(123) + end.to raise_error Mindee::Errors::MindeeInputError + end + + it 'should trigger an error when the payload is not hashable' do + local_response = Mindee::Input::LocalResponse.new('Your mother was a hamster.') + expect do + local_response.as_hash + end.to raise_error Mindee::Errors::MindeeInputError + end + end +end diff --git a/spec/v2/parsing/inference_spec.rb b/spec/v2/parsing/inference_spec.rb index 3285b74b..78fd5f4e 100644 --- a/spec/v2/parsing/inference_spec.rb +++ b/spec/v2/parsing/inference_spec.rb @@ -15,6 +15,7 @@ let(:complete_path) { File.join(findoc_path, 'complete.json') } let(:rag_matched_path) { File.join(inference_path, 'rag_matched.json') } let(:rag_not_matched_path) { File.join(inference_path, 'rag_not_matched.json') } + let(:text_context_path) { File.join(inference_path, 'text_context_enabled.json') } def load_v2_inference(resource_path) local_response = Mindee::Input::LocalResponse.new(resource_path) @@ -81,6 +82,7 @@ def load_v2_inference(resource_path) expect(active_options.raw_text).to eq(false) expect(active_options.polygon).to eq(false) expect(active_options.confidence).to eq(false) + expect(active_options.text_context).to eq(false) expect(active_options.rag).to eq(false) fields = inference.result.fields @@ -363,4 +365,12 @@ def load_standard_fields expect(response.inference.result.rag.retrieved_document_id).to be_nil end end + + describe 'text context' do + it 'when enabled' do + response = load_v2_inference(text_context_path) + expect(response.inference).not_to be_nil + expect(response.inference.active_options.text_context).to be_truthy + end + end end From a4da614b4b0ebb826073e9b0a7e302858149990a Mon Sep 17 00:00:00 2001 From: sebastianMindee <130448732+sebastianMindee@users.noreply.github.com> Date: Tue, 2 Dec 2025 11:42:10 +0100 Subject: [PATCH 2/3] fix lint --- spec/v2/input/local_response_v2_spec.rb | 1 - 1 file changed, 1 deletion(-) diff --git a/spec/v2/input/local_response_v2_spec.rb b/spec/v2/input/local_response_v2_spec.rb index 59fa0f3c..b72af8a1 100644 --- a/spec/v2/input/local_response_v2_spec.rb +++ b/spec/v2/input/local_response_v2_spec.rb @@ -3,7 +3,6 @@ require 'mindee/input/local_response' require_relative '../../data' - def assert_local_response(local_response) dummy_secret_key = 'ogNjY44MhvKPGTtVsI8zG82JqWQa68woYQH' signature = 'b82a515c832fd2c4f4ce3a7e6f53c12e8d10e19223f6cf0e3a9809a7a3da26be' From 090f852bc1e7e884c995715c1b9c6882c79ce300 Mon Sep 17 00:00:00 2001 From: sebastianMindee <130448732+sebastianMindee@users.noreply.github.com> Date: Tue, 2 Dec 2025 11:53:08 +0100 Subject: [PATCH 3/3] add test --- spec/v2/input/local_response_v2_spec.rb | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/spec/v2/input/local_response_v2_spec.rb b/spec/v2/input/local_response_v2_spec.rb index b72af8a1..a10fa1bc 100644 --- a/spec/v2/input/local_response_v2_spec.rb +++ b/spec/v2/input/local_response_v2_spec.rb @@ -11,6 +11,10 @@ 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) + expect(inference_response).not_to be_nil + expect(inference_response.inference).not_to be_nil end describe Mindee::Input::LocalResponse do