ruby-amazon-bedrock 0.2.0 → 0.2.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (50) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +11 -0
  3. data/Gemfile +0 -1
  4. data/Gemfile.lock +1 -9
  5. data/README.md +165 -26
  6. data/lib/amazon_bedrock/version.rb +1 -1
  7. data/lib/amazon_bedrock.rb +33 -0
  8. data/lib/bedrock_runtime/client.rb +10 -9
  9. data/lib/bedrock_runtime/payload_builders/ai_21_labs/base.rb +20 -8
  10. data/lib/bedrock_runtime/payload_builders/ai_21_labs/j2_mid_v1.rb +1 -1
  11. data/lib/bedrock_runtime/payload_builders/ai_21_labs/j2_ultra_v1.rb +1 -1
  12. data/lib/bedrock_runtime/payload_builders/amazon/base.rb +11 -7
  13. data/lib/bedrock_runtime/payload_builders/amazon/titan_image_generator_v1.rb +1 -1
  14. data/lib/bedrock_runtime/payload_builders/amazon/titan_text_lite_v1.rb +7 -15
  15. data/lib/bedrock_runtime/payload_builders/anthropic/base.rb +16 -8
  16. data/lib/bedrock_runtime/payload_builders/base.rb +9 -2
  17. data/lib/bedrock_runtime/payload_builders/cohere/command_base.rb +25 -4
  18. data/lib/bedrock_runtime/payload_builders/cohere/embed_base.rb +10 -2
  19. data/lib/bedrock_runtime/payload_builders/meta/base.rb +12 -4
  20. data/lib/bedrock_runtime/payload_builders/stability_ai/base.rb +12 -4
  21. data/lib/bedrock_runtime/payload_factory.rb +5 -5
  22. data/lib/bedrock_runtime/response_builders/image.rb +4 -0
  23. data/spec/bedrock_runtime/client_spec.rb +2 -2
  24. data/spec/bedrock_runtime/payload_builders/ai_21_labs/base_spec.rb +10 -12
  25. data/spec/bedrock_runtime/payload_builders/ai_21_labs/j2_mid_v1_spec.rb +10 -13
  26. data/spec/bedrock_runtime/payload_builders/ai_21_labs/j2_ultra_v1_spec.rb +11 -14
  27. data/spec/bedrock_runtime/payload_builders/amazon/base_spec.rb +7 -9
  28. data/spec/bedrock_runtime/payload_builders/amazon/titan_text_express_v1_spec.rb +7 -10
  29. data/spec/bedrock_runtime/payload_builders/amazon/titan_text_lite_v1_spec.rb +7 -10
  30. data/spec/bedrock_runtime/payload_builders/anthropic/base_spec.rb +8 -10
  31. data/spec/bedrock_runtime/payload_builders/anthropic/claude_instant_v1_spec.rb +8 -11
  32. data/spec/bedrock_runtime/payload_builders/anthropic/claude_v1_spec.rb +8 -11
  33. data/spec/bedrock_runtime/payload_builders/anthropic/claude_v2_spec.rb +8 -11
  34. data/spec/bedrock_runtime/payload_builders/base_spec.rb +1 -1
  35. data/spec/bedrock_runtime/payload_builders/cohere/command_base_spec.rb +16 -11
  36. data/spec/bedrock_runtime/payload_builders/cohere/command_light_text_v14_spec.rb +16 -12
  37. data/spec/bedrock_runtime/payload_builders/cohere/command_text_v14_spec.rb +16 -12
  38. data/spec/bedrock_runtime/payload_builders/cohere/embed_base_spec.rb +8 -10
  39. data/spec/bedrock_runtime/payload_builders/cohere/embed_english_v3_spec.rb +9 -11
  40. data/spec/bedrock_runtime/payload_builders/cohere/embed_multilingual_v3_spec.rb +9 -11
  41. data/spec/bedrock_runtime/payload_builders/meta/base_spec.rb +8 -10
  42. data/spec/bedrock_runtime/payload_builders/meta/llama213b_chat_v1_spec.rb +8 -11
  43. data/spec/bedrock_runtime/payload_builders/meta/llama270b_chat_v1_spec.rb +8 -11
  44. data/spec/bedrock_runtime/payload_builders/stability_ai/base_spec.rb +8 -10
  45. data/spec/bedrock_runtime/payload_builders/stability_ai/stable_diffusion_xl_v0_spec.rb +8 -11
  46. data/spec/bedrock_runtime/payload_builders/stability_ai/stable_diffusion_xl_v1_spec.rb +8 -11
  47. data/spec/bedrock_runtime/payload_factory_spec.rb +3 -3
  48. data/spec/spec_helper.rb +1 -2
  49. data/spec/support/helpers.rb +169 -0
  50. metadata +3 -2
