Skip to content

Commit 58d868d

Browse files
committed
move validation into Client to ensure it runs
1 parent 25a513f commit 58d868d

File tree

2 files changed

+13
-11
lines changed

2 files changed

+13
-11
lines changed

lib/openai.rb

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,8 @@ def call(env)
3636
end
3737

3838
class Configuration
39-
attr_reader :azure_token_provider
4039
attr_accessor :api_type, :api_version, :organization_id, :uri_base, :request_timeout,
41-
:extra_headers, :access_token
40+
:extra_headers, :access_token, :azure_token_provider
4241

4342
DEFAULT_API_VERSION = "v1".freeze
4443
DEFAULT_URI_BASE = "https://api.openai.com/".freeze
@@ -54,15 +53,6 @@ def initialize
5453
@extra_headers = {}
5554
@azure_token_provider = nil
5655
end
57-
58-
def azure_token_provider=(provider)
59-
unless provider.nil? || provider.respond_to?(:to_proc)
60-
raise ConfigurationError,
61-
"OpenAI Azure AD token provider must be a Proc, Lambda, or respond to to_proc."
62-
end
63-
64-
@azure_token_provider = provider&.to_proc
65-
end
6656
end
6757

6858
class << self

lib/openai/client.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ def initialize(config = {}, &faraday_middleware)
2323
end
2424
@faraday_middleware = faraday_middleware
2525
validate_credential_config!
26+
validate_azure_credential_provider!
2627
end
2728

2829
def chat(parameters: {})
@@ -104,5 +105,16 @@ def validate_credential_config!
104105
raise ConfigurationError,
105106
"OpenAI access token or Azure token provider missing! See https://github.com/alexrudall/ruby-openai#usage"
106107
end
108+
109+
def validate_azure_credential_provider!
110+
return if @azure_token_provider.nil?
111+
112+
unless @azure_token_provider.respond_to?(:to_proc)
113+
raise ConfigurationError,
114+
"OpenAI Azure AD token provider must be a Proc, Lambda, or respond to to_proc."
115+
end
116+
117+
@azure_token_provider = @azure_token_provider&.to_proc
118+
end
107119
end
108120
end

0 commit comments

Comments
 (0)