ruby-amazon-bedrock 0.2.1 → 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 (46) hide show
  1. checksums.yaml +4 -4
  2. data/CHANGELOG.md +5 -0
  3. data/Gemfile.lock +1 -1
  4. data/README.md +112 -18
  5. data/lib/amazon_bedrock/version.rb +1 -1
  6. data/lib/bedrock_runtime/client.rb +4 -4
  7. data/lib/bedrock_runtime/payload_builders/ai_21_labs/base.rb +20 -8
  8. data/lib/bedrock_runtime/payload_builders/amazon/base.rb +11 -7
  9. data/lib/bedrock_runtime/payload_builders/amazon/titan_image_generator_v1.rb +1 -1
  10. data/lib/bedrock_runtime/payload_builders/amazon/titan_text_lite_v1.rb +7 -15
  11. data/lib/bedrock_runtime/payload_builders/anthropic/base.rb +16 -8
  12. data/lib/bedrock_runtime/payload_builders/base.rb +9 -2
  13. data/lib/bedrock_runtime/payload_builders/cohere/command_base.rb +25 -4
  14. data/lib/bedrock_runtime/payload_builders/cohere/embed_base.rb +10 -2
  15. data/lib/bedrock_runtime/payload_builders/meta/base.rb +12 -4
  16. data/lib/bedrock_runtime/payload_builders/stability_ai/base.rb +12 -4
  17. data/lib/bedrock_runtime/payload_factory.rb +3 -3
  18. data/lib/bedrock_runtime/response_builders/image.rb +4 -0
  19. data/spec/bedrock_runtime/client_spec.rb +2 -2
  20. data/spec/bedrock_runtime/payload_builders/ai_21_labs/base_spec.rb +9 -11
  21. data/spec/bedrock_runtime/payload_builders/ai_21_labs/j2_mid_v1_spec.rb +9 -12
  22. data/spec/bedrock_runtime/payload_builders/ai_21_labs/j2_ultra_v1_spec.rb +10 -13
  23. data/spec/bedrock_runtime/payload_builders/amazon/base_spec.rb +7 -9
  24. data/spec/bedrock_runtime/payload_builders/amazon/titan_text_express_v1_spec.rb +7 -10
  25. data/spec/bedrock_runtime/payload_builders/amazon/titan_text_lite_v1_spec.rb +7 -10
  26. data/spec/bedrock_runtime/payload_builders/anthropic/base_spec.rb +8 -10
  27. data/spec/bedrock_runtime/payload_builders/anthropic/claude_instant_v1_spec.rb +8 -11
  28. data/spec/bedrock_runtime/payload_builders/anthropic/claude_v1_spec.rb +8 -11
  29. data/spec/bedrock_runtime/payload_builders/anthropic/claude_v2_spec.rb +8 -11
  30. data/spec/bedrock_runtime/payload_builders/base_spec.rb +1 -1
  31. data/spec/bedrock_runtime/payload_builders/cohere/command_base_spec.rb +16 -11
  32. data/spec/bedrock_runtime/payload_builders/cohere/command_light_text_v14_spec.rb +16 -12
  33. data/spec/bedrock_runtime/payload_builders/cohere/command_text_v14_spec.rb +16 -12
  34. data/spec/bedrock_runtime/payload_builders/cohere/embed_base_spec.rb +8 -10
  35. data/spec/bedrock_runtime/payload_builders/cohere/embed_english_v3_spec.rb +9 -11
  36. data/spec/bedrock_runtime/payload_builders/cohere/embed_multilingual_v3_spec.rb +9 -11
  37. data/spec/bedrock_runtime/payload_builders/meta/base_spec.rb +8 -10
  38. data/spec/bedrock_runtime/payload_builders/meta/llama213b_chat_v1_spec.rb +8 -11
  39. data/spec/bedrock_runtime/payload_builders/meta/llama270b_chat_v1_spec.rb +8 -11
  40. data/spec/bedrock_runtime/payload_builders/stability_ai/base_spec.rb +8 -10
  41. data/spec/bedrock_runtime/payload_builders/stability_ai/stable_diffusion_xl_v0_spec.rb +8 -11
  42. data/spec/bedrock_runtime/payload_builders/stability_ai/stable_diffusion_xl_v1_spec.rb +8 -11
  43. data/spec/bedrock_runtime/payload_factory_spec.rb +1 -1
  44. data/spec/spec_helper.rb +2 -0
  45. data/spec/support/helpers.rb +169 -0
  46. metadata +3 -2
