Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add llama370b_instruct_v1 #4

Open
wants to merge 7 commits into
base: main
Choose a base branch
from
Open
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
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## [0.2.4] - 2024-04-25

- Support the use of AWS Named Profiles for authentication
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @ErebusBat let's add all your changes to the same version, please add the following notes to the CHANGELOG

  • Support for llama370b_instruct_v1
  • Explicitly add base64 gem to dependencies


## [0.2.3] - 2024-01-12

- Fix A121 Labs bug for maxTokens parameter
Expand Down
6 changes: 4 additions & 2 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
PATH
remote: .
specs:
ruby-amazon-bedrock (0.2.3)
ruby-amazon-bedrock (0.2.5)
aws-sdk-bedrockruntime (~> 1.0)
aws-sdk-s3 (~> 1.0)
base64 (~> 0.2)

GEM
remote: https://rubygems.org/
Expand All @@ -30,6 +31,7 @@ GEM
aws-sigv4 (~> 1.6)
aws-sigv4 (1.8.0)
aws-eventstream (~> 1, >= 1.0.2)
base64 (0.2.0)
bundler-audit (0.9.1)
bundler (>= 1.2.0, < 3)
thor (~> 1.0)
Expand Down Expand Up @@ -106,4 +108,4 @@ DEPENDENCIES
webmock (~> 3.12)

