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
@@ -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
@@ -4,24 +4,22 @@ require 'spec_helper'
4
4
  require 'bedrock_runtime/payload_builders/cohere/embed_multilingual_v3'
5
5
 
6
6
  RSpec.describe RubyAmazonBedrock::PayloadBuilders::Cohere::EmbedMultilingualV3 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-multilingual-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
@@ -4,25 +4,23 @@ require 'spec_helper'
4
4
  require 'bedrock_runtime/payload_builders/meta/base'
5
5
 
6
6
  RSpec.describe RubyAmazonBedrock::PayloadBuilders::Meta::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,
11
+ prompt: prompt,
12
12
  max_gen_len: 512,
13
- temperature: 0.2,
13
+ temperature: 0.5,
14
14
  top_p: 0.9
15
15
  }.to_json
16
16
  end
17
17
 
18
18
  describe '#build' do
19
- it 'returns a hash with the expected structure' do
20
- payload_builder = described_class.new(input, options)
21
- payload = payload_builder.build
19
+ it_should_behave_like 'a payload builder'
22
20
 
23
- expect(payload[:content_type]).to eq('application/json')
24
- expect(payload[:accept]).to eq('*/*')
25
- expect(payload[:body]).to eq(body)
21
+ context 'with custom parameters' do
22
+ include_context 'meta parameters'
23
+ it_should_behave_like 'a payload builder'
26
24
  end
27
25
  end
28
26
  end
@@ -4,26 +4,23 @@ require 'spec_helper'
4
4
  require 'bedrock_runtime/payload_builders/meta/llama213b_chat_v1'
5
5
 
6
6
  RSpec.describe RubyAmazonBedrock::PayloadBuilders::Meta::Llama213bChatV1 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,
11
+ prompt: prompt,
12
12
  max_gen_len: 512,
13
- temperature: 0.2,
13
+ temperature: 0.5,
14
14
  top_p: 0.9
15
15
  }.to_json
16
16
  end
17
17
 
18
18
  describe '#build' do
19
- it 'returns a hash with the expected structure' do
20
- payload_builder = described_class.new(input, options)
21
- payload = payload_builder.build
19
+ it_should_behave_like 'a payload builder'
22
20
 
23
- expect(payload[:model_id]).to eq('meta.llama2-13b-chat-v1')
24
- expect(payload[:content_type]).to eq('application/json')
25
- expect(payload[:accept]).to eq('*/*')
26
- expect(payload[:body]).to eq(body)
21
+ context 'with custom parameters' do
22
+ include_context 'meta parameters'
23
+ it_should_behave_like 'a payload builder'
27
24
  end
28
25
  end
29
26
  end
@@ -4,26 +4,23 @@ require 'spec_helper'
4
4
  require 'bedrock_runtime/payload_builders/meta/llama270b_chat_v1'
5
5
 
6
6
  RSpec.describe RubyAmazonBedrock::PayloadBuilders::Meta::Llama270bChatV1 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,
11
+ prompt: prompt,
12
12
  max_gen_len: 512,
13
- temperature: 0.2,
13
+ temperature: 0.5,
14
14
  top_p: 0.9
15
15
  }.to_json
16
16
  end
17
17
 
18
18
  describe '#build' do
19
- it 'returns a hash with the expected structure' do
20
- payload_builder = described_class.new(input, options)
21
- payload = payload_builder.build
19
+ it_should_behave_like 'a payload builder'
22
20
 
23
- expect(payload[:model_id]).to eq('meta.llama2-70b-chat-v1')
24
- expect(payload[:content_type]).to eq('application/json')
25
- expect(payload[:accept]).to eq('*/*')
26
- expect(payload[:body]).to eq(body)
21
+ context 'with custom parameters' do
22
+ include_context 'meta parameters'
23
+ it_should_behave_like 'a payload builder'
27
24
  end
28
25
  end
29
26
  end
@@ -4,27 +4,25 @@ require 'spec_helper'
4
4
  require 'bedrock_runtime/payload_builders/stability_ai/base'
5
5
 
6
6
  RSpec.describe RubyAmazonBedrock::PayloadBuilders::StabilityAi::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
11
  text_prompts: [
12
- { text: input }
12
+ { text: prompt }
13
13
  ],
14
14
  cfg_scale: 10,
15
15
  seed: 0,
16
- steps: 50
16
+ steps: 30
17
17
  }.to_json
18
18
  end
19
19
 
20
20
  describe '#build' do
21
- it 'returns a hash with the expected structure' do
22
- payload_builder = described_class.new(input, options)
23
- payload = payload_builder.build
21
+ it_should_behave_like 'a payload builder'
24
22
 