@@ -33,14 +33,12 @@ module RubyAmazonBedrock
33
33
  content_type: 'application/json',
34
34
  accept: '*/*',
35
35
  body: {
36
- prompt: "\n\nHuman: #{@input}\n\nAssistant:",
37
- max_tokens_to_sample: 300,
38
- temperature: 0.5,
39
- top_k: 250,
40
- top_p: 1,
41
- stop_sequences: [
42
- '\n\nHuman'
43
- ],
36
+ prompt: "\n\nHuman: #{@prompt}\n\nAssistant:",
37
+ max_tokens_to_sample: parameters[:max_tokens_to_sample],
38
+ temperature: parameters[:temperature],
39
+ top_k: parameters[:top_k],
40
+ top_p: parameters[:top_p],
41
+ stop_sequences: parameters[:stop_sequences],
44
42
  anthropic_version: 'bedrock-2023-05-31'
45
43
  }.to_json
46
44
  }
@@ -49,6 +47,16 @@ module RubyAmazonBedrock
49
47
  def model_id
50
48
  # noop
51
49
  end
50
+
51
+ def parameters
52
+ {
53
+ max_tokens_to_sample: @options[:max_tokens] || 200,
54
+ temperature: @options[:temperature] || 0.5,
55
+ top_k: @options[:top_k] || 250,
56
+ top_p: @options[:top_p] || 1,
57
+ stop_sequences: @options[:stop_sequences] || ['\n\nHuman']
58
+ }
59
+ end
52
60
  end
53
61
  end
54
62
  end
@@ -10,8 +10,8 @@ module RubyAmazonBedrock
10
10
  # @param input [String] The input string for what needs to be generated.
11
11
  # @param options [Hash] optional parameters to customize payload building.
12
12
  # @option options [Any] :key Custom option key-value pairs.
13
- def initialize(input, options = {})
14
- @input = input
13
+ def initialize(prompt, options = {})
14
+ @prompt = prompt
15
15
  @options = options
16
16
  end
17
17
 
@@ -29,6 +29,13 @@ module RubyAmazonBedrock
29
29
  raise NotImplementedError
30
30
  end
31
31
 
32
+ # Abstract method to set the model parameters to be sent in the request.
33
+ # @raise [NotImplementedError] if the subclass does not implement this method.
34
+ # @return [Hash] the Amazon Bedrock model configuration parameters.
35
+ def parameters
36
+ raise NotImplementedError
37
+ end
38
+
32
39
  # Abstract method to retrieve the model type.
33
40
  # @return [Symbol] the model result type: :text (default) or :image.
34
41
  def type
@@ -29,10 +29,16 @@ module RubyAmazonBedrock
29
29
  content_type: 'application/json',
30
30
  accept: '*/*',
31
31
  body: {
32
- prompt: "#{@input}:",
33
- max_tokens: 100,
34
- temperature: 0.8
35
- # return_likelihood: 'GENERATION' NOTE: This was since it was giving an error
32
+ prompt: "#{@prompt}:",
33
+ temperature: parameters[:temperature],
34
+ p: parameters[:p],
35
+ k: parameters[:k],
36
+ max_tokens: parameters[:max_tokens],
37
+ num_generations: parameters[:num_generations],
38
+ return_likelihoods: parameters[:return_likelihoods],
39
+ stop_sequences: parameters[:stop_sequences],
40
+ stream: parameters[:stream],
41
+ truncate: parameters[:truncate]
36
42
  }.to_json
37
43
  }
38
44
  end
@@ -40,6 +46,21 @@ module RubyAmazonBedrock
40
46
  def model_id
