Module: OpenAI::Providers::Azure Private
- Defined in:
- lib/openai/providers/azure.rb
This module is part of a private API. You should avoid using this module if possible, as it may be removed or be changed in the future.
Defined Under Namespace
Classes: Auth, Definition
Constant Summary collapse
- API_KEY_AUTH_MARKER =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
:openai_azure_api_key- BEARER_AUTH_MARKER =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
:openai_azure_bearer- AUTH_HEADERS =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
%w[api-key authorization].freeze
- MISSING_ENDPOINT_MESSAGE =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
"Azure OpenAI requires an endpoint. Pass `endpoint` to `azure(...)`, or set " \ "`AZURE_OPENAI_ENDPOINT`."
- MISSING_CREDENTIALS_MESSAGE =
This constant is part of a private API. You should avoid using this constant if possible, as it may be removed or be changed in the future.
"Could not find credentials for Azure OpenAI. Pass `api_key` or `token_provider` " \ "to `azure(...)`, or set `AZURE_OPENAI_API_KEY`."
Class Method Summary collapse
- .normalize_endpoint(endpoint) ⇒ Object private
- .normalize_optional_string(value) ⇒ Object private
- .provider_headers(request, marker:) ⇒ Object private
- .validate_origin!(url, base_url) ⇒ Object private
Class Method Details
.normalize_endpoint(endpoint) ⇒ Object
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.
86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 |
# File 'lib/openai/providers/azure.rb', line 86 def normalize_endpoint(endpoint) uri = URI(endpoint) unless uri.is_a?(URI::HTTP) && uri.host raise ArgumentError, "The Azure OpenAI `endpoint` must be an absolute HTTP or HTTPS URL." end unless uri.query.nil? raise ArgumentError, "The Azure OpenAI `endpoint` must not include a query string." end unless uri.fragment.nil? raise ArgumentError, "The Azure OpenAI `endpoint` must not include a fragment." end unless uri.userinfo.nil? raise ArgumentError, "The Azure OpenAI `endpoint` must not include user information." end path = uri.path.sub(%r{/+\z}, "") uri.path = case path when %r{/openai/v1\z} path when %r{/openai\z} "#{path}/v1" else "#{path}/openai/v1" end uri.to_s rescue URI::InvalidURIError => e = "The Azure OpenAI `endpoint` must be an absolute HTTP or HTTPS URL." raise ArgumentError.new(), cause: e end |
.normalize_optional_string(value) ⇒ Object
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.
120 121 122 123 124 |
# File 'lib/openai/providers/azure.rb', line 120 def normalize_optional_string(value) return nil unless value.is_a?(String) normalized = value.strip normalized unless normalized.empty? end |
.provider_headers(request, marker:) ⇒ Object
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.
126 127 128 129 130 131 132 133 134 135 136 137 138 139 |
# File 'lib/openai/providers/azure.rb', line 126 def provider_headers(request, marker:) headers = request.fetch(:headers).dup if request[:provider_auth] == marker AUTH_HEADERS.each { headers.delete(_1) } elsif AUTH_HEADERS.any? { headers.key?(_1) } raise( OpenAI::Errors::Error, "Azure OpenAI provider authentication cannot be combined with a custom " \ "`Authorization` or `api-key` header." ) end headers end |
.validate_origin!(url, base_url) ⇒ Object
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.
141 142 143 144 145 146 147 148 |
# File 'lib/openai/providers/azure.rb', line 141 def validate_origin!(url, base_url) return if OpenAI::Internal::Util.uri_origin(url) == OpenAI::Internal::Util.uri_origin(base_url) raise( OpenAI::Errors::Error, "Refusing to authenticate a request for an origin other than the configured " \ "Azure OpenAI endpoint." ) end |