Module: Llmemory::LLM

Defined in:
lib/llmemory/llm.rb,
lib/llmemory/llm/base.rb,
lib/llmemory/llm/usage.rb,
lib/llmemory/llm/openai.rb,
lib/llmemory/llm/response.rb,
lib/llmemory/llm/anthropic.rb,
lib/llmemory/llm/usage_ledger.rb,
lib/llmemory/llm/usage_recorder.rb,
lib/llmemory/llm/tracking_client.rb

Defined Under Namespace

Modules: UsageRecorder Classes: Anthropic, Base, OpenAI, Response, TrackingClient, Usage, UsageLedger

Class Method Summary collapse

Class Method Details

.client(api_key: nil) ⇒ Object



14
15
16
17
18
19
20
21
22
# File 'lib/llmemory/llm.rb', line 14

def self.client(api_key: nil)
  opts = api_key.to_s.empty? ? {} : { api_key: api_key }
  case Llmemory.configuration.llm_provider.to_sym
  when :openai then OpenAI.new(**opts)
  when :anthropic then Anthropic.new(**opts)
  else
    raise Llmemory::ConfigurationError, "Unknown LLM provider: #{Llmemory.configuration.llm_provider}"
  end
end