25
- expect(payload[:content_type]).to eq('application/json')
26
- expect(payload[:accept]).to eq('*/*')
27
- expect(payload[:body]).to eq(body)
23
+ context 'with custom parameters' do
24
+ include_context 'stability ai parameters'
25
+ it_should_behave_like 'a payload builder'
28
26
  end
29
27
  end
30
28
  end
@@ -4,28 +4,25 @@ require 'spec_helper'
4
4
  require 'bedrock_runtime/payload_builders/stability_ai/stable_diffusion_xl_v0'
5
5
 
6
6
  RSpec.describe RubyAmazonBedrock::PayloadBuilders::StabilityAi::StableDiffusionXlV0 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
11
  text_prompts: [
12
- { text: input }
12
+ { text: prompt }
13
13
  ],
14
14
  cfg_scale: 10,
15
15
  seed: 0,
16
- steps: 50
16
+ steps: 30
17
17
  }.to_json
18
18
  end
19
19
 
20
20
  describe '#build' do
21
- it 'returns a hash with the expected structure' do
22
- payload_builder = described_class.new(input, options)
23
- payload = payload_builder.build
21
+ it_should_behave_like 'a payload builder'
24
22
 
25
- expect(payload[:model_id]).to eq('stability.stable-diffusion-xl-v0')
26
- expect(payload[:content_type]).to eq('application/json')
27
- expect(payload[:accept]).to eq('*/*')
28
- expect(payload[:body]).to eq(body)
23
+ context 'with custom parameters' do
24
+ include_context 'stability ai parameters'
25
+ it_should_behave_like 'a payload builder'
29
26
  end
30
27
  end
31
28
  end
@@ -4,28 +4,25 @@ require 'spec_helper'
4
4
  require 'bedrock_runtime/payload_builders/stability_ai/stable_diffusion_xl_v1'
5
5
 
6
6
  RSpec.describe RubyAmazonBedrock::PayloadBuilders::StabilityAi::StableDiffusionXlV1 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
11
  text_prompts: [
12
- { text: input }
12
+ { text: prompt }
13
13
  ],
14
14
  cfg_scale: 10,
15
15
  seed: 0,
16
- steps: 50
16
+ steps: 30
17
17
  }.to_json
18
18
  end
19
19
 
20
20
  describe '#build' do
21
- it 'returns a hash with the expected structure' do
22
- payload_builder = described_class.new(input, options)
23
- payload = payload_builder.build
21
+ it_should_behave_like 'a payload builder'
24
22
 
25
- expect(payload[:model_id]).to eq('stability.stable-diffusion-xl-v1')
26
- expect(payload[:content_type]).to eq('application/json')
27
- expect(payload[:accept]).to eq('*/*')
28
- expect(payload[:body]).to eq(body)
23
+ context 'with custom parameters' do
24
+ include_context 'stability ai parameters'
25
+ it_should_behave_like 'a payload builder'
29
26
  end
30
27
  end
31
28
  end
@@ -5,13 +5,13 @@ require 'bedrock_runtime/payload_factory'
5
5
 
6
6
  RSpec.describe RubyAmazonBedrock::PayloadFactory do
7
7
  let(:bedrock_models) do