41
47
  # noop
42
48
  end
49
+
50
+ def parameters # rubocop:disable Metrics/CyclomaticComplexity,Metrics/PerceivedComplexity
51
+ {
52
+ temperature: @options[:temperature] || 0.9,
53
+ p: @options[:top_p] || 0.75,
54
+ k: @options[:top_k] || 0,
55
+ max_tokens: @options[:max_tokens] || 20,
56
+ num_generations: @options[:num_generations] || 1,
57
+ return_likelihoods: @options[:return_likelihoods] || 'GENERATION',
58
+ stop_sequences: @options[:stop_sequences] || [],
59
+ stream: @options[:stream] || false,
60
+ # logit_bias: @options[:logit_bias] || {},
61
+ truncate: @options[:truncate] || 'NONE'
62
+ }
63
+ end
43
64
  end
44
65
  end
45
66
  end
@@ -26,8 +26,9 @@ module RubyAmazonBedrock
26
26
  content_type: 'application/json',
27
27
  accept: '*/*',
28
28
  body: {
29
- texts: [@input],
30
- input_type: 'search_document'
29
+ texts: [@prompt],
30
+ input_type: parameters[:input_type],
31
+ truncate: parameters[:truncate]
31
32
  }.to_json
32
33
  }
33
34
  end
@@ -35,6 +36,13 @@ module RubyAmazonBedrock
35
36
  def model_id
36
37
  # noop
37
38
  end
39
+
40
+ def parameters
41
+ {
42
+ input_type: @options[:input_type] || 'search_document',
43
+ truncate: @options[:truncate] || 'NONE'
44
+ }
45
+ end
38
46
  end
39
47
  end
40
48
  end
@@ -28,10 +28,10 @@ module RubyAmazonBedrock
28
28
  content_type: 'application/json',
29
29
  accept: '*/*',
30
30
  body: {
31
- prompt: @input,
32
- max_gen_len: 512,
33
- temperature: 0.2,
34
- top_p: 0.9
31
+ prompt: @prompt,
32
+ max_gen_len: parameters[:max_gen_len],
33
+ temperature: parameters[:temperature],
34
+ top_p: parameters[:top_p]
35
35
  }.to_json
36
36
  }
37
37
  end
@@ -39,6 +39,14 @@ module RubyAmazonBedrock
39
39
  def model_id
40
40
  # noop
41
41
  end
42
+
43
+ def parameters
44
+ {
45
+ max_gen_len: @options[:max_tokens] || 512,
46
+ temperature: @options[:temperature] || 0.5,
47
+ top_p: @options[:top_p] || 0.9
48
+ }
49
+ end
42
50
  end
43
51
  end
44
52
  end
@@ -30,11 +30,11 @@ module RubyAmazonBedrock
30
30
  accept: '*/*',
31
31
  body: {
32
32
  text_prompts: [
33
- { text: @input }
33
+ { text: @prompt }
34
34
  ],
35
- cfg_scale: 10,
36
- seed: 0,
37
- steps: 50
35
+ cfg_scale: parameters[:cfg_scale],
36
+ seed: parameters[:seed],
37
+ steps: parameters[:steps]
38
38
  }.to_json
39
39
  }
40
40
  end
@@ -43,6 +43,14 @@ module RubyAmazonBedrock
43
43
  # noop
44
44
  end
45
45
 
46
+ def parameters
47
+ {
48
+ cfg_scale: @options[:cfg_scale] || 10,
49
+ seed: @options[:seed] || 0,
50
+ steps: @options[:steps] || 30
51
+ }
52
+ end
53
+
46
54
  def type
47
55
  :image
48
56
  end
@@ -29,7 +29,7 @@ module RubyAmazonBedrock
29
29
  class PayloadFactory
30
30
  def initialize(model_id, input, options = {})
31
31
  @model_id = model_id
32
- @input = input
32
+ @prompt = input
33
33
  @options = options
34
34
  end
35
35
 
@@ -42,7 +42,7 @@ module RubyAmazonBedrock
42
42
 
43
43
  raise UnknownModelError, "Unknown modelId: #{@model_id}" unless builder_class
