Class: Application

Inherits:
Object
  • Object
show all
Defined in:
lib/kaba/application.rb

Class Method Summary collapse

Class Method Details

.connectionObject



3
4
5
6
7
8
9
# File 'lib/kaba/application.rb', line 3

def connection
  endpoint = ENV["LISA_TYPECHAT_ENDPOINT"] || "https://lisa-typechat.listenai.com"
  @connection ||= Faraday.new(endpoint) do |faraday|
    faraday.adapter :async_http, clients: Async::HTTP::Faraday::PersistentClients
    faraday.request :json
  end
end

.env!(name) ⇒ Object



39
40
41
# File 'lib/kaba/application.rb', line 39

def env!(name)
  ENV[name] or raise "missing environment variable: #{name}"
end

.judge_llm_clientObject



22
23
24
25
26
27
28
29
30
31
# File 'lib/kaba/application.rb', line 22

def judge_llm_client
  @judge_llm_client ||= OpenAI::Client.new(
    log_errors: true,
    access_token: env!("JUDGE_ACCCESS_TOKEN"),
    request_timeout: ENV.fetch("LISA_LLM_REQUEST_TIMEOUT", 120).to_i,
    uri_base: ENV.fetch("JUDGE_LLM_URI_BASE", "https://api.listenai.com")
  ) do |faraday|
    faraday.adapter Faraday.default_adapter, clients: Async::HTTP::Faraday::PersistentClients
  end
end

.llm_clientObject



11
12
13
14
15
16
17
18
19
20
# File 'lib/kaba/application.rb', line 11

def llm_client
  @llm_client ||= OpenAI::Client.new(
    log_errors: true,
    access_token: env!("LISA_ACCESS_TOKEN"),
    request_timeout: ENV.fetch("LISA_LLM_REQUEST_TIMEOUT", 120).to_i,
    uri_base: ENV.fetch("LISA_LLM_URI_BASE", "https://api.listenai.com")
  ) do |faraday|
    faraday.adapter Faraday.default_adapter, clients: Async::HTTP::Faraday::PersistentClients
  end
end

.llm_client_extra_headers=(headers) ⇒ Object



33
34
35
36
37
# File 'lib/kaba/application.rb', line 33

def llm_client_extra_headers=(headers)
  OpenAI.configure do |config|
    config.extra_headers = headers
  end
end