Class: ActiveAgent::Providers::Azure::Options
- Inherits:
-
OpenAI::Options
- Object
- Common::BaseModel
- OpenAI::Options
- ActiveAgent::Providers::Azure::Options
- Defined in:
- lib/active_agent/providers/azure/options.rb
Overview
Configuration options for Azure OpenAI Service.
Azure OpenAI uses a different authentication and endpoint structure than standard OpenAI:
-
Endpoint: https://resource.openai.azure.com/openai/deployments/deployment/
-
Authentication: api-key header instead of Authorization: Bearer
-
API Version: Required query parameter
You can configure Azure OpenAI in two ways:
-
Using azure_resource and deployment_id (standard Azure OpenAI): @example
= Azure::Options.new( api_key: ENV["AZURE_OPENAI_API_KEY"], azure_resource: "mycompany", deployment_id: "gpt-4-deployment", api_version: "2024-10-21" ) -
Using a direct host/base_url (for custom domains or Azure AI Foundry): @example
= Azure::Options.new( api_key: ENV["AZURE_OPENAI_API_KEY"], host: "https://mycompany.cognitiveservices.azure.com/openai/deployments/gpt-4", api_version: "2024-10-21" )
Constant Summary collapse
- DEFAULT_API_VERSION =
"2024-10-21"
Instance Method Summary collapse
-
#base_url ⇒ String
Builds the base URL for Azure OpenAI API requests.
-
#extra_headers ⇒ Hash
Returns Azure-specific headers for authentication.
-
#extra_query ⇒ Hash
Returns Azure-specific query parameters.
-
#initialize(kwargs = {}) ⇒ Options
constructor
A new instance of Options.
Methods inherited from Common::BaseModel
#<=>, #==, attribute, #deep_compact, #deep_dup, delegate_attributes, drop_attributes, inherited, #inspect, keys, #merge!, required_attributes, #serialize, #to_h, #to_hash
Constructor Details
#initialize(kwargs = {}) ⇒ Options
Returns a new instance of Options.
43 44 45 46 47 48 49 50 |
# File 'lib/active_agent/providers/azure/options.rb', line 43 def initialize(kwargs = {}) kwargs = kwargs.deep_symbolize_keys if kwargs.respond_to?(:deep_symbolize_keys) kwargs[:api_version] ||= resolve_api_version(kwargs) # Store explicit host before super processes kwargs # host is aliased to base_url in parent, so check both @explicit_host = kwargs[:host] || kwargs[:base_url] super(kwargs) end |
Instance Method Details
#base_url ⇒ String
Builds the base URL for Azure OpenAI API requests.
If a direct host/base_url is provided, uses that directly. Otherwise, constructs the URL from azure_resource and deployment_id.
76 77 78 79 80 81 82 83 84 |
# File 'lib/active_agent/providers/azure/options.rb', line 76 def base_url if @explicit_host.present? @explicit_host elsif azure_resource.present? && deployment_id.present? "https://#{azure_resource}.openai.azure.com/openai/deployments/#{deployment_id}" else raise ArgumentError, "Either host or azure_resource + deployment_id must be provided" end end |
#extra_headers ⇒ Hash
Returns Azure-specific headers for authentication.
Azure uses api-key header instead of Authorization: Bearer.
57 58 59 |
# File 'lib/active_agent/providers/azure/options.rb', line 57 def extra_headers { "api-key" => api_key } end |
#extra_query ⇒ Hash
Returns Azure-specific query parameters.
Azure requires api-version as a query parameter.
66 67 68 |
# File 'lib/active_agent/providers/azure/options.rb', line 66 def extra_query { "api-version" => api_version } end |