44
44
 
45
- builder_class.new(@input, @options)
45
+ builder_class.new(@prompt, @options)
46
46
  end
47
47
 
48
48
  # Defines a mapping from model identifiers to their respective builder classes.
@@ -50,13 +50,13 @@ module RubyAmazonBedrock
50
50
  # @return [Hash] The mapping of model identifiers to builder classes.
51
51
  def models_to_builders
52
52
  {
53
- 'ai21labs.j2-mid-v1' => PayloadBuilders::Ai21Labs::J2MidV1,
54
- 'ai21labs.j2-ultra-v1' => PayloadBuilders::Ai21Labs::J2UltraV1,
53
+ 'ai21.j2-mid-v1' => PayloadBuilders::Ai21Labs::J2MidV1,
54
+ 'ai21.j2-ultra-v1' => PayloadBuilders::Ai21Labs::J2UltraV1,
55
55
  'amazon.titan-image-generator-v1' => PayloadBuilders::Amazon::TitanImageGeneratorV1,
56
56
  'amazon.titan-text-lite-v1' => PayloadBuilders::Amazon::TitanTextLiteV1,
57
57
  'amazon.titan-text-express-v1' => PayloadBuilders::Amazon::TitanTextExpressV1,
58
- 'anthropic.claude-v1' => PayloadBuilders::Anthropic::ClaudeV1,
59
58
  'anthropic.claude-instant-v1' => PayloadBuilders::Anthropic::ClaudeInstantV1,
59
+ 'anthropic.claude-v1' => PayloadBuilders::Anthropic::ClaudeV1,
60
60
  'anthropic.claude-v2' => PayloadBuilders::Anthropic::ClaudeV2,
61
61
  'cohere.command-light-text-v14' => PayloadBuilders::Cohere::CommandLightTextV14,
62
62
  'cohere.command-text-v14' => PayloadBuilders::Cohere::CommandTextV14,
@@ -41,6 +41,10 @@ module RubyAmazonBedrock
41
41
  error: e
42
42
  }
43
43
  end
44
+
45
+ def model_id
46
+ # noop
47
+ end
44
48
  end
45
49
  end
46
50
  end
@@ -33,7 +33,7 @@ RSpec.describe RubyAmazonBedrock::Client do
33
33
  models.each do |model|
34
34
  it "invokes #{model} model with the given payload" do
35
35
  VCR.use_cassette("models/#{model}") do
36
- response = client.invoke_model(id: model, input: 'Give me a short list of steps for creating a Ruby gem', options: {})
36
+ response = client.invoke_model(id: model, prompt: 'Give me a short list of steps for creating a Ruby gem', options: {})
37
37
  expect(response).to be_a(Hash)
38
38
  end
39
39
  end
@@ -42,7 +42,7 @@ RSpec.describe RubyAmazonBedrock::Client do
42
42
  context 'when the model is not found' do
43
43
  it 'raises an UnkownModelError' do
44
44
  VCR.use_cassette('models/not_found') do
45
- expect { client.invoke_model(id: 'unknown-model', input: 'Hello World', options: {}) }.to raise_error(RubyAmazonBedrock::UnknownModelError)
45
+ expect { client.invoke_model(id: 'unknown-model', prompt: 'Hello World', options: {}) }.to raise_error(RubyAmazonBedrock::UnknownModelError)
46
46
  end
47
47
  end
48
48
  end
@@ -4,15 +4,15 @@ require 'spec_helper'
4
4
  require 'bedrock_runtime/payload_builders/ai_21_labs/base'
5
5
 
6
6
  RSpec.describe RubyAmazonBedrock::PayloadBuilders::Ai21Labs::Base do
7
- let(:input) { 'example_input' }
8
- let(:options) { { key: 'value' } }
7
+ let(:prompt) { 'example_prompt' }
8
+ let(:options) { {} }
9
9
  let(:body) do
