From 8cafa3a6094387e000dbfe9ad70fe94c92cd5e8f Mon Sep 17 00:00:00 2001 From: karthikreddy-02 Date: Wed, 1 Apr 2026 15:39:00 -0400 Subject: [PATCH 1/2] Add temperature parameter to process_image Adds an optional `temperature:` keyword argument (default 0.0) to `Client#process_image`, forwarded to the Bedrock converse API via `inference_config`. Includes tests for default and custom temperature values. Co-Authored-By: Claude Sonnet 4.6 --- lib/alt_text/client.rb | 5 +++-- spec/alt_text/client_spec.rb | 30 ++++++++++++++++++++++++++++-- 2 files changed, 31 insertions(+), 4 deletions(-) diff --git a/lib/alt_text/client.rb b/lib/alt_text/client.rb index 9c8ab2c..e2fd33e 100644 --- a/lib/alt_text/client.rb +++ b/lib/alt_text/client.rb @@ -14,7 +14,7 @@ def initialize(access_key:, secret_key:, region:) ) end - def process_image(image_path, prompt:, model_id:) + def process_image(image_path, prompt:, model_id:, temperature: 0.0) model_id = AltText::LLMRegistry.resolve(model_id) image_format = image_format_for(image_path) tmp_image = resize_if_needed(image_path) @@ -52,7 +52,8 @@ def process_image(image_path, prompt:, model_id:) # - Amazon Nova Lite (supports text and images) # - Anthropic Claude / Opus (supports text and images) response = @client.converse(model_id: model_id, - messages: messages) + messages: messages, + inference_config: { temperature: temperature }) response.output.message.content.first.text end diff --git a/spec/alt_text/client_spec.rb b/spec/alt_text/client_spec.rb index 677df07..b5b8683 100644 --- a/spec/alt_text/client_spec.rb +++ b/spec/alt_text/client_spec.rb @@ -57,7 +57,8 @@ } ] } - ] + ], + inference_config: { temperature: 0.0 } ).and_return(mock_response) end @@ -93,7 +94,8 @@ before do allow(mocked_bedrock_client).to receive(:converse).with( model_id: AltText::LLMRegistry.resolve(model_id), - messages: anything + messages: anything, + inference_config: anything ).and_raise('error') end @@ -103,6 +105,30 @@ }.to raise_error('error') end end + + context 'temperature configuration' do + it 'passes the temperature to the converse call' do + allow(mocked_bedrock_client).to receive(:converse).with( + model_id: AltText::LLMRegistry.resolve(model_id), + messages: anything, + inference_config: { temperature: 0.7 } + ).and_return(mock_response) + + result = client.process_image(image_path, prompt: prompt, model_id: model_id, temperature: 0.7) + expect(result).to eq('alt text') + end + + it 'defaults temperature to 0.0' do + allow(mocked_bedrock_client).to receive(:converse).with( + model_id: AltText::LLMRegistry.resolve(model_id), + messages: anything, + inference_config: { temperature: 0.0 } + ).and_return(mock_response) + + result = client.process_image(image_path, prompt: prompt, model_id: model_id) + expect(result).to eq('alt text') + end + end end describe '#resize_if_needed' do From f097957ec58237cc78cec703b535cf51de478e0d Mon Sep 17 00:00:00 2001 From: karthikreddy-02 Date: Wed, 1 Apr 2026 18:23:11 -0400 Subject: [PATCH 2/2] Update Gemfile.lock to resolve niftany dependency, edit client_spec.rb to comply with rubocop --- Gemfile.lock | 93 ++++++++++++++++++------------------ spec/alt_text/client_spec.rb | 2 +- 2 files changed, 48 insertions(+), 47 deletions(-) diff --git a/Gemfile.lock b/Gemfile.lock index a82c2bf..7575c6d 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -10,20 +10,20 @@ PATH GEM remote: https://rubygems.org/ specs: - actionview (8.0.2.1) - activesupport (= 8.0.2.1) + actionview (8.1.3) + activesupport (= 8.1.3) builder (~> 3.1) erubi (~> 1.11) rails-dom-testing (~> 2.2) rails-html-sanitizer (~> 1.6) - activesupport (8.0.2.1) + activesupport (8.1.3) base64 - benchmark (>= 0.3) bigdecimal concurrent-ruby (~> 1.0, >= 1.3.1) connection_pool (>= 2.2.5) drb i18n (>= 1.6, < 2) + json logger (>= 1.4.2) minitest (>= 5.1) securerandom (>= 0.3) @@ -31,11 +31,11 @@ GEM uri (>= 0.13.1) ast (2.4.3) aws-eventstream (1.4.0) - aws-partitions (1.1160.0) + aws-partitions (1.1233.0) aws-sdk-bedrockruntime (1.55.0) aws-sdk-core (~> 3, >= 3.228.0) aws-sigv4 (~> 1.5) - aws-sdk-core (3.232.0) + aws-sdk-core (3.244.0) aws-eventstream (~> 1, >= 1.3.0) aws-partitions (~> 1, >= 1.992.0) aws-sigv4 (~> 1.9) @@ -46,20 +46,19 @@ GEM aws-sigv4 (1.12.1) aws-eventstream (~> 1, >= 1.0.2) base64 (0.3.0) - benchmark (0.4.1) - better_html (2.1.1) - actionview (>= 6.0) - activesupport (>= 6.0) + better_html (2.2.0) + actionview (>= 7.0) + activesupport (>= 7.0) ast (~> 2.0) erubi (~> 1.4) parser (>= 2.4) smart_properties - bigdecimal (3.2.2) + bigdecimal (4.1.0) builder (3.3.0) coderay (1.1.3) colorize (1.1.0) - concurrent-ruby (1.3.5) - connection_pool (2.5.3) + concurrent-ruby (1.3.6) + connection_pool (3.0.2) crass (1.0.6) diff-lcs (1.6.2) dotenv (3.1.8) @@ -72,17 +71,17 @@ GEM rubocop (>= 1) smart_properties erubi (1.13.1) - ffi (1.17.2) - ffi (1.17.2-arm64-darwin) - i18n (1.14.7) + ffi (1.17.4) + ffi (1.17.4-arm64-darwin) + i18n (1.14.8) concurrent-ruby (~> 1.0) io-console (0.8.2) jmespath (1.6.2) - json (2.13.2) + json (2.19.3) language_server-protocol (3.17.0.5) lint_roller (1.1.0) logger (1.7.0) - loofah (2.24.1) + loofah (2.25.1) crass (~> 1.0.2) nokogiri (>= 1.12.0) marcel (1.1.0) @@ -90,7 +89,9 @@ GEM mini_magick (5.3.1) logger mini_portile2 (2.8.9) - minitest (5.25.5) + minitest (6.0.3) + drb (~> 2.0) + prism (~> 1.5) niftany (0.12.1) colorize (~> 1.1.0) erb_lint (~> 0.9.0) @@ -102,50 +103,50 @@ GEM rubocop-rspec (~> 3.5) rubocop-rspec_rails (~> 2.30) scss_lint (~> 0.60) - nokogiri (1.18.9) + nokogiri (1.19.2) mini_portile2 (~> 2.8.2) racc (~> 1.4) - nokogiri (1.18.9-arm64-darwin) + nokogiri (1.19.2-arm64-darwin) racc (~> 1.4) parallel (1.27.0) - parser (3.3.9.0) + parser (3.3.11.1) ast (~> 2.4.1) racc - prism (1.4.0) + prism (1.9.0) pry (0.16.0) coderay (~> 1.1) method_source (~> 1.0) reline (>= 0.6.0) racc (1.8.1) - rack (3.2.3) + rack (3.2.6) rails-dom-testing (2.3.0) activesupport (>= 5.0.0) minitest nokogiri (>= 1.6) - rails-html-sanitizer (1.6.2) - loofah (~> 2.21) + rails-html-sanitizer (1.7.0) + loofah (~> 2.25) nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0) rainbow (3.1.1) rb-fsevent (0.11.2) rb-inotify (0.11.1) ffi (~> 1.0) - regexp_parser (2.11.2) + regexp_parser (2.11.3) reline (0.6.3) io-console (~> 0.5) - rspec (3.13.1) + rspec (3.13.2) rspec-core (~> 3.13.0) rspec-expectations (~> 3.13.0) rspec-mocks (~> 3.13.0) - rspec-core (3.13.5) + rspec-core (3.13.6) rspec-support (~> 3.13.0) rspec-expectations (3.13.5) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.13.0) - rspec-mocks (3.13.5) + rspec-mocks (3.13.8) diff-lcs (>= 1.2.0, < 2.0) rspec-support (~> 3.13.0) - rspec-support (3.13.5) - rubocop (1.79.2) + rspec-support (3.13.7) + rubocop (1.86.0) json (~> 2.3) language_server-protocol (~> 3.17.0.2) lint_roller (~> 1.1.0) @@ -153,32 +154,32 @@ GEM parser (>= 3.3.0.2) rainbow (>= 2.2.2, < 4.0) regexp_parser (>= 2.9.3, < 3.0) - rubocop-ast (>= 1.46.0, < 2.0) + rubocop-ast (>= 1.49.0, < 2.0) ruby-progressbar (~> 1.7) unicode-display_width (>= 2.4.0, < 4.0) - rubocop-ast (1.46.0) + rubocop-ast (1.49.1) parser (>= 3.3.7.2) - prism (~> 1.4) + prism (~> 1.7) rubocop-capybara (2.22.1) lint_roller (~> 1.1) rubocop (~> 1.72, >= 1.72.1) - rubocop-factory_bot (2.27.1) + rubocop-factory_bot (2.28.0) lint_roller (~> 1.1) rubocop (~> 1.72, >= 1.72.1) - rubocop-performance (1.25.0) + rubocop-performance (1.26.1) lint_roller (~> 1.1) rubocop (>= 1.75.0, < 2.0) - rubocop-ast (>= 1.38.0, < 2.0) - rubocop-rails (2.33.3) + rubocop-ast (>= 1.47.1, < 2.0) + rubocop-rails (2.34.3) activesupport (>= 4.2.0) lint_roller (~> 1.1) rack (>= 1.1) rubocop (>= 1.75.0, < 2.0) rubocop-ast (>= 1.44.0, < 2.0) - rubocop-rspec (3.6.0) + rubocop-rspec (3.9.0) lint_roller (~> 1.1) - rubocop (~> 1.72, >= 1.72.1) - rubocop-rspec_rails (2.31.0) + rubocop (~> 1.81) + rubocop-rspec_rails (2.32.0) lint_roller (~> 1.1) rubocop (~> 1.72, >= 1.72.1) rubocop-rspec (~> 3.5) @@ -194,10 +195,10 @@ GEM smart_properties (1.17.0) tzinfo (2.0.6) concurrent-ruby (~> 1.0) - unicode-display_width (3.1.5) - unicode-emoji (~> 4.0, >= 4.0.4) - unicode-emoji (4.0.4) - uri (1.0.3) + unicode-display_width (3.2.0) + unicode-emoji (~> 4.1) + unicode-emoji (4.2.0) + uri (1.1.1) PLATFORMS arm64-darwin-24 diff --git a/spec/alt_text/client_spec.rb b/spec/alt_text/client_spec.rb index b5b8683..38f4bbe 100644 --- a/spec/alt_text/client_spec.rb +++ b/spec/alt_text/client_spec.rb @@ -106,7 +106,7 @@ end end - context 'temperature configuration' do + context 'when temperature configuration' do it 'passes the temperature to the converse call' do allow(mocked_bedrock_client).to receive(:converse).with( model_id: AltText::LLMRegistry.resolve(model_id),