Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
93 changes: 47 additions & 46 deletions Gemfile.lock
Original file line number Diff line number Diff line change
Expand Up @@ -10,32 +10,32 @@ 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)
tzinfo (~> 2.0, >= 2.0.5)
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)
Expand All @@ -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)
Expand All @@ -72,25 +71,27 @@ 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)
method_source (1.1.0)
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)
Expand All @@ -102,83 +103,83 @@ 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)
parallel (~> 1.10)
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)
Expand All @@ -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
Expand Down
5 changes: 3 additions & 2 deletions lib/alt_text/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
30 changes: 28 additions & 2 deletions spec/alt_text/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,8 @@
}
]
}
]
],
inference_config: { temperature: 0.0 }
).and_return(mock_response)
end

Expand Down Expand Up @@ -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

Expand All @@ -103,6 +105,30 @@
}.to raise_error('error')
end
end

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),
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
Expand Down
Loading