Class: Asimov::HeadersFactory
- Inherits:
-
Object
- Object
- Asimov::HeadersFactory
- Defined in:
- lib/asimov/headers_factory.rb
Overview
Configures the set of HTTP headers being sent with requests to the OpenAI API. These header include authentication and content-type information.
Not intended for client use.
Constant Summary collapse
- NULL_ORGANIZATION_ID =
Null object used to allow nil override of a default organization_id.
Object.new.freeze
Instance Attribute Summary collapse
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
-
#organization_id ⇒ Object
readonly
Returns the value of attribute organization_id.
Instance Method Summary collapse
-
#headers(content_type = "application/json") ⇒ Object
Returns the headers to use for a request.
-
#initialize(api_key, organization_id) ⇒ HeadersFactory
constructor
A new instance of HeadersFactory.
Constructor Details
#initialize(api_key, organization_id) ⇒ HeadersFactory
Returns a new instance of HeadersFactory.
17 18 19 20 21 22 23 24 25 |
# File 'lib/asimov/headers_factory.rb', line 17 def initialize(api_key, organization_id) @api_key = api_key || Asimov.configuration.api_key initialize_organization_id(organization_id) return if @api_key raise Asimov::MissingApiKeyError, "No OpenAI API key was provided for this client." end |
Instance Attribute Details
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
15 16 17 |
# File 'lib/asimov/headers_factory.rb', line 15 def api_key @api_key end |
#organization_id ⇒ Object (readonly)
Returns the value of attribute organization_id.
15 16 17 |
# File 'lib/asimov/headers_factory.rb', line 15 def organization_id @organization_id end |
Instance Method Details
#headers(content_type = "application/json") ⇒ Object
Returns the headers to use for a request.
32 33 34 35 36 |
# File 'lib/asimov/headers_factory.rb', line 32 def headers(content_type = "application/json") { "Content-Type" => content_type }.merge(openai_headers) end |