Class: OpenAI::Providers::Bedrock::Definition Private

Inherits:
Object
  • Object
show all
Defined in:
lib/openai/providers/bedrock.rb

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(region:, base_url:, bearer_provider:, profile:, access_key_id:, secret_access_key:, session_token:, credentials_provider:, default_chain:) ⇒ Definition

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Definition.



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/openai/providers/bedrock.rb', line 40

def initialize(
  region:,
  base_url:,
  bearer_provider:,
  profile:,
  access_key_id:,
  secret_access_key:,
  session_token:,
  credentials_provider:,
  default_chain:
)
  @name = "bedrock"
  @region = region&.freeze
  @base_url = base_url&.freeze
  @bearer_provider = bearer_provider
  @profile = profile&.freeze
  @access_key_id = access_key_id&.freeze
  @secret_access_key = secret_access_key&.freeze
  @session_token = session_token&.freeze
  @credentials_provider = credentials_provider
  @default_chain = default_chain
end

Instance Attribute Details

#nameObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



38
39
40
# File 'lib/openai/providers/bedrock.rb', line 38

def name
  @name
end

Instance Method Details

#configureObject

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
# File 'lib/openai/providers/bedrock.rb', line 63

def configure
  if @bearer_provider
    base_url = Bedrock.resolve_base_url(@base_url, @region)
    auth = BearerAuth.new(token_provider: @bearer_provider, base_url: base_url)
  else
    Bedrock.load_aws!
    region = @region || Bedrock.profile_region(@profile)
    raise ArgumentError, MISSING_REGION_MESSAGE if region.nil?

    base_url = Bedrock.resolve_base_url(@base_url, region)
    credentials =
      if @access_key_id
        Aws::Credentials.new(@access_key_id, @secret_access_key, @session_token)
      elsif @credentials_provider
        CustomCredentialsProvider.new(@credentials_provider)
      elsif @profile
        ProfileCredentialsProvider.new(@profile, region: region)
      else
        DefaultCredentialsProvider.new
      end
    auth = SigV4Auth.new(
      region: region,
      base_url: base_url,
      credentials_provider: credentials,
      default_chain: @default_chain
    )
  end

  OpenAI::Internal::Provider::Runtime.new(
    name: name,
    base_url: base_url,
    prepare_request: auth.method(:prepare_request)
  )
end