Module: Githuh::LLM

Defined in:
lib/githuh/llm.rb,
lib/githuh/llm/base.rb,
lib/githuh/llm/openai.rb,
lib/githuh/llm/anthropic.rb

Defined Under Namespace

Classes: Anthropic, Base, Error, OpenAI

Class Method Summary collapse

Class Method Details

.available?Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/githuh/llm.rb', line 18

def self.available?
  !build.nil?
end

.buildObject

Returns an adapter instance based on available env vars. Priority: ANTHROPIC_API_KEY > OPENAI_API_KEY. Returns nil if no key is set (caller decides how to handle).



10
11
12
13
14
15
16
# File 'lib/githuh/llm.rb', line 10

def self.build
  if (key = env('ANTHROPIC_API_KEY'))
    Anthropic.new(api_key: key)
  elsif (key = env('OPENAI_API_KEY'))
    OpenAI.new(api_key: key)
  end
end

.env(name) ⇒ Object



22
23
24
25
# File 'lib/githuh/llm.rb', line 22

def self.env(name)
  value = ENV.fetch(name, nil)
  value && !value.strip.empty? ? value.strip : nil
end