@@ -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.
@@ -55,8 +55,8 @@ module RubyAmazonBedrock
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,14 +4,14 @@ 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: 1.0,
14
+ topP: 1,
15
15
  stopSequences: [],
16
16
  countPenalty: { scale: 0 },
17
17
  presencePenalty: { 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,14 +4,14 @@ 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: 1.0,
14
+ topP: 1,
15
15
  stopSequences: [],
16
16
  countPenalty: { scale: 0 },
17
17
  presencePenalty: { 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('ai21.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,14 +4,14 @@ 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: 1.0,
14
+ topP: 1,
15
15
  stopSequences: [],
16
16
  countPenalty: { scale: 0 },
17
17
  presencePenalty: { 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('ai21.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
@@ -4,24 +4,29 @@ require 'spec_helper'
4
4
  require 'bedrock_runtime/payload_builders/cohere/command_base'
5
5
 
6
6
  RSpec.describe RubyAmazonBedrock::PayloadBuilders::Cohere::CommandBase 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
- max_tokens: 100,
13
- temperature: 0.8
11
+ prompt: "#{prompt}:",
12
+ temperature: 0.9,
13
+ p: 0.75,
14
+ k: 0,
15
+ max_tokens: 20,
16
+ num_generations: 1,
17
+ return_likelihoods: 'GENERATION',
18
+ stop_sequences: [],
19
+ stream: false,
20
+ truncate: 'NONE'
14
21
  }.to_json
15
22
  end
16
23
 
17
24
  describe '#build' do
18
- it 'returns a hash with the expected structure' do
19
- payload_builder = described_class.new(input, options)
20
- payload = payload_builder.build
25
+ it_behaves_like 'a payload builder'
21
26
 
22
- expect(payload[:content_type]).to eq('application/json')
23
- expect(payload[:accept]).to eq('*/*')
24
- expect(payload[:body]).to eq(body)
27
+ context 'with custom parameters' do
28
+ include_context 'cohere command parameters'
29
+ it_should_behave_like 'a payload builder'
25
30
  end
26
31
  end
27
32
  end
@@ -4,25 +4,29 @@ require 'spec_helper'
4
4
  require 'bedrock_runtime/payload_builders/cohere/command_light_text_v14'
5
5
 
6
6
  RSpec.describe RubyAmazonBedrock::PayloadBuilders::Cohere::CommandLightTextV14 do
7
- let(:input) { 'example_input' }
8
- let(:options) { { key: 'value' } }
7
+ let(:prompt) { 'example_input' }
8
+ let(:options) { {} }
9
9
  let(:body) do
10
10
  {
11
- prompt: "#{input}:",
12
- max_tokens: 100,
13
- temperature: 0.8
11
+ prompt: "#{prompt}:",
12
+ temperature: 0.9,
13
+ p: 0.75,
14
+ k: 0,
15
+ max_tokens: 20,
16
+ num_generations: 1,
17
+ return_likelihoods: 'GENERATION',
18
+ stop_sequences: [],
19
+ stream: false,
20
+ truncate: 'NONE'
14
21
  }.to_json
15
22
  end
16
23
 
17
24
  describe '#build' do
18
- it 'returns a hash with the expected structure' do
19
- payload_builder = described_class.new(input, options)
20
- payload = payload_builder.build
25
+ it_behaves_like 'a payload builder'
21
26
 
22
- expect(payload[:model_id]).to eq('cohere.command-light-text-v14')
23
- expect(payload[:content_type]).to eq('application/json')
24
- expect(payload[:accept]).to eq('*/*')
25
- expect(payload[:body]).to eq(body)
27
+ context 'with custom parameters' do
28
+ include_context 'cohere command parameters'
29
+ it_should_behave_like 'a payload builder'
26
30
  end
27
31
  end
28
32
  end
@@ -4,25 +4,29 @@ require 'spec_helper'
4
4
  require 'bedrock_runtime/payload_builders/cohere/command_text_v14'
5
5
 
6
6
  RSpec.describe RubyAmazonBedrock::PayloadBuilders::Cohere::CommandTextV14 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
- max_tokens: 100,
13
- temperature: 0.8
11
+ prompt: "#{prompt}:",
12
+ temperature: 0.9,
13
+ p: 0.75,
14
+ k: 0,
15
+ max_tokens: 20,
16
+ num_generations: 1,
17
+ return_likelihoods: 'GENERATION',
18
+ stop_sequences: [],
19
+ stream: false,
20
+ truncate: 'NONE'
14
21
  }.to_json
15
22
  end
16
23
 
17
24
  describe '#build' do
18
- it 'returns a hash with the expected structure' do
19
- payload_builder = described_class.new(input, options)
20
- payload = payload_builder.build
25
+ it_behaves_like 'a payload builder'
21
26
 
22
- expect(payload[:model_id]).to eq('cohere.command-text-v14')
23
- expect(payload[:content_type]).to eq('application/json')
24
- expect(payload[:accept]).to eq('*/*')
25
- expect(payload[:body]).to eq(body)
27
+ context 'with custom parameters' do
28
+ include_context 'cohere command parameters'
29
+ it_should_behave_like 'a payload builder'
26
30
  end
27
31
  end
28
32
  end
@@ -4,23 +4,21 @@ require 'spec_helper'
4
4
  require 'bedrock_runtime/payload_builders/cohere/embed_base'
5
5
 
6
6
  RSpec.describe RubyAmazonBedrock::PayloadBuilders::Cohere::EmbedBase 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
- texts: [input],
12
- input_type: 'search_document'
11
+ texts: [prompt],
12
+ input_type: 'search_document',
13
+ truncate: 'NONE'
13
14
  }.to_json
14
15
  end
15
16
 
16
17
  describe '#build' do
17
- it 'returns a hash with the expected structure' do
18
- payload_builder = described_class.new(input, options)
19
- payload = payload_builder.build
18
+ it_behaves_like 'a payload builder'
20
19
 
21
- expect(payload[:content_type]).to eq('application/json')
22
- expect(payload[:accept]).to eq('*/*')
23
- expect(payload[:body]).to eq(body)
20
+ context 'with custom parameters' do
21
+ it_should_behave_like 'a payload builder'
24
22
  end
25
23
  end
26
24
  end
@@ -4,24 +4,22 @@ require 'spec_helper'
4
4
  require 'bedrock_runtime/payload_builders/cohere/embed_english_v3'
5
5
 
6
6
  RSpec.describe RubyAmazonBedrock::PayloadBuilders::Cohere::EmbedEnglishV3 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
- texts: [input],
12
- input_type: 'search_document'
11
+ texts: [prompt],
12
+ input_type: 'search_document',
13
+ truncate: 'NONE'
13
14
  }.to_json
14
15
  end
15
16
 
16
17
  describe '#build' do
17
- it 'returns a hash with the expected structure' do
18
- payload_builder = described_class.new(input, options)
19
- payload = payload_builder.build
18
+ it_behaves_like 'a payload builder'
20
19
 
21
- expect(payload[:model_id]).to eq('cohere.embed-english-v3')
22
- expect(payload[:content_type]).to eq('application/json')
23
- expect(payload[:accept]).to eq('*/*')
24
- expect(payload[:body]).to eq(body)
20
+ context 'with custom parameters' do
21
+ include_context 'cohere embed parameters'
22
+ it_should_behave_like 'a payload builder'
25
23
  end
26
24
  end
27
25
  end