10
10
  {
11
- prompt: input,
12
- maxTokens: 200,
11
+ prompt: prompt,
12
+ maxTokenCount: 200,
13
13
  temperature: 0,
14
- topP: 250,
15
- stop_sequences: [],
14
+ topP: 1,
15
+ stopSequences: [],
16
16
  countPenalty: { scale: 0 },
17
17
  presencePenalty: { scale: 0 },
18
18
  frequencyPenalty: { scale: 0 }
@@ -20,13 +20,11 @@ RSpec.describe RubyAmazonBedrock::PayloadBuilders::Ai21Labs::Base do
20
20
  end
21
21
 
22
22
  describe '#build' do
23
- it 'returns a hash with the expected structure' do
24
- payload_builder = described_class.new(input, options)
25
- payload = payload_builder.build
23
+ it_should_behave_like 'a payload builder'
26
24
 
27
- expect(payload[:content_type]).to eq('application/json')
28
- expect(payload[:accept]).to eq('*/*')
29
- expect(payload[:body]).to eq(body)
25
+ context 'with custom parameters' do
26
+ include_context 'a121 labs parameters'
27
+ it_should_behave_like 'a payload builder'
30
28
  end
31
29
  end
32
30
  end
@@ -4,15 +4,15 @@ require 'spec_helper'
4
4
  require 'bedrock_runtime/payload_builders/ai_21_labs/j2_mid_v1'
5
5
 
6
6
  RSpec.describe RubyAmazonBedrock::PayloadBuilders::Ai21Labs::J2MidV1 do
7
- let(:input) { 'example_input' }
8
- let(:options) { { key: 'value' } }
7
+ let(:prompt) { 'example_prompt' }
8
+ let(:options) { {} }
9
9
  let(:body) do
10
10
  {
11
- prompt: input,
12
- maxTokens: 200,
11
+ prompt: prompt,
12
+ maxTokenCount: 200,
13
13
  temperature: 0,
14
- topP: 250,
15
- stop_sequences: [],
14
+ topP: 1,
15
+ stopSequences: [],
16
16
  countPenalty: { scale: 0 },
17
17
  presencePenalty: { scale: 0 },
18
18
  frequencyPenalty: { scale: 0 }
@@ -20,14 +20,11 @@ RSpec.describe RubyAmazonBedrock::PayloadBuilders::Ai21Labs::J2MidV1 do
20
20
  end
21
21
 
22
22
  describe '#build' do
23
- it 'returns a hash with the expected structure' do
24
- payload_builder = described_class.new(input, options)
25
- payload = payload_builder.build
23
+ it_behaves_like 'a payload builder'
26
24
 
27
- expect(payload[:model_id]).to eq('ai21labs.j2-mid-v1')
28
- expect(payload[:content_type]).to eq('application/json')
29
- expect(payload[:accept]).to eq('*/*')
30
- expect(payload[:body]).to eq(body)
25
+ context 'with custom parameters' do
26
+ include_context 'a121 labs parameters'
27
+ it_should_behave_like 'a payload builder'
31
28
  end
32
29
  end
33
30
  end
@@ -4,15 +4,15 @@ require 'spec_helper'
4
4
  require 'bedrock_runtime/payload_builders/ai_21_labs/j2_ultra_v1'
5
5
 
6
6
  RSpec.describe RubyAmazonBedrock::PayloadBuilders::Ai21Labs::J2UltraV1 do
7
- let(:input) { 'example_input' }
8
- let(:options) { { key: 'value' } }
7
+ let(:prompt) { 'example_prompt' }
8
+ let(:options) { {} }
9
9
  let(:body) do
10
10
  {
11
- prompt: input,
12
- maxTokens: 200,
11
+ prompt: prompt,
12
+ maxTokenCount: 200,
13
13
  temperature: 0,
14
- topP: 250,
15
- stop_sequences: [],
14
+ topP: 1,
15
+ stopSequences: [],
16
16
  countPenalty: { scale: 0 },
17
17
  presencePenalty: { scale: 0 },
18
18
  frequencyPenalty: { scale: 0 }
@@ -20,14 +20,11 @@ RSpec.describe RubyAmazonBedrock::PayloadBuilders::Ai21Labs::J2UltraV1 do
20
20
  end
21
21
 
22
22
  describe '#build' do
23
- it 'returns a hash with the expected structure' do
24
- payload_builder = described_class.new(input, options)
25
- payload = payload_builder.build
23
+ it_should_behave_like 'a payload builder'
24
+ end
26
25
 
27
- expect(payload[:model_id]).to eq('ai21labs.j2-ultra-v1')
28
- expect(payload[:content_type]).to eq('application/json')
29
- expect(payload[:accept]).to eq('*/*')
30
- expect(payload[:body]).to eq(body)
31
- end
26
+ context 'with custom parameters' do
27
+ include_context 'a121 labs parameters'
28
+ it_should_behave_like 'a payload builder'
32
29
  end
33
30
  end
@@ -4,11 +4,11 @@ require 'spec_helper'
4
4
  require 'bedrock_runtime/payload_builders/amazon/base'
5
5
 
6
6
  RSpec.describe RubyAmazonBedrock::PayloadBuilders::Amazon::Base do
7
- let(:input) { 'example_input' }
8
- let(:options) { { key: 'value' } }
7
+ let(:prompt) { 'example_prompt' }
8
+ let(:options) { {} }
9
9
  let(:body) do
10
10
  {
11
- inputText: input,
11
+ inputText: prompt,
12
12
  textGenerationConfig: {
13
13
  maxTokenCount: 4096,
14
14
  stopSequences: [],
@@ -19,13 +19,11 @@ RSpec.describe RubyAmazonBedrock::PayloadBuilders::Amazon::Base do
19
19
  end
20
20
 
21
21
  describe '#build' do
22
- it 'returns a hash with the expected structure' do
23
- payload_builder = described_class.new(input, options)
24
- payload = payload_builder.build
22
+ it_should_behave_like 'a payload builder'
25
23
 
26
- expect(payload[:content_type]).to eq('application/json')
27
- expect(payload[:accept]).to eq('*/*')
28
- expect(payload[:body]).to eq(body)
24
+ context 'with custom parameters' do
25
+ include_context 'amazon titan parameters'
26
+ it_should_behave_like 'a payload builder'
29
27
  end
30
28
  end
31
29
  end
@@ -4,11 +4,11 @@ require 'spec_helper'
4
4
  require 'bedrock_runtime/payload_builders/amazon/titan_text_express_v1'
5
5
 
6
6
  RSpec.describe RubyAmazonBedrock::PayloadBuilders::Amazon::TitanTextExpressV1 do
7
- let(:input) { 'example_input' }
8
- let(:options) { { key: 'value' } }
7
+ let(:prompt) { 'example_prompt' }
8
+ let(:options) { {} }
9
9
  let(:body) do
10
10
  {
11
- inputText: input,
11
+ inputText: prompt,
12
12
  textGenerationConfig: {
13
13
  maxTokenCount: 4096,
14
14
  stopSequences: [],
@@ -19,14 +19,11 @@ RSpec.describe RubyAmazonBedrock::PayloadBuilders::Amazon::TitanTextExpressV1 do
19
19
  end
20
20
 
21
21
  describe '#build' do
22
- it 'returns a hash with the expected structure' do
23
- payload_builder = described_class.new(input, options)
24
- payload = payload_builder.build
22
+ it_should_behave_like 'a payload builder'
25
23
 
26
- expect(payload[:model_id]).to eq('amazon.titan-text-express-v1')
27
- expect(payload[:content_type]).to eq('application/json')
28
- expect(payload[:accept]).to eq('*/*')
29
- expect(payload[:body]).to eq(body)
24
+ context 'with custom parameters' do
25
+ include_context 'amazon titan parameters'
26
+ it_should_behave_like 'a payload builder'
30
27
  end
31
28
  end
32
29
  end
@@ -4,11 +4,11 @@ require 'spec_helper'
4
4
  require 'bedrock_runtime/payload_builders/amazon/titan_text_lite_v1'
5
5
 
6
6
  RSpec.describe RubyAmazonBedrock::PayloadBuilders::Amazon::TitanTextLiteV1 do
7
- let(:input) { 'example_input' }
8
- let(:options) { { key: 'value' } }
7
+ let(:prompt) { 'example_prompt' }
8
+ let(:options) { {} }
9
9
  let(:body) do
10
10
  {
11
- inputText: input,
11
+ inputText: prompt,
12
12
  textGenerationConfig: {
13
13
  maxTokenCount: 4096,
14
14
  stopSequences: [],
@@ -19,14 +19,11 @@ RSpec.describe RubyAmazonBedrock::PayloadBuilders::Amazon::TitanTextLiteV1 do
19
19
  end
20
20
 
21
21
  describe '#build' do
22
- it 'returns a hash with the expected structure' do
23
- payload_builder = described_class.new(input, options)
24
- payload = payload_builder.build
22
+ it_should_behave_like 'a payload builder'
25
23
 
26
- expect(payload[:model_id]).to eq('amazon.titan-text-lite-v1')
27
- expect(payload[:content_type]).to eq('application/json')
28
- expect(payload[:accept]).to eq('*/*')
29
- expect(payload[:body]).to eq(body)
24
+ context 'with custom parameters' do
25
+ include_context 'amazon titan parameters'
26
+ it_should_behave_like 'a payload builder'
30
27
  end
31
28
  end
32
29
  end
@@ -4,12 +4,12 @@ require 'spec_helper'
4
4
  require 'bedrock_runtime/payload_builders/anthropic/base'
5
5
 
6
6
  RSpec.describe RubyAmazonBedrock::PayloadBuilders::Anthropic::Base do
7
- let(:input) { 'example_input' }
8
- let(:options) { { key: 'value' } }
7
+ let(:prompt) { 'example_prompt' }
8
+ let(:options) { {} }
9
9
  let(:body) do
10
10
  {
11
- prompt: "\n\nHuman: #{input}\n\nAssistant:",
12
- max_tokens_to_sample: 300,
11
+ prompt: "\n\nHuman: #{prompt}\n\nAssistant:",
12
+ max_tokens_to_sample: 200,
13
13
  temperature: 0.5,
14
14
  top_k: 250,
15
15
  top_p: 1,
@@ -21,13 +21,11 @@ RSpec.describe RubyAmazonBedrock::PayloadBuilders::Anthropic::Base do
21
21
  end
22
22
 
23
23
  describe '#build' do
24
- it 'returns a hash with the expected structure' do
25
- payload_builder = described_class.new(input, options)
26
- payload = payload_builder.build
24
+ it_should_behave_like 'a payload builder'
27
25
 
28
- expect(payload[:content_type]).to eq('application/json')
29
- expect(payload[:accept]).to eq('*/*')
30
- expect(payload[:body]).to eq(body)
26
+ context 'with custom parameters' do
27
+ include_context 'anthropic parameters'
28
+ it_should_behave_like 'a payload builder'
31
29
  end
32
30
  end
33
31
  end
@@ -4,12 +4,12 @@ require 'spec_helper'
4
4
  require 'bedrock_runtime/payload_builders/anthropic/claude_instant_v1'
5
5
 
6
6
  RSpec.describe RubyAmazonBedrock::PayloadBuilders::Anthropic::ClaudeInstantV1 do
7
- let(:input) { 'example_input' }
8
- let(:options) { { key: 'value' } }
7
+ let(:prompt) { 'example_prompt' }
8
+ let(:options) { {} }
9
9
  let(:body) do
10
10
  {
11
- prompt: "\n\nHuman: #{input}\n\nAssistant:",
12
- max_tokens_to_sample: 300,
11
+ prompt: "\n\nHuman: #{prompt}\n\nAssistant:",
12
+ max_tokens_to_sample: 200,
13
13
  temperature: 0.5,
14
14
  top_k: 250,
15
15
  top_p: 1,
@@ -21,14 +21,11 @@ RSpec.describe RubyAmazonBedrock::PayloadBuilders::Anthropic::ClaudeInstantV1 do
21
21
  end
22
22
 
23
23
  describe '#build' do
24
- it 'returns a hash with the expected structure' do
25
- payload_builder = described_class.new(input, options)
26
- payload = payload_builder.build
24
+ it_behaves_like 'a payload builder'
27
25
 
28
- expect(payload[:model_id]).to eq('anthropic.claude-instant-v1')
29
- expect(payload[:content_type]).to eq('application/json')
30
- expect(payload[:accept]).to eq('*/*')
31
- expect(payload[:body]).to eq(body)
26
+ context 'with custom parameters' do
27
+ include_context 'anthropic parameters'
28
+ it_should_behave_like 'a payload builder'
32
29
  end
33
30
  end
34
31
  end
@@ -4,12 +4,12 @@ require 'spec_helper'
4
4
  require 'bedrock_runtime/payload_builders/anthropic/claude_v1'
5
5
 
6
6
  RSpec.describe RubyAmazonBedrock::PayloadBuilders::Anthropic::ClaudeV1 do
7
- let(:input) { 'example_input' }
8
- let(:options) { { key: 'value' } }
7
+ let(:prompt) { 'example_prompt' }
8
+ let(:options) { {} }
9
9
  let(:body) do
10
10
  {
11
- prompt: "\n\nHuman: #{input}\n\nAssistant:",
12
- max_tokens_to_sample: 300,
11
+ prompt: "\n\nHuman: #{prompt}\n\nAssistant:",
12
+ max_tokens_to_sample: 200,
13
13
  temperature: 0.5,
14
14
  top_k: 250,
15
15
  top_p: 1,
@@ -21,14 +21,11 @@ RSpec.describe RubyAmazonBedrock::PayloadBuilders::Anthropic::ClaudeV1 do
21
21
  end
22
22
 
23
23
  describe '#build' do
24
- it 'returns a hash with the expected structure' do
25
- payload_builder = described_class.new(input, options)
26
- payload = payload_builder.build
24
+ it_behaves_like 'a payload builder'
27
25
 
28
- expect(payload[:model_id]).to eq('anthropic.claude-v1')
29
- expect(payload[:content_type]).to eq('application/json')
30
- expect(payload[:accept]).to eq('*/*')
31
- expect(payload[:body]).to eq(body)
26
+ context 'with custom parameters' do
27
+ include_context 'anthropic parameters'
28
+ it_should_behave_like 'a payload builder'
32
29
  end
33
30
  end
34
31
  end
@@ -4,12 +4,12 @@ require 'spec_helper'
4
4
  require 'bedrock_runtime/payload_builders/anthropic/claude_v2'
5
5
 
6
6
  RSpec.describe RubyAmazonBedrock::PayloadBuilders::Anthropic::ClaudeV2 do
7
- let(:input) { 'example_input' }
8
- let(:options) { { key: 'value' } }
7
+ let(:prompt) { 'example_prompt' }
8
+ let(:options) { {} }
9
9
  let(:body) do
10
10
  {
11
- prompt: "\n\nHuman: #{input}\n\nAssistant:",
12
- max_tokens_to_sample: 300,
11
+ prompt: "\n\nHuman: #{prompt}\n\nAssistant:",
12
+ max_tokens_to_sample: 200,
13
13
  temperature: 0.5,
14
14
  top_k: 250,
15
15
  top_p: 1,
@@ -21,14 +21,11 @@ RSpec.describe RubyAmazonBedrock::PayloadBuilders::Anthropic::ClaudeV2 do
21
21
  end
22
22
 
23
23
  describe '#build' do
24
- it 'returns a hash with the expected structure' do
25
- payload_builder = described_class.new(input, options)
26
- payload = payload_builder.build
24
+ it_behaves_like 'a payload builder'
27
25
 
28
- expect(payload[:model_id]).to eq('anthropic.claude-v2')
29
- expect(payload[:content_type]).to eq('application/json')
30
- expect(payload[:accept]).to eq('*/*')
31
- expect(payload[:body]).to eq(body)
26
+ context 'with custom parameters' do
27
+ include_context 'anthropic parameters'
28
+ it_should_behave_like 'a payload builder'
32
29
  end
33
30
  end
34
31
  end
@@ -11,7 +11,7 @@ RSpec.describe RubyAmazonBedrock::PayloadBuilders::Base do
11
11
 
12
12
  payload_builder = described_class.new(input, options)
13
13
 
14
- expect(payload_builder.instance_variable_get(:@input)).to eq(input)
14
+ expect(payload_builder.instance_variable_get(:@prompt)).to eq(input)
15
15
  expect(payload_builder.instance_variable_get(:@options)).to eq(options)
16
16
  end
17
17
  end