Class: Charai::OpenaiConfiguration

Inherits:
Object
  • Object
show all
Defined in:
lib/charai/openai_configuration.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model:, api_key:) ⇒ OpenaiConfiguration

Returns a new instance of OpenaiConfiguration.



3
4
5
6
7
# File 'lib/charai/openai_configuration.rb', line 3

def initialize(model:, api_key:)
  @endpoint_url = 'https://api.openai.com/v1/chat/completions'
  @model = model
  @api_key = api_key
end

Instance Attribute Details

#endpoint_urlObject (readonly)

Returns the value of attribute endpoint_url.



9
10
11
# File 'lib/charai/openai_configuration.rb', line 9

def endpoint_url
  @endpoint_url
end

Instance Method Details

#add_auth_header(headers) ⇒ Object



11
12
13
14
# File 'lib/charai/openai_configuration.rb', line 11

def add_auth_header(headers)
  headers['Authorization'] = "Bearer #{@api_key}"
  headers
end

#decorate_body(payload) ⇒ Object



16
17
18
19
# File 'lib/charai/openai_configuration.rb', line 16

def decorate_body(payload)
  payload[:model] = @model
  payload
end