Class: LLM

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

Defined Under Namespace

Modules: Info, StopReason

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(model) ⇒ LLM

Returns a new instance of LLM.



12
13
14
15
16
17
# File 'lib/llm.rb', line 12

def initialize(model)
  @canonical_name = model[:canonical_name]
  @display_name = model[:display_name]
  @provider = model[:provider]
  @client_class = LLM::Clients::OpenAI # TODO: Allow alternative client classes.
end

Instance Attribute Details

#canonical_nameObject (readonly)

Returns the value of attribute canonical_name.



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

def canonical_name
  @canonical_name
end

#display_nameObject (readonly)

Returns the value of attribute display_name.



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

def display_name
  @display_name
end

#providerObject (readonly)

Returns the value of attribute provider.



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

def provider
  @provider
end

Class Method Details

.all!Object



32
33
34
# File 'lib/llm.rb', line 32

def all!
  known_models
end

.from_string!(model_string) ⇒ Object

Raises:

  • (ArgumentError)


36
37
38
39
40
41
42
# File 'lib/llm.rb', line 36

def from_string!(model_string)
  model = known_models.find { |model| model.canonical_name == model_string }

  raise ArgumentError, "Unknown model: #{model_string}" unless model

  model
end

Instance Method Details

#clientObject



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

def client
  client_class.new(llm: self)
end