8
- ["ai21labs.j2-mid-v1",
9
- "ai21labs.j2-ultra-v1",
8
+ ["ai21.j2-mid-v1",
9
+ "ai21.j2-ultra-v1",
10
10
  "amazon.titan-image-generator-v1",
11
11
  "amazon.titan-text-lite-v1",
12
12
  "amazon.titan-text-express-v1",
13
- "anthropic.claude-v1",
14
13
  "anthropic.claude-instant-v1",
14
+ "anthropic.claude-v1",
15
15
  "anthropic.claude-v2",
16
16
  "cohere.command-light-text-v14",
17
17
  "cohere.command-text-v14",
data/spec/spec_helper.rb CHANGED
@@ -1,14 +1,13 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  require 'dotenv/load'
4
- require 'simplecov'
5
4
  require 'vcr'
6
5
 
7
6
  require 'amazon_bedrock'
8
7
  require 'bedrock_runtime/client'
9
8
  require 'bedrock_runtime/payload_factory'
10
9
 
11
- SimpleCov.start
10
+ require 'support/helpers'
12
11
 
13
12
  RSpec.configure do |config|
14
13
  # Enable flags like --only-failures and --next-failure
@@ -0,0 +1,169 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'pry'
4
+
5
+ RSpec.shared_examples 'a payload builder' do
6
+ it 'validates the payload structure' do
7
+ payload_builder = described_class.new(prompt, options)
8
+ payload = payload_builder.build
9
+
10
+ expect(payload[:content_type]).to eq('application/json')
11
+ expect(payload[:accept]).to eq('*/*')
12
+ expect(payload[:body]).to eq(body)
13
+ end
14
+ end
15
+
16
+ RSpec.shared_context 'a121 labs parameters' do
17
+ let(:options) do
18
+ {
19
+ max_tokens: 100,
20
+ temperature: 0.5,
21
+ top_p: 2,
22
+ stop_sequences: %w[stop1 stop2],
23
+ count_penalty: 1,
24
+ presence_penalty: 1,
25
+ frequency_penalty: 1
26
+ }
27
+ end
28
+ let(:body) do
29
+ {
30
+ prompt: prompt,
31
+ maxTokenCount: 100,
32
+ temperature: 0.5,
33
+ topP: 2,
34
+ stopSequences: %w[stop1 stop2],
35
+ countPenalty: { scale: 1 },
36
+ presencePenalty: { scale: 1 },
37
+ frequencyPenalty: { scale: 1 }
38
+ }.to_json
39
+ end
40
+ end
41
+
42
+ RSpec.shared_context 'amazon titan parameters' do
43
+ let(:options) do
44
+ {
45
+ max_tokens: 100,
46
+ stop_sequences: %w[stop1 stop2],
47
+ temperature: 0.5,
48
+ top_p: 2
49
+ }
50
+ end
51
+ let(:body) do
52
+ {
53
+ inputText: prompt,
54
+ textGenerationConfig: {
55
+ maxTokenCount: 100,
56
+ stopSequences: %w[stop1 stop2],
57
+ temperature: 0.5,
58
+ topP: 2
59
+ }
60
+ }.to_json
61
+ end
62
+ end
63
+
64
+ RSpec.shared_context 'anthropic parameters' do
65
+ let(:options) do
66
+ {
67
+ max_tokens: 100,
68
+ stop_sequences: [],
69
+ temperature: 0.1,
70
+ top_k: 150,
71
+ top_p: 2
72
+ }
73
+ end
74
+ let(:body) do
75
+ {
76
+ prompt: "\n\nHuman: #{prompt}\n\nAssistant:",
77
+ max_tokens_to_sample: 100,
78
+ temperature: 0.1,
79
+ top_k: 150,
80
+ top_p: 2,
81
+ stop_sequences: [],
82
+ anthropic_version: 'bedrock-2023-05-31'
83
+ }.to_json
84
+ end
85
+ end
86
+
87
+ RSpec.shared_context 'cohere command parameters' do
88
+ let(:options) do
89
+ {
90
+ temperature: 0.1,
91
+ top_p: 0.2,
92
+ top_k: 0.3,
93
+ max_tokens: 100,
94
+ num_generations: 2,
95
+ return_likelihoods: 'ALL',
96
+ stop_sequences: %w[stop1 stop2],
97
+ stream: true,
98
+ truncate: 'LINE'
99
+ }
100
+ end
101
+ let(:body) do
102
+ {
103
+ prompt: "#{prompt}:",
104
+ temperature: 0.1,
105
+ p: 0.2,
106
+ k: 0.3,
107
+ max_tokens: 100,
108
+ num_generations: 2,
109
+ return_likelihoods: 'ALL',
110
+ stop_sequences: %w[stop1 stop2],
111
+ stream: true,
112
+ truncate: 'LINE'
113
+ }.to_json
114
+ end
115
+ end
116
+
117
+ RSpec.shared_context 'cohere embed parameters' do
118
+ let(:options) do
119
+ {
120
+ input_type: 'classification',
121
+ truncate: 'LEFT'
122
+ }
123
+ end
124
+ let(:body) do
125
+ {
126
+ texts: [prompt],
127
+ input_type: 'classification',
128
+ truncate: 'LEFT'
129
+ }.to_json
130
+ end
131
+ end
132
+
133
+ RSpec.shared_context 'meta parameters' do
134
+ let(:options) do
135
+ {
136
+ max_tokens: 256,
137
+ temperature: 0.1,
138
+ top_p: 0.2
139
+ }
140
+ end
141
+ let(:body) do
142
+ {
143
+ prompt: prompt,
144
+ max_gen_len: 256,
145
+ temperature: 0.1,
146
+ top_p: 0.2
147
+ }.to_json
148
+ end
149
+ end
150
+
151
+ RSpec.shared_context 'stability ai parameters' do
152
+ let(:options) do
153
+ {
154
+ cfg_scale: 20,
155
+ seed: 1,
156
+ steps: 40
157
+ }
158
+ end
159
+ let(:body) do
160
+ {
161
+ text_prompts: [
162
+ { text: prompt }
163
+ ],
164
+ cfg_scale: 20,
165
+ seed: 1,
166
+ steps: 40
167
+ }.to_json
168
+ end
169
+ end