BUNDLED WITH
2.4.22
2.4.14
14 changes: 6 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -63,16 +63,14 @@ client = RubyAmazonBedrock::Client.new(
)
```

## With Configuration
### AWS Named Profiles

```ruby
RubyAmazonBedrock.configure do |config|
config.region = ENV.fetch('AWS_REGION', nil)
config.access_key_id = ENV.fetch('AWS_ACCESS_KEY_ID', nil)
config.secret_access_key = ENV.fetch('AWS_SECRET_ACCESS_KEY', nil)
end
You can also use [AWS Named Profiles](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html#cli-configure-files-format-profile) by passing the `profile` keywoard argument. When using a named profile, specyfing the `region`, `access_key_id` and `access_token` won't be required.
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Don't remove the With Configuration documentation, you can add the AWS Named Profiles note below that.


client = RubyAmazonBedrock::Client.new
```ruby
client = RubyAmazonBedrock::Client.new(
profile: "AWS_PROFILE"
)
```

## Options
Expand Down
3 changes: 2 additions & 1 deletion lib/amazon_bedrock.rb
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class Error < StandardError; end

# Configuration class for setting up AWS credentials and region.
class Configuration
attr_accessor :region, :access_key_id, :secret_access_key
attr_accessor :region, :access_key_id, :secret_access_key, :profile

# Initializes a new Configuration instance, loading values from
# environment variables or setting them to nil by default so the
Expand All @@ -22,6 +22,7 @@ def initialize
@region = ENV.fetch('AWS_REGION', nil)
@access_key_id = ENV.fetch('AWS_ACCESS_KEY_ID', nil)
@secret_access_key = ENV.fetch('AWS_SECRET_ACCESS_KEY', nil)
@profile = ENV.fetch('AWS_PROFILE', nil)
end
end

Expand Down
2 changes: 1 addition & 1 deletion lib/amazon_bedrock/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# frozen_string_literal: true

module RubyAmazonBedrock
VERSION = "0.2.3"
VERSION = "0.2.5"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's keep it to 0.2.4 version

end
20 changes: 14 additions & 6 deletions lib/bedrock_runtime/client.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
# frozen_string_literal: true

require 'pry'

require 'base64'
require 'aws-sdk-bedrockruntime'
require 'bedrock_runtime/payload_factory'
Expand All @@ -14,14 +16,20 @@ class Client
# Initializes the AWS BedrockRuntime client.
#
# @note The AWS credentials and region are fetched from the environment variables.
def initialize(region: nil, access_key_id: nil, secret_access_key: nil)
def initialize(region: nil, access_key_id: nil, secret_access_key: nil, profile: nil)
config = RubyAmazonBedrock.configuration || RubyAmazonBedrock::Configuration.new

@client = Aws::BedrockRuntime::Client.new(
region: region || config.region,
access_key_id: access_key_id || config.access_key_id,
secret_access_key: secret_access_key || config.secret_access_key
)
@client = if profile
Aws::BedrockRuntime::Client.new(
profile: profile
)
else
Aws::BedrockRuntime::Client.new(
region: region || config.region,
access_key_id: access_key_id || config.access_key_id,
secret_access_key: secret_access_key || config.secret_access_key
)
end
end

# Invokes a model using the Bedrock Runtime client.
Expand Down
21 changes: 21 additions & 0 deletions lib/bedrock_runtime/payload_builders/meta/llama370b_instruct_v1.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
# frozen_string_literal: true

module RubyAmazonBedrock
module PayloadBuilders
module Meta
# Llama370bInstructV1 is a subclass of Base. It provides functionalities specific to the Meta
# Llama 3 70B Instruct model.
#
# @see https://us-west-2.console.aws.amazon.com/bedrock/home?region=us-west-2#/providers?model=meta.llama3-70b-instruct-v1:0
# for more information about the Meta model.
class Llama370bInstructV1 < Base
# Returns the model ID for the Meta Llama 3 70B Instruct model.
#
# @return [String] 'meta.llama2-70b-chat-v1:0'
def model_id
'meta.llama3-70b-instruct-v1:0'
end
end
end
end
end
2 changes: 2 additions & 0 deletions lib/bedrock_runtime/payload_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
require_relative 'payload_builders/cohere/embed_multilingual_v3'
require_relative 'payload_builders/meta/llama213b_chat_v1'
require_relative 'payload_builders/meta/llama270b_chat_v1'
require_relative 'payload_builders/meta/llama370b_instruct_v1'
require_relative 'payload_builders/stability_ai/stable_diffusion_xl_v0'
require_relative 'payload_builders/stability_ai/stable_diffusion_xl_v1'

Expand Down Expand Up @@ -64,6 +65,7 @@ def models_to_builders
'cohere.embed-multilingual-v3' => PayloadBuilders::Cohere::EmbedMultilingualV3,
'meta.llama2-13b-chat-v1' => PayloadBuilders::Meta::Llama213bChatV1,
'meta.llama2-70b-chat-v1' => PayloadBuilders::Meta::Llama270bChatV1,
'meta.llama3-70b-instruct-v1:0' => PayloadBuilders::Meta::Llama370bInstructV1,
'stability.stable-diffusion-xl-v0' => PayloadBuilders::StabilityAi::StableDiffusionXlV0,
'stability.stable-diffusion-xl-v1' => PayloadBuilders::StabilityAi::StableDiffusionXlV1
}
Expand Down
1 change: 1 addition & 0 deletions lib/bedrock_runtime/response_factory.rb
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ def models_to_builders
'cohere.embed-multilingual-v3' => ResponseBuilders::CohereEmbed,
'meta.llama2-13b-chat-v1' => ResponseBuilders::Meta,
'meta.llama2-70b-chat-v1' => ResponseBuilders::Meta,
'meta.llama3-70b-instruct-v1:0' => ResponseBuilders::Meta,
'stability.stable-diffusion-xl-v0' => ResponseBuilders::StabilityAi,
'stability.stable-diffusion-xl-v1' => ResponseBuilders::StabilityAi
}
Expand Down
1 change: 1 addition & 0 deletions ruby-amazon-bedrock.gemspec
Original file line number Diff line number Diff line change
Expand Up @@ -37,4 +37,5 @@ Gem::Specification.new do |spec|

spec.add_dependency "aws-sdk-bedrockruntime", "~> 1.0"
spec.add_dependency "aws-sdk-s3", "~> 1.0"
spec.add_dependency "base64", "~> 0.2"
end
3 changes: 2 additions & 1 deletion spec/bedrock_runtime/client_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
described_class.new(
region: ENV.fetch('AWS_REGION', nil),
access_key_id: ENV.fetch('AWS_ACCESS_KEY_ID', nil),
secret_access_key: ENV.fetch('AWS_SECRET_ACCESS_KEY', nil)
secret_access_key: ENV.fetch('AWS_SECRET_ACCESS_KEY', nil),
profile: ENV.fetch('AWS_PROFILE', nil)
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add a new test scenario where the client instantiation is done without the profile so both cases are covered.

)
end

Expand Down