Class: Lluminary::Providers::Bedrock
- Defined in:
- lib/lluminary/providers/bedrock.rb
Overview
Provider for AWS Bedrock models. Implements the Base provider interface for AWS Bedrock’s API.
Constant Summary collapse
- NAME =
:bedrock- DEFAULT_MODEL =
Models::Bedrock::AnthropicClaudeInstantV1
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#config ⇒ Object
readonly
Returns the value of attribute config.
Instance Method Summary collapse
- #call(prompt, _task) ⇒ Object
-
#initialize(**config_overrides) ⇒ Bedrock
constructor
A new instance of Bedrock.
- #model ⇒ Object
- #models ⇒ Object
Constructor Details
#initialize(**config_overrides) ⇒ Bedrock
Returns a new instance of Bedrock.
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/lluminary/providers/bedrock.rb', line 17 def initialize(**config_overrides) super @config = { model: DEFAULT_MODEL }.merge(config) @client = Aws::BedrockRuntime::Client.new( region: config[:region], credentials: Aws::Credentials.new( config[:access_key_id], config[:secret_access_key] ) ) end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
15 16 17 |
# File 'lib/lluminary/providers/bedrock.rb', line 15 def client @client end |
#config ⇒ Object (readonly)
Returns the value of attribute config.
15 16 17 |
# File 'lib/lluminary/providers/bedrock.rb', line 15 def config @config end |
Instance Method Details
#call(prompt, _task) ⇒ Object
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/lluminary/providers/bedrock.rb', line 32 def call(prompt, _task) response = client.converse( model_id: model.name, messages: [{ role: "user", content: [{ text: prompt }] }] ) content = response.dig(:output, :message, :content, 0, :text) { raw: content, parsed: begin JSON.parse(content) if content rescue JSON::ParserError nil end } end |
#model ⇒ Object
52 53 54 |
# File 'lib/lluminary/providers/bedrock.rb', line 52 def model @model ||= config[:model].new end |
#models ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/lluminary/providers/bedrock.rb', line 56 def models models_client = Aws::Bedrock::Client.new( region: config[:region], credentials: Aws::Credentials.new( config[:access_key_id], config[:secret_access_key] ) ) response = models_client.list_foundation_models response.foundation_models.map(&:model_id) end |